From aa6b6e0d96b14a064a2d68edd01f25c23b5da852 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 6 Jan 2026 22:32:42 -0800 Subject: [PATCH] Fix many tests (#1225). --- borgmatic/borg/create.py | 8 +- borgmatic/execute.py | 4 +- tests/integration/test_execute.py | 66 +++---- tests/unit/hooks/data_source/test_sqlite.py | 12 +- tests/unit/hooks/data_source/test_zfs.py | 32 ++-- tests/unit/test_execute.py | 184 +++++++++++--------- 6 files changed, 153 insertions(+), 153 deletions(-) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 446fc99c..b7e42601 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -128,11 +128,9 @@ def validate_planned_backup_paths( # If all root patterns in the runtime directory are missing from the paths Borg is planning # to backup, then they must've gotten excluded, e.g. by user-configured excludes. Warn # accordingly (below). - if ( - validate_runtime_directory and any( - any_parent_directories(path, (pattern.path,)) - for pattern in runtime_directory_root_patterns - ) + if validate_runtime_directory and any( + any_parent_directories(path, (pattern.path,)) + for pattern in runtime_directory_root_patterns ): runtime_directory_in_path = True diff --git a/borgmatic/execute.py b/borgmatic/execute.py index f36c7aaf..708c2935 100644 --- a/borgmatic/execute.py +++ b/borgmatic/execute.py @@ -485,7 +485,7 @@ def execute_command_and_capture_output( borg_exit_codes, ) - return captured_lines + yield from captured_lines def execute_command_with_processes( @@ -557,4 +557,4 @@ def execute_command_with_processes( borg_exit_codes, ) - return captured_lines + yield from captured_lines diff --git a/tests/integration/test_execute.py b/tests/integration/test_execute.py index c58c3773..0704d925 100644 --- a/tests/integration/test_execute.py +++ b/tests/integration/test_execute.py @@ -43,7 +43,7 @@ def test_log_outputs_logs_each_line_separately(): (), ).and_return((there_process.stdout,)) - assert ( + assert tuple( module.log_outputs( (hi_process, there_process), exclude_stdouts=(), @@ -51,8 +51,7 @@ def test_log_outputs_logs_each_line_separately(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_logs_stderr_as_error(): @@ -76,7 +75,7 @@ def test_log_outputs_logs_stderr_as_error(): (), ).and_return((echo_process.stdout, echo_process.stderr)) - assert ( + assert tuple( module.log_outputs( (echo_process,), exclude_stdouts=(), @@ -84,8 +83,7 @@ def test_log_outputs_logs_stderr_as_error(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_skips_logs_for_process_with_none_stdout(): @@ -114,7 +112,7 @@ def test_log_outputs_skips_logs_for_process_with_none_stdout(): (), ).and_return((there_process.stdout,)) - assert ( + assert tuple( module.log_outputs( (hi_process, there_process), exclude_stdouts=(), @@ -122,8 +120,7 @@ def test_log_outputs_skips_logs_for_process_with_none_stdout(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_returns_output_without_logging_for_output_log_level_none(): @@ -142,15 +139,15 @@ def test_log_outputs_returns_output_without_logging_for_output_log_level_none(): (), ).and_return((there_process.stdout,)) - captured_outputs = module.log_outputs( + output_lines = tuple(module.log_outputs( (hi_process, there_process), exclude_stdouts=(), output_log_level=None, borg_local_path='borg', borg_exit_codes=None, - ) + )) - assert captured_outputs == {hi_process: 'hi', there_process: 'there'} + assert output_lines == ('there',) def test_log_outputs_includes_error_output_in_exception(): @@ -162,13 +159,13 @@ def test_log_outputs_includes_error_output_in_exception(): flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,)) with pytest.raises(subprocess.CalledProcessError) as error: - module.log_outputs( + tuple(module.log_outputs( (process,), exclude_stdouts=(), output_log_level=logging.INFO, borg_local_path='borg', borg_exit_codes=None, - ) + )) assert error.value.output @@ -190,13 +187,13 @@ def test_log_outputs_logs_multiline_error_output(): flexmock(module.logger).should_call('handle').at_least().times(3) with pytest.raises(subprocess.CalledProcessError): - module.log_outputs( + tuple(module.log_outputs( (process,), exclude_stdouts=(), output_log_level=logging.INFO, borg_local_path='borg', borg_exit_codes=None, - ) + )) def test_log_outputs_skips_error_output_in_exception_for_process_with_none_stdout(): @@ -208,13 +205,13 @@ def test_log_outputs_skips_error_output_in_exception_for_process_with_none_stdou flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,)) with pytest.raises(subprocess.CalledProcessError) as error: - module.log_outputs( + tuple(module.log_outputs( (process,), exclude_stdouts=(), output_log_level=logging.INFO, borg_local_path='borg', borg_exit_codes=None, - ) + )) assert error.value.returncode == 2 assert not error.value.output @@ -258,13 +255,13 @@ def test_log_outputs_kills_other_processes_and_raises_when_one_errors(): flexmock(other_process).should_receive('kill').once() with pytest.raises(subprocess.CalledProcessError) as error: - module.log_outputs( + tuple(module.log_outputs( (process, other_process), exclude_stdouts=(), output_log_level=logging.INFO, borg_local_path='borg', borg_exit_codes=None, - ) + )) assert error.value.returncode == 2 assert error.value.output @@ -307,7 +304,7 @@ def test_log_outputs_kills_other_processes_and_returns_when_one_exits_with_warni ).and_return((other_process.stdout,)) flexmock(other_process).should_receive('kill').once() - assert ( + assert tuple( module.log_outputs( (process, other_process), exclude_stdouts=(), @@ -315,8 +312,7 @@ def test_log_outputs_kills_other_processes_and_returns_when_one_exits_with_warni borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_vents_other_processes_when_one_exits(): @@ -354,7 +350,7 @@ def test_log_outputs_vents_other_processes_when_one_exits(): ).and_return((other_process.stdout,)) flexmock(process.stdout).should_call('readline').at_least().once() - assert ( + assert tuple( module.log_outputs( (process, other_process), exclude_stdouts=(process.stdout,), @@ -362,8 +358,7 @@ def test_log_outputs_vents_other_processes_when_one_exits(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_does_not_error_when_one_process_exits(): @@ -394,7 +389,7 @@ def test_log_outputs_does_not_error_when_one_process_exits(): (process.stdout,), ).and_return((other_process.stdout,)) - assert ( + assert tuple( module.log_outputs( (process, other_process), exclude_stdouts=(process.stdout,), @@ -402,8 +397,7 @@ def test_log_outputs_does_not_error_when_one_process_exits(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_truncates_long_error_output(): @@ -426,13 +420,13 @@ def test_log_outputs_truncates_long_error_output(): flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,)) with pytest.raises(subprocess.CalledProcessError) as error: - flexmock(module, ERROR_OUTPUT_MAX_LINE_COUNT=0).log_outputs( + tuple(flexmock(module, ERROR_OUTPUT_MAX_LINE_COUNT=0).log_outputs( (process,), exclude_stdouts=(), output_log_level=logging.INFO, borg_local_path='borg', borg_exit_codes=None, - ) + )) assert error.value.returncode == 2 assert error.value.output.startswith('...') @@ -445,7 +439,7 @@ def test_log_outputs_with_no_output_logs_nothing(): process = subprocess.Popen(['true'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,)) - assert ( + assert tuple( module.log_outputs( (process,), exclude_stdouts=(), @@ -453,8 +447,7 @@ def test_log_outputs_with_no_output_logs_nothing(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () def test_log_outputs_with_unfinished_process_re_polls(): @@ -465,7 +458,7 @@ def test_log_outputs_with_unfinished_process_re_polls(): flexmock(process).should_receive('poll').and_return(None).and_return(0).times(3) flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,)) - assert ( + assert tuple( module.log_outputs( (process,), exclude_stdouts=(), @@ -473,5 +466,4 @@ def test_log_outputs_with_unfinished_process_re_polls(): borg_local_path='borg', borg_exit_codes=None, ) - == {} - ) + ) == () diff --git a/tests/unit/hooks/data_source/test_sqlite.py b/tests/unit/hooks/data_source/test_sqlite.py index 9feab9db..fb132884 100644 --- a/tests/unit/hooks/data_source/test_sqlite.py +++ b/tests/unit/hooks/data_source/test_sqlite.py @@ -341,7 +341,7 @@ def test_restore_data_source_dump_restores_database(): output_log_level=logging.DEBUG, input_file=extract_process.stdout, working_directory=None, - ).once() + ).and_yield().once() flexmock(module.os).should_receive('remove').once() @@ -379,7 +379,7 @@ def test_restore_data_source_dump_runs_non_default_sqlite_restores_database(): output_log_level=logging.DEBUG, input_file=extract_process.stdout, working_directory=None, - ).once() + ).and_yield().once() flexmock(module.os).should_receive('remove').once() @@ -415,7 +415,7 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_ output_log_level=logging.DEBUG, input_file=extract_process.stdout, working_directory=None, - ).once() + ).and_yield().once() flexmock(module.os).should_receive('remove').once() @@ -451,7 +451,7 @@ def test_restore_data_source_dump_runs_non_default_sqlite_with_connection_params output_log_level=logging.DEBUG, input_file=extract_process.stdout, working_directory=None, - ).once() + ).and_yield().once() flexmock(module.os).should_receive('remove').once() @@ -489,7 +489,7 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_ output_log_level=logging.DEBUG, input_file=extract_process.stdout, working_directory=None, - ).once() + ).and_yield().once() flexmock(module.os).should_receive('remove').once() @@ -526,7 +526,7 @@ def test_restore_data_source_dump_runs_non_default_sqlite_without_connection_par output_log_level=logging.DEBUG, input_file=extract_process.stdout, working_directory=None, - ).once() + ).and_yield().once() flexmock(module.os).should_receive('remove').once() diff --git a/tests/unit/hooks/data_source/test_zfs.py b/tests/unit/hooks/data_source/test_zfs.py index cdb39d94..042e7e08 100644 --- a/tests/unit/hooks/data_source/test_zfs.py +++ b/tests/unit/hooks/data_source/test_zfs.py @@ -8,8 +8,8 @@ from borgmatic.hooks.data_source import zfs as module def test_get_datasets_to_backup_filters_datasets_by_patterns(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - 'dataset\t/dataset\ton\t-\nother\t/other\ton\t-', + ).and_yield( + 'dataset\t/dataset\ton\t-', 'other\t/other\ton\t-', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -63,8 +63,8 @@ def test_get_datasets_to_backup_filters_datasets_by_patterns(): def test_get_datasets_to_backup_skips_non_root_patterns(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - 'dataset\t/dataset\ton\t-\nother\t/other\ton\t-', + ).and_yield( + 'dataset\t/dataset\ton\t-', 'other\t/other\ton\t-', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -109,8 +109,8 @@ def test_get_datasets_to_backup_skips_non_root_patterns(): def test_get_datasets_to_backup_skips_non_config_patterns(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - 'dataset\t/dataset\ton\t-\nother\t/other\ton\t-', + ).and_yield( + 'dataset\t/dataset\ton\t-', 'other\t/other\ton\t-', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -155,8 +155,8 @@ def test_get_datasets_to_backup_skips_non_config_patterns(): def test_get_datasets_to_backup_filters_datasets_by_user_property(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - 'dataset\t/dataset\ton\tauto\nother\t/other\ton\t-', + ).and_yield( + 'dataset\t/dataset\ton\tauto', 'other\t/other\ton\t-', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -181,8 +181,8 @@ def test_get_datasets_to_backup_filters_datasets_by_user_property(): def test_get_datasets_to_backup_filters_datasets_by_canmount_property(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - 'dataset\t/dataset\toff\t-\nother\t/other\ton\t-', + ).and_yield( + 'dataset\t/dataset\toff\t-', 'other\t/other\ton\t-', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -207,7 +207,7 @@ def test_get_datasets_to_backup_filters_datasets_by_canmount_property(): def test_get_datasets_to_backup_with_invalid_list_output_raises(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( + ).and_yield( 'dataset', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( @@ -221,8 +221,8 @@ def test_get_datasets_to_backup_with_invalid_list_output_raises(): def test_get_all_dataset_mount_points_omits_none(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - '/dataset\nnone\n/other', + ).and_yield( + '/dataset', 'none', '/other', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -238,7 +238,7 @@ def test_get_all_dataset_mount_points_omits_duplicates(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', ).and_return( - '/dataset\n/other\n/dataset\n/other', + '/dataset', '/other', '/dataset', '/other', ) flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive( 'get_contained_patterns', @@ -506,8 +506,8 @@ def test_dump_data_sources_ignores_mismatch_between_given_patterns_and_contained def test_get_all_snapshots_parses_list_output(): flexmock(module.borgmatic.execute).should_receive( 'execute_command_and_capture_output', - ).and_return( - 'dataset1@borgmatic-1234\ndataset2@borgmatic-4567', + ).and_yield( + 'dataset1@borgmatic-1234', 'dataset2@borgmatic-4567', ) assert module.get_all_snapshots('zfs') == ('dataset1@borgmatic-1234', 'dataset2@borgmatic-4567') diff --git a/tests/unit/test_execute.py b/tests/unit/test_execute.py index 4a277fe9..a0b88422 100644 --- a/tests/unit/test_execute.py +++ b/tests/unit/test_execute.py @@ -207,11 +207,14 @@ def test_parse_log_line_with_came_from_stderr_and_warning_prefix_makes_warning_r def test_handle_log_record_under_max_line_count_appends(): last_lines = ['last'] flexmock(module.logger).should_receive('handle').once() + log_record = flexmock(levelno=module.logging.INFO, getMessage=lambda: 'line') - module.handle_log_record( - flexmock(levelno=module.logging.INFO, getMessage=lambda: 'line'), - last_lines, - captured_output=flexmock(), + assert ( + module.handle_log_record( + log_record, + last_lines, + ) + == log_record ) assert last_lines == ['last', 'line'] @@ -221,30 +224,19 @@ def test_handle_log_record_over_max_line_count_trims_and_appends(): original_last_lines = [str(number) for number in range(module.ERROR_OUTPUT_MAX_LINE_COUNT)] last_lines = list(original_last_lines) flexmock(module.logger).should_receive('handle').once() + log_record = flexmock(levelno=module.logging.INFO, getMessage=lambda: 'line') - module.handle_log_record( - flexmock(levelno=module.logging.INFO, getMessage=lambda: 'line'), - last_lines, - captured_output=flexmock(), + assert ( + module.handle_log_record( + log_record, + last_lines, + ) + == log_record ) assert last_lines == [*original_last_lines[1:], 'line'] -def test_handle_log_record_with_output_log_level_none_appends_captured_output(): - last_lines = ['last'] - captured_output = ['captured'] - flexmock(module.logger).should_receive('handle').never() - - module.handle_log_record( - flexmock(levelno=None, getMessage=lambda: 'line'), - last_lines, - captured_output=captured_output, - ) - - assert captured_output == ['captured', 'line'] - - def test_mask_command_secrets_masks_password_flag_value(): assert module.mask_command_secrets(('cooldb', '--username', 'bob', '--password', 'pass')) == ( 'cooldb', @@ -326,7 +318,7 @@ def test_execute_command_calls_full_command(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command) @@ -348,7 +340,7 @@ def test_execute_command_calls_full_command_with_output_file(): close_fds=False, ).and_return(flexmock(stderr=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command, output_file=output_file) @@ -370,7 +362,7 @@ def test_execute_command_calls_full_command_without_capturing_output(): ).and_return(flexmock(wait=lambda: 0)).once() flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS) flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command, output_file=module.DO_NOT_CAPTURE) @@ -392,7 +384,7 @@ def test_execute_command_calls_full_command_with_input_file(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command, input_file=input_file) @@ -413,7 +405,7 @@ def test_execute_command_calls_full_command_with_shell(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command, shell=True) @@ -434,7 +426,7 @@ def test_execute_command_calls_full_command_with_environment(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command, environment={'a': 'b'}) @@ -455,7 +447,7 @@ def test_execute_command_calls_full_command_with_working_directory(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() output = module.execute_command(full_command, working_directory='/working') @@ -477,7 +469,7 @@ def test_execute_command_without_run_to_completion_returns_process(): close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield() assert module.execute_command(full_command, run_to_completion=False) == process @@ -497,11 +489,11 @@ def test_execute_command_and_capture_output_returns_stdout(): close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield('out') - output = module.execute_command_and_capture_output(full_command) + output_lines = tuple(module.execute_command_and_capture_output(full_command)) - assert output == 'out' + assert output_lines == ('out',) def test_execute_command_and_capture_output_with_capture_stderr_returns_stderr(): @@ -518,11 +510,13 @@ def test_execute_command_and_capture_output_with_capture_stderr_returns_stderr() close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield('out') - output = module.execute_command_and_capture_output(full_command, capture_stderr=True) + output_lines = tuple( + module.execute_command_and_capture_output(full_command, capture_stderr=True) + ) - assert output == 'out' + assert output_lines == ('out',) def test_execute_command_and_capture_output_returns_output_when_process_error_is_not_considered_an_error(): @@ -543,9 +537,9 @@ def test_execute_command_and_capture_output_returns_output_when_process_error_is module.Exit_status.SUCCESS, ).once() - output = module.execute_command_and_capture_output(full_command) + output_lines = tuple(module.execute_command_and_capture_output(full_command)) - assert output == '[]' + assert output_lines == () def test_execute_command_and_capture_output_raises_when_command_errors(): @@ -566,10 +560,10 @@ def test_execute_command_and_capture_output_raises_when_command_errors(): ).once() with pytest.raises(subprocess.CalledProcessError): - module.execute_command_and_capture_output(full_command) + tuple(module.execute_command_and_capture_output(full_command)) -def test_execute_command_and_capture_output_returns_output_with_shell(): +def test_execute_command_and_capture_output_with_shell_returns_output(): full_command = ['foo', 'bar'] flexmock(module).should_receive('log_command') process = flexmock() @@ -584,14 +578,14 @@ def test_execute_command_and_capture_output_returns_output_with_shell(): close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield('out') - output = module.execute_command_and_capture_output(full_command, shell=True) + output_lines = tuple(module.execute_command_and_capture_output(full_command, shell=True)) - assert output == 'out' + assert output_lines == ('out',) -def test_execute_command_and_capture_output_returns_output_with_environment(): +def test_execute_command_and_capture_output_with_enviroment_returns_output(): full_command = ['foo', 'bar'] flexmock(module).should_receive('log_command') process = flexmock() @@ -606,15 +600,17 @@ def test_execute_command_and_capture_output_returns_output_with_environment(): close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield('out') - output = module.execute_command_and_capture_output( - full_command, - shell=False, - environment={'a': 'b'}, + output_lines = tuple( + module.execute_command_and_capture_output( + full_command, + shell=False, + environment={'a': 'b'}, + ) ) - assert output == 'out' + assert output_lines == ('out',) def test_execute_command_and_capture_output_returns_output_with_working_directory(): @@ -632,15 +628,17 @@ def test_execute_command_and_capture_output_returns_output_with_working_director close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield('out') - output = module.execute_command_and_capture_output( - full_command, - shell=False, - working_directory='/working', + output_lines = tuple( + module.execute_command_and_capture_output( + full_command, + shell=False, + working_directory='/working', + ) ) - assert output == 'out' + assert output_lines == ('out',) def test_execute_command_with_processes_calls_full_command(): @@ -658,11 +656,11 @@ def test_execute_command_with_processes_calls_full_command(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes(full_command, processes) + output_lines = tuple(module.execute_command_with_processes(full_command, processes)) - assert output is None + assert output_lines == () def test_execute_command_with_processes_returns_output_with_output_log_level_none(): @@ -681,11 +679,13 @@ def test_execute_command_with_processes_returns_output_with_output_log_level_non close_fds=False, ).and_return(process).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs').and_return({process: 'out'}) + flexmock(module).should_receive('log_outputs').and_yield('out') - output = module.execute_command_with_processes(full_command, processes, output_log_level=None) + output_lines = tuple( + module.execute_command_with_processes(full_command, processes, output_log_level=None) + ) - assert output == 'out' + assert output_lines == ('out',) def test_execute_command_with_processes_calls_full_command_with_output_file(): @@ -704,11 +704,13 @@ def test_execute_command_with_processes_calls_full_command_with_output_file(): close_fds=False, ).and_return(flexmock(stderr=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes(full_command, processes, output_file=output_file) + output_lines = tuple( + module.execute_command_with_processes(full_command, processes, output_file=output_file) + ) - assert output is None + assert output_lines == () def test_execute_command_with_processes_calls_full_command_without_capturing_output(): @@ -727,15 +729,17 @@ def test_execute_command_with_processes_calls_full_command_without_capturing_out ).and_return(flexmock(wait=lambda: 0)).once() flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS) flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes( - full_command, - processes, - output_file=module.DO_NOT_CAPTURE, + output_lines = tuple( + module.execute_command_with_processes( + full_command, + processes, + output_file=module.DO_NOT_CAPTURE, + ) ) - assert output is None + assert output_lines == () def test_execute_command_with_processes_calls_full_command_with_input_file(): @@ -754,11 +758,13 @@ def test_execute_command_with_processes_calls_full_command_with_input_file(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes(full_command, processes, input_file=input_file) + output_lines = tuple( + module.execute_command_with_processes(full_command, processes, input_file=input_file) + ) - assert output is None + assert output_lines == () def test_execute_command_with_processes_calls_full_command_with_shell(): @@ -776,11 +782,11 @@ def test_execute_command_with_processes_calls_full_command_with_shell(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes(full_command, processes, shell=True) + output_lines = tuple(module.execute_command_with_processes(full_command, processes, shell=True)) - assert output is None + assert output_lines == () def test_execute_command_with_processes_calls_full_command_with_environment(): @@ -798,11 +804,13 @@ def test_execute_command_with_processes_calls_full_command_with_environment(): close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes(full_command, processes, environment={'a': 'b'}) + output_lines = tuple( + module.execute_command_with_processes(full_command, processes, environment={'a': 'b'}) + ) - assert output is None + assert output_lines == () def test_execute_command_with_processes_calls_full_command_with_working_directory(): @@ -820,15 +828,17 @@ def test_execute_command_with_processes_calls_full_command_with_working_director close_fds=False, ).and_return(flexmock(stdout=None)).once() flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) - flexmock(module).should_receive('log_outputs') + flexmock(module).should_receive('log_outputs').and_yield() - output = module.execute_command_with_processes( - full_command, - processes, - working_directory='/working', + output_lines = tuple( + module.execute_command_with_processes( + full_command, + processes, + working_directory='/working', + ) ) - assert output is None + assert output_lines == () def test_execute_command_with_processes_kills_processes_on_error(): @@ -852,4 +862,4 @@ def test_execute_command_with_processes_kills_processes_on_error(): flexmock(module).should_receive('log_outputs').never() with pytest.raises(subprocess.CalledProcessError): - module.execute_command_with_processes(full_command, processes) + tuple(module.execute_command_with_processes(full_command, processes))