mim/tests/test_train.py

45 lines
1.2 KiB
Python
Raw Normal View History

2021-05-20 00:03:43 +08:00
import os.path as osp
2021-05-24 22:23:45 +08:00
import shutil
2021-05-20 00:03:43 +08:00
import time
from click.testing import CliRunner
from mim.commands.install import cli as install
from mim.commands.train import cli as train
from mim.utils import download_from_file, extract_tar, is_installed
2021-05-20 17:18:31 +08:00
dataset_url = 'https://download.openmmlab.com/mim/dataset.tar'
cfg_url = 'https://download.openmmlab.com/mim/resnet18_b16x8_custom.py'
2021-05-20 00:03:43 +08:00
def setup_module():
runner = CliRunner()
if not is_installed('mmcls'):
result = runner.invoke(install, ['mmcls', '--yes'])
assert result.exit_code == 0
def test_train():
runner = CliRunner()
2021-05-24 22:23:45 +08:00
if not osp.exists('/tmp/dataset'):
download_from_file(dataset_url, '/tmp/dataset.tar')
extract_tar('/tmp/dataset.tar', '/tmp/')
2021-05-20 00:03:43 +08:00
2021-05-24 22:23:45 +08:00
if not osp.exists('/tmp/config.py'):
download_from_file(cfg_url, '/tmp/config.py')
2021-05-20 00:03:43 +08:00
2021-05-24 22:23:45 +08:00
# wait for the download task to complete
time.sleep(5)
2021-05-20 00:03:43 +08:00
2021-05-24 22:23:45 +08:00
result = runner.invoke(
train, ['mmcls', '/tmp/config.py', '--gpus=0', '--work-dir=tmp'])
2021-05-24 22:23:45 +08:00
assert result.exit_code == 0
result = runner.invoke(
train, ['mmcls', '/tmp/xxx.py', '--gpus=0', '--work-dir=tmp'])
2021-05-24 22:23:45 +08:00
assert result.exit_code != 0
2021-05-20 00:03:43 +08:00
2021-05-24 22:23:45 +08:00
shutil.rmtree('tmp')