test_search.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import os.path as osp
  3. from click.testing import CliRunner
  4. from mim.commands.install import cli as install
  5. from mim.commands.search import cli as search
  6. from mim.commands.uninstall import cli as uninstall
  7. from mim.utils import DEFAULT_CACHE_DIR
  8. def setup_module():
  9. runner = CliRunner()
  10. result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
  11. assert result.exit_code == 0
  12. result = runner.invoke(uninstall, ['mmcls', '--yes'])
  13. assert result.exit_code == 0
  14. def test_search():
  15. runner = CliRunner()
  16. result = runner.invoke(install, ['mmcls', '--yes'])
  17. assert result.exit_code == 0
  18. # mim search mmcls
  19. result = runner.invoke(search, ['mmcls'])
  20. assert result.exit_code == 0
  21. # mim search mmcls --remote
  22. # search master branch
  23. result = runner.invoke(search, ['mmcls', '--remote'])
  24. assert result.exit_code == 0
  25. # mim search mmsegmentation --remote
  26. result = runner.invoke(search, ['mmsegmentation', '--remote'])
  27. assert result.exit_code == 0
  28. # mim search mmaction2 --remote
  29. result = runner.invoke(search, ['mmaction2', '--remote'])
  30. assert result.exit_code == 0
  31. # mim search mmcls==0.11.0 --remote
  32. result = runner.invoke(search, ['mmcls==0.11.0', '--remote'])
  33. assert result.exit_code == 0
  34. # the metadata of mmcls==0.11.0 will be saved in cache
  35. assert osp.exists(osp.join(DEFAULT_CACHE_DIR, 'mmcls-0.11.0.pkl'))
  36. # always test latest mmcls
  37. result = runner.invoke(uninstall, ['mmcls', '--yes'])
  38. assert result.exit_code == 0
  39. result = runner.invoke(install, ['mmcls', '--yes'])
  40. assert result.exit_code == 0
  41. # mim search mmcls --save_models res
  42. # invalid save_models
  43. result = runner.invoke(search, ['mmcls', '--save_models', 'res'])
  44. assert result.exit_code == 1
  45. # mim search mmcls --save_models resnet
  46. result = runner.invoke(search, ['mmcls', '--save_models', 'resnet'])
  47. assert result.exit_code == 0
  48. # mim search mmcls --valid-config
  49. result = runner.invoke(search, ['mmcls', '--valid-config'])
  50. assert result.exit_code == 0
  51. # mim search mmcls --config resnet18_b16x8_cifar1
  52. # invalid config
  53. result = runner.invoke(search,
  54. ['mmcls', '--config', 'resnet18_b16x8_cifar1'])
  55. assert result.exit_code == 1
  56. # mim search mmcls --config resnet18_b16x8_cifar10
  57. result = runner.invoke(search,
  58. ['mmcls', '--config', 'resnet18_8xb16_cifar10'])
  59. assert result.exit_code == 0
  60. # mim search mmcls --dataset cifar-1
  61. # invalid dataset
  62. result = runner.invoke(search, ['mmcls', '--dataset', 'cifar-1'])
  63. assert result.exit_code == 1
  64. # mim search mmcls --dataset cifar-10
  65. result = runner.invoke(search, ['mmcls', '--dataset', 'cifar-10'])
  66. assert result.exit_code == 0
  67. # mim search mmcls --condition 'batch_size>45,epochs>100'
  68. result = runner.invoke(
  69. search, ['mmcls', '--condition', 'batch_size>45,epochs>100'])
  70. assert result.exit_code == 0
  71. # mim search mmcls --condition 'batch_size>45 epochs>100'
  72. result = runner.invoke(
  73. search, ['mmcls', '--condition', 'batch_size>45 epochs>100'])
  74. assert result.exit_code == 0
  75. # mim search mmcls --condition '128<batch_size<=256'
  76. result = runner.invoke(search,
  77. ['mmcls', '--condition', '128<batch_size<=256'])
  78. assert result.exit_code == 0
  79. # mim search mmcls --sort epoch
  80. result = runner.invoke(search, ['mmcls', '--sort', 'epoch'])
  81. assert result.exit_code == 0
  82. # mim search mmcls --sort epochs
  83. result = runner.invoke(search, ['mmcls', '--sort', 'epochs'])
  84. assert result.exit_code == 0
  85. # mim search mmcls --sort batch_size epochs
  86. result = runner.invoke(search, ['mmcls', '--sort', 'batch_size', 'epochs'])
  87. assert result.exit_code == 0
  88. # mim search mmcls --field epoch
  89. result = runner.invoke(search, ['mmcls', '--field', 'epoch'])
  90. assert result.exit_code == 0
  91. # mim search mmcls --field epochs
  92. result = runner.invoke(search, ['mmcls', '--field', 'epochs'])
  93. assert result.exit_code == 0
  94. def teardown_module():
  95. runner = CliRunner()
  96. result = runner.invoke(uninstall, ['mmcv-full', '--yes'])
  97. assert result.exit_code == 0
  98. result = runner.invoke(uninstall, ['mmcls', '--yes'])
  99. assert result.exit_code == 0