-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix datamodules ImportError and add tests (#380)
* Warn when unavailable * Add tests * Add more to the tests * Fix experience_source * Fix vocdetection_datamodule * Fix imagenet * Update test_imports * Fix kitti * Apply suggestions from code review Co-authored-by: Jirka Borovec <[email protected]> * Add docstring to tests Co-authored-by: Jirka Borovec <[email protected]>
- Loading branch information
1 parent
f0e2bee
commit ecbb82a
Showing
7 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import importlib | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("dm_cls,deps", [ | ||
("AsynchronousLoader", []), | ||
("BinaryMNISTDataModule", ["torchvision"]), | ||
("CIFAR10DataModule", ["torchvision"]), | ||
("TinyCIFAR10DataModule", ["torchvision"]), | ||
("DiscountedExperienceSource", ["gym"]), | ||
("ExperienceSource", ["gym"]), | ||
("ExperienceSourceDataset", ["gym"]), | ||
("FashionMNISTDataModule", ["torchvision"]), | ||
("ImagenetDataModule", ["torchvision"]), | ||
("MNISTDataModule", ["torchvision"]), | ||
("SklearnDataModule", ["sklearn"]), | ||
("SklearnDataset", []), | ||
("TensorDataset", []), | ||
("SSLImagenetDataModule", ["torchvision"]), | ||
("STL10DataModule", ["torchvision"]), | ||
("VOCDetectionDataModule", ["torchvision"]), | ||
("CityscapesDataModule", ["torchvision"]), | ||
("KittiDataset", ["PIL"]), | ||
("KittiDataModule", ["torchvision"]), | ||
]) | ||
def test_import(dm_cls, deps): | ||
"""Tests importing when dependencies are not met. | ||
Set the followings in @pytest.mark.parametrize: | ||
dm_cls: class to test importing | ||
deps: packages required for dm_cls | ||
""" | ||
with mock.patch.dict("sys.modules", {pkg: None for pkg in deps}): | ||
dms_module = importlib.import_module("pl_bolts.datamodules") | ||
assert hasattr(dms_module, dm_cls), f"`from pl_bolts.datamodules import {dm_cls}` failed." |