test_download.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import pytest
  3. from click.testing import CliRunner
  4. from mim.commands.download import download
  5. from mim.commands.install import cli as install
  6. from mim.commands.uninstall import cli as uninstall
  7. def setup_module():
  8. runner = CliRunner()
  9. result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
  10. assert result.exit_code == 0
  11. result = runner.invoke(uninstall, ['mmcls', '--yes'])
  12. assert result.exit_code == 0
  13. def test_download(tmp_path):
  14. runner = CliRunner()
  15. result = runner.invoke(install, ['mmcv-full', '--yes'])
  16. assert result.exit_code == 0
  17. with pytest.raises(ValueError):
  18. # version is not allowed
  19. download('mmcls==0.11.0', ['resnet18_8xb16_cifar10'])
  20. with pytest.raises(RuntimeError):
  21. # mmcls is not installed
  22. download('mmcls', ['resnet18_8xb16_cifar10'])
  23. with pytest.raises(ValueError):
  24. # invalid config
  25. download('mmcls==0.11.0', ['resnet18_b16x8_cifar1'])
  26. runner = CliRunner()
  27. # mim install mmcls --yes
  28. result = runner.invoke(install, [
  29. 'mmcls', '--yes', '-f',
  30. 'https://github.com/open-mmlab/mmclassification.git'
  31. ])
  32. assert result.exit_code == 0
  33. # mim download mmcls --config resnet18_8xb16_cifar10
  34. checkpoints = download('mmcls', ['resnet18_8xb16_cifar10'])
  35. assert checkpoints == ['resnet18_b16x8_cifar10_20210528-bd6371c8.pth']
  36. checkpoints = download('mmcls', ['resnet18_8xb16_cifar10'])
  37. # mim download mmcls --config resnet18_8xb16_cifar10 --dest tmp_path
  38. checkpoints = download('mmcls', ['resnet18_8xb16_cifar10'], tmp_path)
  39. assert checkpoints == ['resnet18_b16x8_cifar10_20210528-bd6371c8.pth']
  40. def teardown_module():
  41. runner = CliRunner()
  42. result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
  43. assert result.exit_code == 0
  44. result = runner.invoke(uninstall, ['mmcls', '--yes'])
  45. assert result.exit_code == 0