commit 7284fac63bd5100700319ba655f5a2c335193a1b Author: srvetus srvetus@users.noreply.github.com Date: Thu Nov 19 14:16:42 2015 +0100
Test that specific Failures are caught before parent Failures --- ooni/tests/test_errors.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/ooni/tests/test_errors.py b/ooni/tests/test_errors.py new file mode 100644 index 0000000..7baa1ea --- /dev/null +++ b/ooni/tests/test_errors.py @@ -0,0 +1,20 @@ +from twisted.trial import unittest + +import ooni.errors + +class TestErrors(unittest.TestCase): + + def test_catch_child_failures_before_parent_failures(self): + """ + Verify that more specific Failures are caught first by + handleAllFailures() and failureToString(). + + Fails if a subclass is listed after it's parent Failure. + """ + + # Check each Failure against all subsequent failures + for index, (failure, _) in enumerate(ooni.errors.known_failures): + for sub_failure, _ in ooni.errors.known_failures[index+1:]: + + # Fail if subsequent Failure inherits from the current Failure + self.assertNotIsInstance(sub_failure(None), failure)