test_execute.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import logging
  2. import subprocess
  3. import pytest
  4. from flexmock import flexmock
  5. from borgmatic import execute as module
  6. def test_execute_and_log_output_logs_each_line_separately():
  7. flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'hi').once()
  8. flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'there').once()
  9. module.execute_and_log_output(['echo', 'hi'], output_log_level=logging.INFO, shell=False)
  10. module.execute_and_log_output(['echo', 'there'], output_log_level=logging.INFO, shell=False)
  11. def test_execute_and_log_output_logs_borg_error_as_error():
  12. flexmock(module.logger).should_receive('error').with_args('borg: error: oopsie').once()
  13. module.execute_and_log_output(
  14. ['echo', 'borg: error: oopsie'], output_log_level=logging.INFO, shell=False
  15. )
  16. def test_execute_and_log_output_with_no_output_logs_nothing():
  17. flexmock(module.logger).should_receive('log').never()
  18. module.execute_and_log_output(['true'], output_log_level=logging.INFO, shell=False)
  19. def test_execute_and_log_output_with_error_exit_status_raises():
  20. flexmock(module.logger).should_receive('log').never()
  21. with pytest.raises(subprocess.CalledProcessError):
  22. module.execute_and_log_output(['false'], output_log_level=logging.INFO, shell=False)