[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Clean up inputProcessor hook



commit e35b39d35e9f2a6144090d936a093c550d7b67d6
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Thu Nov 15 11:37:25 2012 +0100

    Clean up inputProcessor hook
    * Fixes a bug noticed by isis
---
 ooni/nettest.py |   25 +++++++++----------------
 ooni/runner.py  |    2 +-
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/ooni/nettest.py b/ooni/nettest.py
index fbc5c42..a2f98c4 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -115,7 +115,7 @@ class NetTestCase(object):
         """
         pass
 
-    def inputProcessor(self, filename):
+    def inputProcessor(self, filename=None):
         """
         You may replace this with your own custom input processor. It takes as
         input a file descriptor so remember to close it when you are done.
@@ -137,10 +137,13 @@ class NetTestCase(object):
         Other fun stuff is also possible.
         """
         log.debug("Running default input processor")
-        fp = open(filename)
-        for x in fp.xreadlines():
-            yield x.strip()
-        fp.close()
+        if filename:
+            fp = open(filename)
+            for x in fp.xreadlines():
+                yield x.strip()
+            fp.close()
+        else:
+            pass
 
     def _checkRequiredOptions(self):
         for required_option in self.requiredOptions:
@@ -150,17 +153,7 @@ class NetTestCase(object):
 
     def _processOptions(self, options=None):
         if self.inputFile:
-            try:
-                assert isinstance(self.inputFile, str)
-            except AssertionError, ae:
-                log.err(ae)
-            else:
-                if os.path.isfile(self.inputFile):
-                    self.inputs = self.inputProcessor(self.inputFile)
-        elif not self.inputs[0]:
-            pass
-        elif self.inputFile:
-            raise usage.UsageError("No input file specified!")
+            self.inputs = self.inputProcessor(self.inputFile)
 
         self._checkRequiredOptions()
 
diff --git a/ooni/runner.py b/ooni/runner.py
index 2b9089a..f7fa5dc 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -159,7 +159,7 @@ def runTestWithInput(test_class, test_method, test_input, oreporter):
         return oreporter.testDone(test_instance, test_name)
 
     def test_error(error, test_instance, test_name):
-        log.err("%s\n" % error)
+        log.exception(error)
 
     test_instance = test_class()
     test_instance.input = test_input



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits