[tor-commits] [ooni-probe/master] Improved error handling

art at torproject.org art at torproject.org
Sun Aug 24 17:51:33 UTC 2014


commit f7556f55018278e2228d4e31ed7357edb4769c7d
Author: kudrom <kudrom at riseup.net>
Date:   Wed Aug 20 17:25:44 2014 +0200

    Improved error handling
---
 ooni/errors.py             |   12 ++++++++++++
 ooni/nettest.py            |    4 +++-
 ooni/tests/test_nettest.py |    4 ++--
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ooni/errors.py b/ooni/errors.py
index bcf8c95..081c4ac 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -264,11 +264,13 @@ class MissingRequiredOption(Exception):
     def __str__(self):
         return ','.join(self.message)
 
+
 class OONIUsageError(usage.UsageError):
     def __init__(self, net_test_loader):
         super(OONIUsageError, self).__init__()
         self.net_test_loader = net_test_loader
 
+
 class FailureToLoadNetTest(Exception):
     pass
 
@@ -281,6 +283,15 @@ class InvalidOption(Exception):
     pass
 
 
+class IncoherentOptions(Exception):
+    def __init__(self, first_options, second_options):
+        super(IncoherentOptions, self).__init__()
+        self.message = "%s is different to %s" % (first_options, second_options)
+
+    def __str__(self):
+        return self.message
+
+
 class TaskTimedOut(Exception):
     pass
 
@@ -304,6 +315,7 @@ class ReportLogExists(Exception):
 class InvalidConfigFile(Exception):
     pass
 
+
 class ConfigFileIncoherent(Exception):
     pass
 
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 3852b40..3db82d7 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -250,7 +250,9 @@ class NetTestLoader(object):
             if not usage_options:
                 usage_options = self._parseNetTestOptions(test_class)
             else:
-                assert usage_options == test_class.usageOptions
+                if usage_options != test_class.usageOptions:
+                    raise e.IncoherentOptions(usage_options.__name__,
+                                              test_class.usageOptions.__name__)
         return usage_options
 
     def loadNetTestString(self, net_test_string):
diff --git a/ooni/tests/test_nettest.py b/ooni/tests/test_nettest.py
index f1cc542..4f7b3e4 100644
--- a/ooni/tests/test_nettest.py
+++ b/ooni/tests/test_nettest.py
@@ -6,7 +6,7 @@ from twisted.internet import defer, reactor
 from twisted.python.usage import UsageError
 
 from ooni.settings import config
-from ooni.errors import MissingRequiredOption, OONIUsageError
+from ooni.errors import MissingRequiredOption, OONIUsageError, IncoherentOptions
 from ooni.nettest import NetTest, NetTestLoader
 
 from ooni.director import Director
@@ -235,7 +235,7 @@ class TestNetTest(unittest.TestCase):
         self.verifyMethods(ntl.testCases)
         self.verifyClasses(ntl.testCases, set(('DummyTestCaseA', 'DummyTestCaseB')))
 
-        self.assertRaises(AssertionError, ntl.checkOptions)
+        self.assertRaises(IncoherentOptions, ntl.checkOptions)
 
     def test_load_with_option(self):
         ntl = NetTestLoader(dummyArgs)





More information about the tor-commits mailing list