|
@@ -35,12 +35,32 @@ def test_interpolate_context_escapes_interpolated_variables():
|
|
|
)
|
|
|
|
|
|
|
|
|
+def test_make_environment_without_pyinstaller_does_not_touch_environment():
|
|
|
+ assert module.make_environment({}, sys_module=flexmock()) == {}
|
|
|
+
|
|
|
+
|
|
|
+def test_make_environment_with_pyinstaller_clears_LD_LIBRARY_PATH():
|
|
|
+ assert module.make_environment({}, sys_module=flexmock(frozen=True, _MEIPASS='yup')) == {
|
|
|
+ 'LD_LIBRARY_PATH': ''
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+def test_make_environment_with_pyinstaller_and_LD_LIBRARY_PATH_ORIG_copies_it_into_LD_LIBRARY_PATH():
|
|
|
+ assert module.make_environment(
|
|
|
+ {'LD_LIBRARY_PATH_ORIG': '/lib/lib/lib'}, sys_module=flexmock(frozen=True, _MEIPASS='yup')
|
|
|
+ ) == {'LD_LIBRARY_PATH': '/lib/lib/lib'}
|
|
|
+
|
|
|
+
|
|
|
def test_execute_hook_invokes_each_command():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
- flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
- [':'], output_log_level=logging.WARNING, shell=True
|
|
|
+ flexmock(module).should_receive('make_environment').and_return({})
|
|
|
+ flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
|
|
+ [':'],
|
|
|
+ output_log_level=logging.WARNING,
|
|
|
+ shell=True,
|
|
|
+ extra_environment={},
|
|
|
).once()
|
|
|
|
|
|
module.execute_hook([':'], None, 'config.yaml', 'pre-backup', dry_run=False)
|
|
@@ -50,11 +70,18 @@ def test_execute_hook_with_multiple_commands_invokes_each_command():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
- flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
- [':'], output_log_level=logging.WARNING, shell=True
|
|
|
+ flexmock(module).should_receive('make_environment').and_return({})
|
|
|
+ flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
|
|
+ [':'],
|
|
|
+ output_log_level=logging.WARNING,
|
|
|
+ shell=True,
|
|
|
+ extra_environment={},
|
|
|
).once()
|
|
|
- flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
- ['true'], output_log_level=logging.WARNING, shell=True
|
|
|
+ flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
|
|
+ ['true'],
|
|
|
+ output_log_level=logging.WARNING,
|
|
|
+ shell=True,
|
|
|
+ extra_environment={},
|
|
|
).once()
|
|
|
|
|
|
module.execute_hook([':', 'true'], None, 'config.yaml', 'pre-backup', dry_run=False)
|
|
@@ -66,8 +93,12 @@ def test_execute_hook_with_umask_sets_that_umask():
|
|
|
)
|
|
|
flexmock(module.os).should_receive('umask').with_args(0o77).and_return(0o22).once()
|
|
|
flexmock(module.os).should_receive('umask').with_args(0o22).once()
|
|
|
- flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
- [':'], output_log_level=logging.WARNING, shell=True
|
|
|
+ flexmock(module).should_receive('make_environment').and_return({})
|
|
|
+ flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
|
|
+ [':'],
|
|
|
+ output_log_level=logging.WARNING,
|
|
|
+ shell=True,
|
|
|
+ extra_environment={},
|
|
|
)
|
|
|
|
|
|
module.execute_hook([':'], 77, 'config.yaml', 'pre-backup', dry_run=False)
|
|
@@ -77,7 +108,8 @@ def test_execute_hook_with_dry_run_skips_commands():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
- flexmock(module.execute).should_receive('execute_command').never()
|
|
|
+ flexmock(module).should_receive('make_environment').and_return({})
|
|
|
+ flexmock(module.borgmatic.execute).should_receive('execute_command').never()
|
|
|
|
|
|
module.execute_hook([':', 'true'], None, 'config.yaml', 'pre-backup', dry_run=True)
|
|
|
|
|
@@ -90,8 +122,12 @@ def test_execute_hook_on_error_logs_as_error():
|
|
|
flexmock(module).should_receive('interpolate_context').replace_with(
|
|
|
lambda config_file, hook_description, command, context: command
|
|
|
)
|
|
|
- flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
- [':'], output_log_level=logging.ERROR, shell=True
|
|
|
+ flexmock(module).should_receive('make_environment').and_return({})
|
|
|
+ flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
|
|
+ [':'],
|
|
|
+ output_log_level=logging.ERROR,
|
|
|
+ shell=True,
|
|
|
+ extra_environment={},
|
|
|
).once()
|
|
|
|
|
|
module.execute_hook([':'], None, 'config.yaml', 'on-error', dry_run=False)
|