test_borgmatic.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from flexmock import flexmock
  2. import pytest
  3. from borgmatic.commands import borgmatic as module
  4. def test_parse_arguments_with_no_arguments_uses_defaults():
  5. config_paths = ['default']
  6. flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
  7. parser = module.parse_arguments()
  8. assert parser.config_paths == config_paths
  9. assert parser.excludes_filename is None
  10. assert parser.verbosity is 0
  11. assert parser.json is False
  12. def test_parse_arguments_with_path_arguments_overrides_defaults():
  13. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  14. parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
  15. assert parser.config_paths == ['myconfig']
  16. assert parser.excludes_filename == 'myexcludes'
  17. assert parser.verbosity is 0
  18. def test_parse_arguments_with_multiple_config_paths_parses_as_list():
  19. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  20. parser = module.parse_arguments('--config', 'myconfig', 'otherconfig')
  21. assert parser.config_paths == ['myconfig', 'otherconfig']
  22. assert parser.verbosity is 0
  23. def test_parse_arguments_with_verbosity_flag_overrides_default():
  24. config_paths = ['default']
  25. flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
  26. parser = module.parse_arguments('--verbosity', '1')
  27. assert parser.config_paths == config_paths
  28. assert parser.excludes_filename is None
  29. assert parser.verbosity == 1
  30. def test_parse_arguments_with_json_flag_overrides_default():
  31. parser = module.parse_arguments('--list', '--json')
  32. assert parser.json is True
  33. def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled():
  34. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  35. parser = module.parse_arguments()
  36. assert parser.prune is True
  37. assert parser.create is True
  38. assert parser.check is True
  39. def test_parse_arguments_with_prune_action_leaves_other_actions_disabled():
  40. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  41. parser = module.parse_arguments('--prune')
  42. assert parser.prune is True
  43. assert parser.create is False
  44. assert parser.check is False
  45. def test_parse_arguments_with_multiple_actions_leaves_other_action_disabled():
  46. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  47. parser = module.parse_arguments('--create', '--check')
  48. assert parser.prune is False
  49. assert parser.create is True
  50. assert parser.check is True
  51. def test_parse_arguments_with_invalid_arguments_exits():
  52. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  53. with pytest.raises(SystemExit):
  54. module.parse_arguments('--posix-me-harder')
  55. def test_parse_arguments_with_json_flag_with_list_or_info_flag_does_not_raise_any_error():
  56. module.parse_arguments('--list', '--json')
  57. module.parse_arguments('--info', '--json')
  58. def test_parse_arguments_with_json_flag_but_no_list_or_info_flag_raises_value_error():
  59. with pytest.raises(ValueError):
  60. module.parse_arguments('--json')
  61. def test_parse_arguments_with_json_flag_and_both_list_and_info_flag_raises_value_error():
  62. with pytest.raises(ValueError):
  63. module.parse_arguments('--list', '--info', '--json')