mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
Use pytest tmp_path fixture instead of hardcoded /tmp paths (#1296).
Reviewed-on: https://projects.torsion.org/borgmatic-collective/borgmatic/pulls/1296
This commit is contained in:
@@ -315,10 +315,10 @@ def test_write_configuration_with_already_existing_file_raises():
|
||||
module.write_configuration('config.yaml', 'config: yaml')
|
||||
|
||||
|
||||
def test_write_configuration_with_already_existing_file_and_overwrite_does_not_raise():
|
||||
def test_write_configuration_with_already_existing_file_and_overwrite_does_not_raise(tmp_path):
|
||||
flexmock(os.path).should_receive('exists').and_return(True)
|
||||
|
||||
module.write_configuration('/tmp/config.yaml', 'config: yaml', overwrite=True)
|
||||
module.write_configuration(str(tmp_path / 'config.yaml'), 'config: yaml', overwrite=True)
|
||||
|
||||
|
||||
def test_write_configuration_with_already_existing_directory_does_not_raise():
|
||||
|
||||
@@ -222,11 +222,11 @@ def test_parse_configuration_merges_include():
|
||||
assert logs == []
|
||||
|
||||
|
||||
def test_parse_configuration_raises_for_missing_config_file():
|
||||
def test_parse_configuration_raises_for_missing_config_file(tmp_path):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
module.parse_configuration(
|
||||
'/tmp/config.yaml',
|
||||
'/tmp/schema.yaml',
|
||||
str(tmp_path / 'nonexistent' / 'config.yaml'),
|
||||
str(tmp_path / 'nonexistent' / 'schema.yaml'),
|
||||
arguments={'global': flexmock()},
|
||||
)
|
||||
|
||||
|
||||
+15
-12
@@ -699,7 +699,7 @@ def test_configure_logging_skips_log_file_if_log_file_logging_is_disabled():
|
||||
)
|
||||
|
||||
|
||||
def test_configure_logging_to_log_file_instead_of_syslog():
|
||||
def test_configure_logging_to_log_file_instead_of_syslog(tmp_path):
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
@@ -716,20 +716,21 @@ def test_configure_logging_to_log_file_instead_of_syslog():
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').never()
|
||||
file_handler = logging.handlers.WatchedFileHandler('/tmp/logfile')
|
||||
log_file = str(tmp_path / 'logfile')
|
||||
file_handler = logging.handlers.WatchedFileHandler(log_file)
|
||||
flexmock(module.logging.handlers).should_receive('WatchedFileHandler').with_args(
|
||||
'/tmp/logfile',
|
||||
log_file,
|
||||
).and_return(file_handler).once()
|
||||
|
||||
module.configure_logging(
|
||||
console_log_level=logging.INFO,
|
||||
syslog_log_level=logging.DISABLED,
|
||||
log_file_log_level=logging.DEBUG,
|
||||
log_file='/tmp/logfile',
|
||||
log_file=log_file,
|
||||
)
|
||||
|
||||
|
||||
def test_configure_logging_to_both_log_file_and_syslog():
|
||||
def test_configure_logging_to_both_log_file_and_syslog(tmp_path):
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
@@ -752,20 +753,21 @@ def test_configure_logging_to_both_log_file_and_syslog():
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').with_args(
|
||||
address='/dev/log',
|
||||
).and_return(syslog_handler).once()
|
||||
file_handler = logging.handlers.WatchedFileHandler('/tmp/logfile')
|
||||
log_file = str(tmp_path / 'logfile')
|
||||
file_handler = logging.handlers.WatchedFileHandler(log_file)
|
||||
flexmock(module.logging.handlers).should_receive('WatchedFileHandler').with_args(
|
||||
'/tmp/logfile',
|
||||
log_file,
|
||||
).and_return(file_handler).once()
|
||||
|
||||
module.configure_logging(
|
||||
console_log_level=logging.INFO,
|
||||
syslog_log_level=logging.DEBUG,
|
||||
log_file_log_level=logging.DEBUG,
|
||||
log_file='/tmp/logfile',
|
||||
log_file=log_file,
|
||||
)
|
||||
|
||||
|
||||
def test_configure_logging_to_log_file_formats_with_custom_log_format():
|
||||
def test_configure_logging_to_log_file_formats_with_custom_log_format(tmp_path):
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module).should_receive('Log_prefix_formatter').with_args(
|
||||
@@ -786,15 +788,16 @@ def test_configure_logging_to_log_file_formats_with_custom_log_format():
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(True)
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').never()
|
||||
file_handler = logging.handlers.WatchedFileHandler('/tmp/logfile')
|
||||
log_file = str(tmp_path / 'logfile')
|
||||
file_handler = logging.handlers.WatchedFileHandler(log_file)
|
||||
flexmock(module.logging.handlers).should_receive('WatchedFileHandler').with_args(
|
||||
'/tmp/logfile',
|
||||
log_file,
|
||||
).and_return(file_handler).once()
|
||||
|
||||
module.configure_logging(
|
||||
console_log_level=logging.INFO,
|
||||
log_file_log_level=logging.DEBUG,
|
||||
log_file='/tmp/logfile',
|
||||
log_file=log_file,
|
||||
log_file_format='{message}',
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user