From 2bcfbf6a81d1edb4cb913ecfbc623aad9aa0b66f Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Thu, 26 Oct 2017 21:38:08 +0200 Subject: recursiveloader: warn_handler defaults to fail_handler --- gemato/recursiveloader.py | 12 ++++++++---- tests/test_recursiveloader.py | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 7276686..0fa42ad 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -217,7 +217,7 @@ class ManifestRecursiveLoader(object): def assert_directory_verifies(self, path='', fail_handler=gemato.util.throw_exception, - warn_handler=gemato.util.throw_exception): + warn_handler=None): """ Verify the complete directory tree starting at @path (relative to top Manifest directory). Includes testing for stray files. @@ -229,9 +229,10 @@ class ManifestRecursiveLoader(object): is called whenever verification fails for MISC/OPTIONAL entries. The handlers are passed a ManifestMismatch exception object. - The default handlers raise the exception. However, custom - handlers can be used to provide a non-strict mode, or continue - the scan after the first failure. + The default fail handler raises the exception. Unless specified + explicitly, the warn handler defaults to fail handler. However, + custom handlers can be used to provide a non-strict mode, + or continue the scan after the first failure. If none of the handlers raise exceptions, the function returns boolean. It returns False if at least one of the handler calls @@ -244,6 +245,9 @@ class ManifestRecursiveLoader(object): followlinks=True) ret = True + if warn_handler is None: + warn_handler = fail_handler + for dirpath, dirnames, filenames in it: relpath = os.path.relpath(dirpath, self.root_directory) # strip dot to avoid matching problems diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index 8049f47..25aa382 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -698,6 +698,12 @@ MISC foo 0 MD5 d41d8cd98f00b204e9800998ecf8427e self.assertFalse(m.assert_directory_verifies('', warn_handler=lambda x: False)) + def test_assert_directory_verifies_nonstrict_via_fail_handler(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + self.assertTrue(m.assert_directory_verifies('', + fail_handler=lambda x: True)) + class ManifestOptionalEntryTest(TempDirTestCase): """ -- cgit v1.2.3