[tor-commits] [ooni-probe/master] Write some more docstrings and fix some code.

isis at torproject.org isis at torproject.org
Thu Oct 4 14:41:15 UTC 2012


commit 26f7afc073cb86276a04d1faeec65dde59dd858f
Author: Arturo Filastò <arturo at filasto.net>
Date:   Fri Sep 21 12:05:17 2012 +0000

    Write some more docstrings and fix some code.
---
 ooni/protocols/http.py |    4 ++--
 ooni/reporter.py       |    6 ++++--
 ooni/runner.py         |   23 +++++++++++++++++++++--
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/ooni/protocols/http.py b/ooni/protocols/http.py
index 09bb9b9..569c382 100644
--- a/ooni/protocols/http.py
+++ b/ooni/protocols/http.py
@@ -56,7 +56,7 @@ class HTTPTest(OONITest):
 
     def _processResponseBody(self, data):
         self.response['body'] = data
-        #self.result['response'] = self.response
+        self.result['response'] = self.response
         self.processResponseBody(data)
 
     def processResponseBody(self, data):
@@ -127,7 +127,7 @@ class HTTPTest(OONITest):
         if self.randomize_ua:
             self.randomize_useragent()
 
-        #self.result['request'] = self.request
+        self.result['request'] = self.request
         self.result['url'] = url
         return self.agent.request(self.request['method'], self.request['url'],
                                   Headers(self.request['headers']),
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 4b3ed6f..b145e87 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -138,12 +138,14 @@ class OONIReporter(OReporter):
         # This is here for allowing reporting of legacy tests.
         # XXX In the future this should be removed.
         try:
-            self._tests[idx]['report'] = list(test.legacy_report)
+            report = list(test.legacy_report)
         except:
             # XXX I put a dict() here so that the object is re-instantiated and I
             #     actually end up with the report I want. This could either be a
             #     python bug or a yaml bug.
-            self._tests[idx]['report'] = dict(test.report)
+            report = dict(test.report)
+
+        self._tests[idx]['report'] = report
 
 
     def done(self):
diff --git a/ooni/runner.py b/ooni/runner.py
index 0bcafb0..ff6b47e 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -85,13 +85,18 @@ def adaptLegacyTest(obj, config):
             args = {}
             args[self.key] = self.input
             result = yield my_test.startTest(args)
-            print "Finished!"
-            print result
+            self.report['result'] = result
 
     return LegacyOONITest
 
 
 def findTestClassesFromConfig(config):
+    """
+    Takes as input the command line config parameters and returns the test
+    case classes.
+    If it detects that a certain test class is using the old OONIProbe format,
+    then it will adapt it to the new testing system.
+    """
     filename = config['test']
 
     classes = []
@@ -105,12 +110,20 @@ def findTestClassesFromConfig(config):
     return classes
 
 def makeTestCases(klass, tests, methodPrefix):
+    """
+    Takes a class some tests and returns the test cases. methodPrefix is how
+    the test case functions should be prefixed with.
+    """
     cases = []
     for test in tests:
         cases.append(klass(methodPrefix+test))
     return cases
 
 def loadTestsAndOptions(classes):
+    """
+    Takes a list of classes and returnes their testcases and options.
+    Legacy tests will be adapted.
+    """
     methodPrefix = 'test'
     suiteFactory = InputTestSuite
     options = []
@@ -132,6 +145,12 @@ def loadTestsAndOptions(classes):
     return testCases, options
 
 class ORunner(object):
+    """
+    This is a specialized runner used by the ooniprobe command line tool.
+    I am responsible for reading the inputs from the test files and splitting
+    them in input units. I also create all the report instances required to run
+    the tests.
+    """
     def __init__(self, cases, options=None, config=None):
         self.baseSuite = InputTestSuite
         self.cases = cases





More information about the tor-commits mailing list