From 56fd78089db229a10cb94b1b40f7eb563ab74ccd Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 25 Jun 2019 11:04:10 -0700 Subject: [PATCH] Sort generated flags before passing them to Borg. --- borgmatic/borg/flags.py | 2 +- tests/unit/borg/test_flags.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/borgmatic/borg/flags.py b/borgmatic/borg/flags.py index 4806f29..0665607 100644 --- a/borgmatic/borg/flags.py +++ b/borgmatic/borg/flags.py @@ -25,7 +25,7 @@ def make_flags_from_arguments(arguments, excludes=()): return tuple( itertools.chain.from_iterable( make_flags(name, value=getattr(arguments, name)) - for name in vars(arguments) + for name in sorted(vars(arguments)) if name not in excludes and not name.startswith('_') ) ) diff --git a/tests/unit/borg/test_flags.py b/tests/unit/borg/test_flags.py index ca2ff63..3d1153e 100644 --- a/tests/unit/borg/test_flags.py +++ b/tests/unit/borg/test_flags.py @@ -23,16 +23,14 @@ def test_make_flags_formats_name_with_underscore(): assert module.make_flags('posix_me_harder', 'okay') == ('--posix-me-harder', 'okay') -def test_make_flags_from_arguments_flattens_multiple_arguments(): +def test_make_flags_from_arguments_flattens_and_sorts_multiple_arguments(): flexmock(module).should_receive('make_flags').with_args('foo', 'bar').and_return(('foo', 'bar')) flexmock(module).should_receive('make_flags').with_args('baz', 'quux').and_return( ('baz', 'quux') ) arguments = flexmock(foo='bar', baz='quux') - assert sorted(module.make_flags_from_arguments(arguments)) == sorted( - ('foo', 'bar', 'baz', 'quux') - ) + assert module.make_flags_from_arguments(arguments) == ('baz', 'quux', 'foo', 'bar') def test_make_flags_from_arguments_excludes_underscored_argument_names():