[tor-commits] [ooni-probe/master] Document TestCase

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


commit 839564d3620c24e0057c1dfd9d39ef15f8b202ac
Author: Arturo Filastò <arturo at filasto.net>
Date:   Fri Sep 21 13:07:15 2012 +0000

    Document TestCase
---
 ooni/nettest.py |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/ooni/nettest.py b/ooni/nettest.py
index f3476cf..2a02a43 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -24,11 +24,63 @@ class InputTestSuite(pyunit.TestSuite):
             self._idx += 1
         return result
 
+def lineByLine(fp):
+    for x in fp.readlines():
+        yield x.strip()
+    fp.close()
+
 class TestCase(unittest.TestCase):
-    name = "DefaultOONITestCase"
+    """
+    This is the monad of the OONI nettest universe. When you write a nettest
+    you will subclass this object.
+
+    _inputs_ can be set to a static set of inputs. All the tests (the methods
+    starting with the "test_" prefix) will be run once per input.  At every run
+    the _input_ attribute of the TestCase instance will be set to the value of
+    the current iteration over inputs.  Any python iterable object can be set
+    to inputs.
+
+    _inputFile_ attribute should be set to an array containing the command line
+    argument that should be used as the input file. Such array looks like this:
+
+        ["commandlinearg", "c", "The description"]
+
+    The second value of such arrray is the shorthand for the command line arg.
+    The user will then be able to specify inputs to the test via:
+
+        ooniprobe mytest.py --commandlinearg path/to/file.txt
+
+    or
+
+        ooniprobe mytest.py -c path/to/file.txt
+
+
+    _inputProcessor_ should be set to a function that takes as argument an
+    open file descriptor and it will yield the input to be passed to the test
+    instance.
+
+    _name_ should be set to the name of the test.
+
+    _author_ should contain the name and contact details for the test author.
+    The format for such string is as follows:
+
+        The Name <email at example.com>
+
+    _version_ is the version string of the test.
+    """
+    name = "IDidNotChangeTheName"
+    author = "John Doe <foo at example.com>"
+    version = "0"
+
     inputs = [None]
+    inputFile = None
+    inputProcessor = lineByLine
 
     def getOptions(self):
+        if self.inputFile:
+            fp = open(self.inputFile)
+            self.inputs = inputProcessor(fp)
+
         return {'inputs': self.inputs}
 
     def __repr__(self):





More information about the tor-commits mailing list