Skip to content

Commit

Permalink
Test correctness of module flags
Browse files Browse the repository at this point in the history
  • Loading branch information
JoostvDoorn committed Mar 20, 2022
1 parent 90f0344 commit 0d79821
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion tests/utilities/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
# limitations under the License.
import operator

from pytorch_lightning.utilities import _module_available
from pytorch_lightning.utilities import (
_APEX_AVAILABLE,
_BAGUA_AVAILABLE,
_DEEPSPEED_AVAILABLE,
_FAIRSCALE_AVAILABLE,
_HOROVOD_AVAILABLE,
_module_available,
_OMEGACONF_AVAILABLE,
_POPTORCH_AVAILABLE,
)
from pytorch_lightning.utilities.imports import _compare_version


Expand Down Expand Up @@ -45,3 +54,48 @@ def test_compare_version(monkeypatch):
assert not _compare_version("torch", operator.ge, "1.10.0.rc0")
assert _compare_version("torch", operator.ge, "1.10.0", use_base_version=True)
assert not _compare_version("torch", operator.ge, "1.10.0")


def test_imports():
try:
import apex # noqa

assert _APEX_AVAILABLE
except ModuleNotFoundError:
assert not _APEX_AVAILABLE
try:
import bagua # noqa

assert _BAGUA_AVAILABLE
except ModuleNotFoundError:
assert not _BAGUA_AVAILABLE
try:
import deepspeed # noqa

assert _DEEPSPEED_AVAILABLE
except ModuleNotFoundError:
assert not _DEEPSPEED_AVAILABLE
try:
import fairscale.nn # noqa

assert _FAIRSCALE_AVAILABLE
except ModuleNotFoundError:
assert not _FAIRSCALE_AVAILABLE
try:
import horovod.torch # noqa

assert _HOROVOD_AVAILABLE
except ModuleNotFoundError:
assert not _HOROVOD_AVAILABLE
try:
import omegaconf # noqa

assert _OMEGACONF_AVAILABLE
except ModuleNotFoundError:
assert not _OMEGACONF_AVAILABLE
try:
import poptorch # noqa

assert _POPTORCH_AVAILABLE
except ModuleNotFoundError:
assert not _POPTORCH_AVAILABLE

0 comments on commit 0d79821

Please sign in to comment.