3
0

test_install.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import os
  3. import os.path as osp
  4. import subprocess
  5. import tempfile
  6. from click.testing import CliRunner
  7. from mim.commands.install import cli as install
  8. from mim.commands.uninstall import cli as uninstall
  9. def test_third_party():
  10. runner = CliRunner()
  11. # mim install fire
  12. result = runner.invoke(install, ['fire'])
  13. assert result.exit_code == 0
  14. # mim uninstall fire --yes
  15. result = runner.invoke(uninstall, ['fire', '--yes'])
  16. assert result.exit_code == 0
  17. def test_mmcv_install():
  18. runner = CliRunner()
  19. # mim install mmcv-full --yes
  20. # install latest version
  21. result = runner.invoke(install, ['mmcv-full', '--yes'])
  22. assert result.exit_code == 0
  23. # mim install mmcv-full==1.3.1 --yes
  24. result = runner.invoke(install, ['mmcv-full==1.3.1', '--yes'])
  25. assert result.exit_code == 0
  26. # mim uninstall mmcv-full --yes
  27. result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
  28. assert result.exit_code == 0
  29. # version should be less than latest version
  30. # mim install mmcv-full==100.0.0 --yes
  31. result = runner.invoke(install, ['mmcv-full==100.0.0', '--yes'])
  32. assert result.exit_code == 1
  33. def test_mmrepo_install():
  34. runner = CliRunner()
  35. # install local repo
  36. with tempfile.TemporaryDirectory() as temp_root:
  37. repo_root = osp.join(temp_root, 'mmclassification')
  38. subprocess.check_call([
  39. 'git', 'clone',
  40. 'https://github.com/open-mmlab/mmclassification.git', repo_root
  41. ])
  42. # mim install .
  43. current_root = os.getcwd()
  44. os.chdir(repo_root)
  45. result = runner.invoke(install, ['.', '--yes'])
  46. assert result.exit_code == 0
  47. os.chdir('..')
  48. # mim install ./mmclassification
  49. result = runner.invoke(install, ['./mmclassification', '--yes'])
  50. assert result.exit_code == 0
  51. # mim install -e ./mmclassification
  52. result = runner.invoke(install, ['-e', './mmclassification', '--yes'])
  53. assert result.exit_code == 0
  54. os.chdir(current_root)
  55. # mim install git+https://github.com/open-mmlab/mmclassification.git
  56. result = runner.invoke(
  57. install, ['git+https://github.com/open-mmlab/mmclassification.git'])
  58. assert result.exit_code == 0
  59. # mim install mmcls --yes
  60. result = runner.invoke(install, ['mmcls', '--yes'])
  61. assert result.exit_code == 0
  62. # mim install mmcls==0.11.0 --yes
  63. result = runner.invoke(install, ['mmcls==0.11.0', '--yes'])
  64. assert result.exit_code == 0
  65. result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
  66. assert result.exit_code == 0
  67. result = runner.invoke(uninstall, ['mmcls', '--yes'])
  68. assert result.exit_code == 0