diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 136d0293da..aad4adacdb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,12 +41,13 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install system dependencies run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg - - name: Install unittest dependencies - run: pip install -r requirements/test.txt - name: Build and install run: rm -rf .eggs && pip install -e . + - name: Validate the installation + run: python -c "import mmcv" - name: Run unittests and generate coverage report run: | + pip install -r requirements/test.txt pytest tests/ --ignore=tests/test_runner --ignore=tests/test_optimizer.py --ignore=tests/test_cnn --ignore=tests/test_parallel.py --ignore=tests/test_ops --ignore=tests/test_load_model_zoo.py --ignore=tests/test_utils/test_logging.py --ignore=tests/test_image/test_io.py --ignore=tests/test_utils/test_registry.py --ignore=tests/test_utils/test_parrots_jit.py build_without_ops: @@ -70,12 +71,14 @@ jobs: run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg - name: Install PyTorch run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html - - name: Install unittest dependencies - run: pip install -r requirements/test.txt - name: Build and install run: rm -rf .eggs && pip install -e . + - name: Validate the installation + run: python -c "import mmcv" - name: Run unittests - run: pytest tests/ --ignore=tests/test_ops + run: | + pip install -r requirements/test.txt + pytest tests/ --ignore=tests/test_ops build_cpu: runs-on: ubuntu-latest @@ -107,12 +110,13 @@ jobs: if: ${{matrix.torchvision == '0.4.2'}} - name: Install PyTorch run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html - - name: Install unittest dependencies - run: pip install -r requirements/test.txt - name: Build and install run: rm -rf .eggs && pip install -e . + - name: Validate the installation + run: python -c "import mmcv" - name: Run unittests and generate coverage report run: | + pip install -r requirements/test.txt coverage run --branch --source=mmcv -m pytest tests/ coverage xml coverage report -m @@ -174,12 +178,13 @@ jobs: run: pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html - name: Install system dependencies run: sudo apt-get update && sudo apt-get install -y ffmpeg libturbojpeg - - name: Install unittest dependencies - run: pip install -r requirements/test.txt - name: Build and install run: rm -rf .eggs && pip install -e . + - name: Validate the installation + run: python -c "import mmcv" - name: Run unittests and generate coverage report run: | + pip install -r requirements/test.txt coverage run --branch --source=mmcv -m pytest tests/ --ignore=tests/test_ops/test_onnx.py coverage xml coverage report -m @@ -216,8 +221,6 @@ jobs: python-version: 3.7 - name: Install system dependencies run: brew install ffmpeg jpeg-turbo - - name: Install unittest dependencies - run: pip install -r requirements/test.txt - name: Install Pillow run: pip install Pillow==6.2.2 if: ${{matrix.torchvision == '0.4.2'}} @@ -227,7 +230,10 @@ jobs: run: | rm -rf .eggs CC=clang CXX=clang++ CFLAGS='-stdlib=libc++' pip install -e . + - name: Validate the installation + run: python -c "import mmcv" - name: Run unittests run: | + pip install -r requirements/test.txt # The timing on macos VMs is not precise, so we skip the progressbar tests pytest tests/ --ignore tests/test_utils/test_progressbar.py --ignore tests/test_utils/test_timer.py diff --git a/mmcv/utils/__init__.py b/mmcv/utils/__init__.py index b2f160d9af..4c10f888d3 100644 --- a/mmcv/utils/__init__.py +++ b/mmcv/utils/__init__.py @@ -33,7 +33,7 @@ DataLoader, PoolDataLoader, SyncBatchNorm, _AdaptiveAvgPoolNd, _AdaptiveMaxPoolNd, _AvgPoolNd, _BatchNorm, _ConvNd, _ConvTransposeMixin, _InstanceNorm, _MaxPoolNd, get_build_config) - from .parrots_jit import jit, skip_no_elena, skip_no_parrots + from .parrots_jit import jit, skip_no_elena from .registry import Registry, build_from_cfg __all__ = [ 'Config', 'ConfigDict', 'DictAction', 'collect_env', 'get_logger', @@ -49,6 +49,5 @@ '_InstanceNorm', '_MaxPoolNd', 'get_build_config', 'BuildExtension', 'CppExtension', 'CUDAExtension', 'DataLoader', 'PoolDataLoader', 'TORCH_VERSION', 'deprecated_api_warning', 'digit_version', - 'get_git_hash', 'import_modules_from_strings', 'jit', 'skip_no_elena', - 'skip_no_parrots' + 'get_git_hash', 'import_modules_from_strings', 'jit', 'skip_no_elena' ] diff --git a/mmcv/utils/parrots_jit.py b/mmcv/utils/parrots_jit.py index 552fc999eb..609c11acd0 100644 --- a/mmcv/utils/parrots_jit.py +++ b/mmcv/utils/parrots_jit.py @@ -1,7 +1,4 @@ -import pytest -import torch - -TORCH_VERSION = torch.__version__ +from .parrots_wrapper import TORCH_VERSION if TORCH_VERSION == 'parrots': from parrots.jit import pat as jit @@ -37,11 +34,3 @@ def wrapper(*args, **kargs): return func(*args, **kargs) return wrapper - - -def is_using_parrots(): - return TORCH_VERSION == 'parrots' - - -skip_no_parrots = pytest.mark.skipif( - not is_using_parrots(), reason='test case under parrots environment') diff --git a/tests/test_utils/test_parrots_jit.py b/tests/test_utils/test_parrots_jit.py index 66c85e4298..78f8b9f602 100644 --- a/tests/test_utils/test_parrots_jit.py +++ b/tests/test_utils/test_parrots_jit.py @@ -2,6 +2,10 @@ import torch import mmcv +from mmcv.utils import TORCH_VERSION + +skip_no_parrots = pytest.mark.skipif( + TORCH_VERSION != 'parrots', reason='test case under parrots environment') class TestJit(object): @@ -55,7 +59,7 @@ def add_list_pyfunc(oper, x, y): assert f'k{idx}' in rets_t assert (rets[f'k{idx}'] == rets_t[f'k{idx}']).all() - @mmcv.skip_no_parrots + @skip_no_parrots def test_jit_cache(self): @mmcv.jit @@ -88,7 +92,7 @@ def pyfunc(oper): rets_a = (rets_minus_t + rets_plus_t) / 4 assert torch.allclose(oper['x'], rets_a) - @mmcv.skip_no_parrots + @skip_no_parrots def test_jit_shape(self): @mmcv.jit @@ -109,7 +113,7 @@ def func(a): assert (r == 2).all() assert len(func._cache._cache) == 2 - @mmcv.skip_no_parrots + @skip_no_parrots def test_jit_kwargs(self): @mmcv.jit @@ -206,7 +210,7 @@ def pyfunc(a, b): d = pyfunc(a, b) assert torch.allclose(c, d) - @mmcv.skip_no_parrots + @skip_no_parrots def test_jit_check_input(self): def func(x): @@ -217,7 +221,7 @@ def func(x): with pytest.raises(AssertionError): func = mmcv.jit(func, check_input=(a, )) - @mmcv.skip_no_parrots + @skip_no_parrots def test_jit_partial_shape(self): @mmcv.jit(full_shape=False)