From a40729f4f3c37119b3af5dd4b49e0c1973fc40cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 20 Nov 2015 14:56:18 -0500 Subject: [PATCH 1/4] --progress option was backwards adds unit tests and ensures we detect --progress correctly in all cases --- borg/archiver.py | 2 +- borg/testsuite/archiver.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/borg/archiver.py b/borg/archiver.py index 12de588ea..479d5a854 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -775,7 +775,7 @@ class Archiver: """ def __call__(self, parser, ns, values, option): """set the given flag to true unless ``--no`` is passed""" - setattr(ns, self.dest, option.startswith('--no-')) + setattr(ns, self.dest, not option.startswith('--no-')) subparser = subparsers.add_parser('create', parents=[common_parser], description=self.do_create.__doc__, diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index d61834d99..48b9da0cb 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -669,6 +669,28 @@ class ArchiverTestCase(ArchiverTestCaseBase): manifest, key = Manifest.load(repository) self.assert_equal(len(manifest.archives), 0) + def test_progress(self): + self.create_regular_file('file1', size=1024 * 80) + self.cmd('init', self.repository_location) + # without a terminal, no progress expected + output = self.cmd('create', self.repository_location + '::test1', 'input', fork=False) + self.assert_not_in("\r", output) + # with a terminal, progress expected + output = self.cmd('create', self.repository_location + '::test2', 'input', fork=True) + self.assert_in("\r", output) + # without a terminal, progress forced on + output = self.cmd('create', '--progress', self.repository_location + '::test3', 'input', fork=False) + self.assert_in("\r", output) + # with a terminal, progress forced on + output = self.cmd('create', '--progress', self.repository_location + '::test4', 'input', fork=True) + self.assert_in("\r", output) + # without a termainl, progress forced off + output = self.cmd('create', '--no-progress', self.repository_location + '::test5', 'input', fork=False) + self.assert_not_in("\r", output) + # with a termainl, progress forced off + output = self.cmd('create', '--no-progress', self.repository_location + '::test6', 'input', fork=True) + self.assert_not_in("\r", output) + def test_cmdline_compatibility(self): self.create_regular_file('file1', size=1024 * 80) self.cmd('init', self.repository_location) From a6f8436ceb723e5d86b0abe47d86f0d1a1e687d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 20 Nov 2015 15:01:29 -0500 Subject: [PATCH 2/4] move toggle action to beginning of class so it can be reused --- borg/archiver.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 479d5a854..3e334ec57 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -35,6 +35,20 @@ from .remote import RepositoryServer, RemoteRepository has_lchflags = hasattr(os, 'lchflags') +class ToggleAction(argparse.Action): + """argparse action to handle "toggle" flags easily + + toggle flags are in the form of ``--foo``, ``--no-foo``. + + the ``--no-foo`` argument still needs to be passed to the + ``add_argument()`` call, but it simplifies the ``--no`` + detection. + """ + def __call__(self, parser, ns, values, option): + """set the given flag to true unless ``--no`` is passed""" + setattr(ns, self.dest, not option.startswith('--no-')) + + class Archiver: def __init__(self, verbose=False): @@ -764,19 +778,6 @@ class Archiver: See the output of the "borg help patterns" command for more help on exclude patterns. """) - class ToggleAction(argparse.Action): - """argparse action to handle "toggle" flags easily - - toggle flags are in the form of ``--foo``, ``--no-foo``. - - the ``--no-foo`` argument still needs to be passed to the - ``add_argument()`` call, but it simplifies the ``--no`` - detection. - """ - def __call__(self, parser, ns, values, option): - """set the given flag to true unless ``--no`` is passed""" - setattr(ns, self.dest, not option.startswith('--no-')) - subparser = subparsers.add_parser('create', parents=[common_parser], description=self.do_create.__doc__, epilog=create_epilog, From 0196d80b28e194c5d331a0cbc160dd27746523df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Sun, 22 Nov 2015 21:24:37 -0500 Subject: [PATCH 3/4] fix progress tests on travis we now check if we really have a terminal before doing the fancy auto-detection testing --- borg/testsuite/archiver.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index 48b9da0cb..928b12be3 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -670,6 +670,19 @@ class ArchiverTestCase(ArchiverTestCaseBase): self.assert_equal(len(manifest.archives), 0) def test_progress(self): + self.create_regular_file('file1', size=1024 * 80) + self.cmd('init', self.repository_location) + # progress forced on + output = self.cmd('create', '--progress', self.repository_location + '::test4', 'input') + self.assert_in("\r", output) + # progress forced off + output = self.cmd('create', '--no-progress', self.repository_location + '::test5', 'input') + self.assert_not_in("\r", output) + + @unittest.skipUnless(sys.stdout.isatty(), 'need a tty to test auto-detection') + def test_progress_tty(self): + """test that the --progress and --no-progress flags work, + overriding defaults from the terminal auto-detection""" self.create_regular_file('file1', size=1024 * 80) self.cmd('init', self.repository_location) # without a terminal, no progress expected From 2ac515a5f7696a7e4dc6f2691766c4b7e1b1ea1c Mon Sep 17 00:00:00 2001 From: anarcat Date: Mon, 23 Nov 2015 12:41:20 -0500 Subject: [PATCH 4/4] fix typos --- borg/testsuite/archiver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index 928b12be3..2d31a8309 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -697,10 +697,10 @@ class ArchiverTestCase(ArchiverTestCaseBase): # with a terminal, progress forced on output = self.cmd('create', '--progress', self.repository_location + '::test4', 'input', fork=True) self.assert_in("\r", output) - # without a termainl, progress forced off + # without a terminal, progress forced off output = self.cmd('create', '--no-progress', self.repository_location + '::test5', 'input', fork=False) self.assert_not_in("\r", output) - # with a termainl, progress forced off + # with a terminal, progress forced off output = self.cmd('create', '--no-progress', self.repository_location + '::test6', 'input', fork=True) self.assert_not_in("\r", output)