2022-02-23 22:20:01 +08:00
|
|
|
# Copyright (c) OpenMMLab. All rights reserved.
|
2022-06-14 00:02:58 +08:00
|
|
|
import pytest
|
|
|
|
import torch
|
2021-05-20 00:03:43 +08:00
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
|
|
from mim.commands.install import cli as install
|
|
|
|
from mim.commands.run import cli as run
|
2022-06-14 00:02:58 +08:00
|
|
|
from mim.commands.uninstall import cli as uninstall
|
2021-05-20 00:03:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
def setup_module():
|
|
|
|
runner = CliRunner()
|
2022-06-14 00:02:58 +08:00
|
|
|
result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
|
|
|
|
assert result.exit_code == 0
|
2022-09-23 19:16:40 +08:00
|
|
|
result = runner.invoke(uninstall, ['mmcv', '--yes'])
|
|
|
|
assert result.exit_code == 0
|
2022-06-14 00:02:58 +08:00
|
|
|
result = runner.invoke(uninstall, ['mmcls', '--yes'])
|
|
|
|
assert result.exit_code == 0
|
2021-05-20 00:03:43 +08:00
|
|
|
|
|
|
|
|
2022-06-14 00:02:58 +08:00
|
|
|
@pytest.mark.parametrize('device,gpus', [
|
|
|
|
('cpu', 0),
|
|
|
|
pytest.param(
|
|
|
|
'cuda',
|
|
|
|
1,
|
|
|
|
marks=pytest.mark.skipif(
|
|
|
|
not torch.cuda.is_available(), reason='requires CUDA support')),
|
|
|
|
])
|
|
|
|
def test_run(device, gpus, tmp_path):
|
2021-05-20 00:03:43 +08:00
|
|
|
runner = CliRunner()
|
2022-09-23 19:16:40 +08:00
|
|
|
result = runner.invoke(install, ['mmcls>=1.0.0rc0', '--yes'])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
result = runner.invoke(install, ['mmengine', '--yes'])
|
2022-06-14 00:02:58 +08:00
|
|
|
assert result.exit_code == 0
|
2022-09-23 19:16:40 +08:00
|
|
|
result = runner.invoke(install, ['mmcv>=2.0.0rc0', '--yes'])
|
2022-06-22 20:09:10 +08:00
|
|
|
assert result.exit_code == 0
|
2021-05-20 00:03:43 +08:00
|
|
|
|
2022-06-14 00:02:58 +08:00
|
|
|
result = runner.invoke(run, [
|
2022-09-23 19:16:40 +08:00
|
|
|
'mmcls', 'train', 'tests/data/lenet5_mnist_2.0.py',
|
2022-06-14 00:02:58 +08:00
|
|
|
f'--work-dir={tmp_path}'
|
|
|
|
])
|
2021-05-24 22:23:45 +08:00
|
|
|
assert result.exit_code == 0
|
|
|
|
result = runner.invoke(run, [
|
2022-09-23 19:16:40 +08:00
|
|
|
'mmcls', 'test', 'tests/data/lenet5_mnist_2.0.py',
|
|
|
|
'tests/data/epoch_1.pth'
|
2021-05-24 22:23:45 +08:00
|
|
|
])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
result = runner.invoke(run, [
|
2022-09-23 19:16:40 +08:00
|
|
|
'mmcls', 'xxx', 'tests/data/lenet5_mnist_2.0.py',
|
|
|
|
'tests/data/epoch_1.pth'
|
2021-05-24 22:23:45 +08:00
|
|
|
])
|
|
|
|
assert result.exit_code != 0
|
2022-09-23 19:16:40 +08:00
|
|
|
result = runner.invoke(
|
|
|
|
run, ['mmcls', 'test', 'tests/data/xxx.py', 'tests/data/epoch_1.pth'])
|
2021-05-24 22:23:45 +08:00
|
|
|
assert result.exit_code != 0
|
|
|
|
|
2022-06-14 00:02:58 +08:00
|
|
|
|
|
|
|
def teardown_module():
|
|
|
|
runner = CliRunner()
|
|
|
|
result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
|
|
|
|
assert result.exit_code == 0
|
2022-09-23 19:16:40 +08:00
|
|
|
result = runner.invoke(uninstall, ['mmcv', '--yes'])
|
|
|
|
assert result.exit_code == 0
|
2022-06-14 00:02:58 +08:00
|
|
|
result = runner.invoke(uninstall, ['mmcls', '--yes'])
|
|
|
|
assert result.exit_code == 0
|