Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzaida committed Oct 8, 2023
1 parent b8f01b2 commit d1fe331
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
command: MMENGINE_LITE=1 pip install -e . -v
- run:
name: Install unit tests dependencies
command: pip install -r requirements/tests.txt
command: pip install -r requirements/tests_lite.txt
- run:
name: Run unit tests
command: pytest tests/test_config tests/test_registry tests/test_logging tests/test_utils --ignore=tests/test_utils/test_dl_utils
Expand Down
2 changes: 2 additions & 0 deletions requirements/tests_lite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameterized
pytest
2 changes: 2 additions & 0 deletions tests/test_logging/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from mmengine.logging import MMLogger, print_log
from mmengine.logging.logger import _get_device_id
from mmengine.utils import is_installed


class TestLogger:
Expand Down Expand Up @@ -237,6 +238,7 @@ def test_file_handlers(self, tmp_path):
MMLogger._instance_dict.clear()


@pytest.mark.skipif(not is_installed('torch'), reason='tests requires torch')
@patch('torch.cuda.device_count', lambda: 4)
def test_get_device_id():

Expand Down
8 changes: 3 additions & 5 deletions tests/test_registry/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mmengine.config import Config, ConfigDict # type: ignore
from mmengine.registry import (DefaultScope, Registry, build_from_cfg,
build_model_from_cfg)
from mmengine.utils import ManagerMixin
from mmengine.utils import ManagerMixin, is_installed


class TestRegistry:
Expand Down Expand Up @@ -637,11 +637,9 @@ def __init__(self, name):
Visualizer.get_current_instance()


@pytest.mark.skipif(not is_installed('torch'), reason='tests requires torch')
def test_build_model_from_cfg():
try:
import torch.nn as nn
except ImportError:
pytest.skip('require torch')
import torch.nn as nn

BACKBONES = Registry('backbone', build_func=build_model_from_cfg)

Expand Down
15 changes: 9 additions & 6 deletions tests/test_utils/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import numpy as np
import pytest
import torch

from mmengine import MMLogger
from mmengine.utils import is_installed
# yapf: disable
from mmengine.utils.misc import (apply_to, concat_list, deprecated_api_warning,
deprecated_function, get_object_from_string,
Expand Down Expand Up @@ -290,7 +290,10 @@ def deprecated_demo1():
assert expected_docstring.strip(' ') == deprecated_demo1.__doc__


@pytest.mark.skipif(not is_installed('torch'), reason='tests requires torch')
def test_apply_to():
import torch

# Test only apply `+1` to int object.
data = dict(a=1, b=2.0)
result = apply_to(data, lambda x: isinstance(x, int), lambda x: x + 1)
Expand Down Expand Up @@ -332,9 +335,9 @@ def test_apply_to():

def test_locate():
assert get_object_from_string('a.b.c') is None
model_module = import_module('mmengine.model')
assert get_object_from_string('mmengine.model') is model_module
config_module = import_module('mmengine.config')
assert get_object_from_string('mmengine.config') is config_module
assert get_object_from_string(
'mmengine.model.BaseModel') is model_module.BaseModel
assert get_object_from_string('mmengine.model.BaseModel.forward') is \
model_module.BaseModel.forward
'mmengine.config.Config') is config_module.Config
assert get_object_from_string('mmengine.config.Config.fromfile') is \
config_module.Config.fromfile

0 comments on commit d1fe331

Please sign in to comment.