From 8b91c01a4c527a8ec3410c39950405999181528b Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 11 May 2020 11:34:14 -0700 Subject: [PATCH] Add some missing test coverage. --- tests/unit/borg/test_create.py | 30 ++++++++++++++++++++++++++++++ tests/unit/borg/test_extract.py | 17 +++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index bf09e508..4ab69d01 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -1005,6 +1005,36 @@ def test_create_archive_with_progress_calls_borg_with_progress_parameter(): ) +def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter(): + processes = flexmock() + flexmock(module).should_receive('borgmatic_source_directories').and_return([]) + flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')) + flexmock(module).should_receive('_expand_home_directories').and_return(()) + flexmock(module).should_receive('_write_pattern_file').and_return(None) + flexmock(module).should_receive('_make_pattern_flags').and_return(()) + flexmock(module).should_receive('_make_exclude_flags').and_return(()) + flexmock(module).should_receive('execute_command_with_processes').with_args( + ('borg', 'create', '--read-special', '--progress') + ARCHIVE_WITH_PATHS, + processes=processes, + output_log_level=logging.INFO, + output_file=module.DO_NOT_CAPTURE, + error_on_warnings=False, + ) + + module.create_archive( + dry_run=False, + repository='repo', + location_config={ + 'source_directories': ['foo', 'bar'], + 'repositories': ['repo'], + 'exclude_patterns': None, + }, + storage_config={}, + progress=True, + stream_processes=processes, + ) + + def test_create_archive_with_json_calls_borg_with_json_parameter(): flexmock(module).should_receive('borgmatic_source_directories').and_return([]) flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')) diff --git a/tests/unit/borg/test_extract.py b/tests/unit/borg/test_extract.py index 95ed2acc..faca6440 100644 --- a/tests/unit/borg/test_extract.py +++ b/tests/unit/borg/test_extract.py @@ -1,5 +1,6 @@ import logging +import pytest from flexmock import flexmock from borgmatic.borg import extract as module @@ -239,6 +240,22 @@ def test_extract_archive_calls_borg_with_progress_parameter(): ) +def test_extract_archive_with_progress_and_extract_to_stdout_raises(): + flexmock(module).should_receive('execute_command').never() + + with pytest.raises(ValueError): + module.extract_archive( + dry_run=False, + repository='repo', + archive='archive', + paths=None, + location_config={}, + storage_config={}, + progress=True, + extract_to_stdout=True, + ) + + def test_extract_archive_calls_borg_with_stdout_parameter_and_returns_process(): flexmock(module.os.path).should_receive('abspath').and_return('repo') process = flexmock()