test_execute.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic import execute as module
  4. def test_execute_command_calls_full_command():
  5. full_command = ['foo', 'bar']
  6. flexmock(module).should_receive('execute_and_log_output').with_args(
  7. full_command, output_log_level=logging.INFO, shell=False
  8. ).once()
  9. output = module.execute_command(full_command)
  10. assert output is None
  11. def test_execute_command_calls_full_command_with_shell():
  12. full_command = ['foo', 'bar']
  13. flexmock(module).should_receive('execute_and_log_output').with_args(
  14. full_command, output_log_level=logging.INFO, shell=True
  15. ).once()
  16. output = module.execute_command(full_command, shell=True)
  17. assert output is None
  18. def test_execute_command_captures_output():
  19. full_command = ['foo', 'bar']
  20. expected_output = '[]'
  21. flexmock(module.subprocess).should_receive('check_output').with_args(
  22. full_command, shell=False
  23. ).and_return(flexmock(decode=lambda: expected_output)).once()
  24. output = module.execute_command(full_command, output_log_level=None)
  25. assert output == expected_output
  26. def test_execute_command_captures_output_with_shell():
  27. full_command = ['foo', 'bar']
  28. expected_output = '[]'
  29. flexmock(module.subprocess).should_receive('check_output').with_args(
  30. full_command, shell=True
  31. ).and_return(flexmock(decode=lambda: expected_output)).once()
  32. output = module.execute_command(full_command, output_log_level=None, shell=True)
  33. assert output == expected_output