From 2f7527a3334f18ad0752cb2a766740e5e7758a22 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 9 Jul 2017 17:03:45 -0700 Subject: [PATCH] Completed test coverage of commands (except for main()s). --- borgmatic/commands/borgmatic.py | 2 +- borgmatic/commands/convert_config.py | 3 ++- borgmatic/commands/generate_config.py | 2 +- .../integration/commands/test_convert_config.py | 14 ++++++++++++++ .../integration/commands/test_generate_config.py | 12 ++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 borgmatic/tests/integration/commands/test_convert_config.py create mode 100644 borgmatic/tests/integration/commands/test_generate_config.py diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 4c2e9bab9..1fcc582d0 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -39,7 +39,7 @@ def parse_arguments(*arguments): return parser.parse_args(arguments) -def main(): +def main(): # pragma: no cover try: # TODO: Detect whether only legacy config is present. If so, inform the user about how to # upgrade, then exet. diff --git a/borgmatic/commands/convert_config.py b/borgmatic/commands/convert_config.py index 8f645c0aa..77735bf7f 100644 --- a/borgmatic/commands/convert_config.py +++ b/borgmatic/commands/convert_config.py @@ -11,6 +11,7 @@ from borgmatic.config import convert, generate, legacy, validate DEFAULT_SOURCE_CONFIG_FILENAME = '/etc/borgmatic/config' +# TODO: Fold excludes into the YAML config file. DEFAULT_SOURCE_EXCLUDES_FILENAME = '/etc/borgmatic/excludes' DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml' @@ -37,7 +38,7 @@ def parse_arguments(*arguments): return parser.parse_args(arguments) -def main(): +def main(): # pragma: no cover try: args = parse_arguments(*sys.argv[1:]) source_config = legacy.parse_configuration(args.source_filename, legacy.CONFIG_FORMAT) diff --git a/borgmatic/commands/generate_config.py b/borgmatic/commands/generate_config.py index f326d6ae9..0f0474086 100644 --- a/borgmatic/commands/generate_config.py +++ b/borgmatic/commands/generate_config.py @@ -29,7 +29,7 @@ def parse_arguments(*arguments): return parser.parse_args(arguments) -def main(): +def main(): # pragma: no cover try: args = parse_arguments(*sys.argv[1:]) diff --git a/borgmatic/tests/integration/commands/test_convert_config.py b/borgmatic/tests/integration/commands/test_convert_config.py new file mode 100644 index 000000000..b2bc32bd8 --- /dev/null +++ b/borgmatic/tests/integration/commands/test_convert_config.py @@ -0,0 +1,14 @@ +from borgmatic.commands import convert_config as module + + +def test_parse_arguments_with_no_arguments_uses_defaults(): + parser = module.parse_arguments() + + assert parser.source_filename == module.DEFAULT_SOURCE_CONFIG_FILENAME + assert parser.destination_filename == module.DEFAULT_DESTINATION_CONFIG_FILENAME + +def test_parse_arguments_with_filename_arguments_overrides_defaults(): + parser = module.parse_arguments('--source', 'config', '--destination', 'config.yaml') + + assert parser.source_filename == 'config' + assert parser.destination_filename == 'config.yaml' diff --git a/borgmatic/tests/integration/commands/test_generate_config.py b/borgmatic/tests/integration/commands/test_generate_config.py new file mode 100644 index 000000000..b9b4db082 --- /dev/null +++ b/borgmatic/tests/integration/commands/test_generate_config.py @@ -0,0 +1,12 @@ +from borgmatic.commands import generate_config as module + + +def test_parse_arguments_with_no_arguments_uses_defaults(): + parser = module.parse_arguments() + + assert parser.destination_filename == module.DEFAULT_DESTINATION_CONFIG_FILENAME + +def test_parse_arguments_with_filename_argument_overrides_defaults(): + parser = module.parse_arguments('--destination', 'config.yaml') + + assert parser.destination_filename == 'config.yaml'