[tor-commits] [ooni-probe/master] Write test case for OONITest

art at torproject.org art at torproject.org
Thu May 31 15:44:23 UTC 2012


commit eb6a0f732a60f2d340de758deebf67781ae1358e
Author: Arturo Filastò <hellais at torproject.org>
Date:   Thu May 31 17:43:20 2012 +0200

    Write test case for OONITest
    * Make the test result conform to the spec
---
 docs/writing_tests.txt |   12 ------------
 ooni/plugoo/tests.py   |    2 +-
 tests/test_tests.py    |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/docs/writing_tests.txt b/docs/writing_tests.txt
deleted file mode 100644
index 1692f82..0000000
--- a/docs/writing_tests.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-There are two modes of writing tests.
-
-The first kind of mechanism relied of writing a test that uses blocking code
-and each instance of it is run inside of a separate thread. Beware that your
-blocking code must be thread safe to run properly (as is obvious :P)
-
-The other menthod invloves having some knowledge about twisted. The test you
-will write will be written in twisted and should implement async style non
-blocking architecture.
-
-It is recommended that tests are written using the second pattern and the first
-should only be used for runnign tests that have been previously written.
diff --git a/ooni/plugoo/tests.py b/ooni/plugoo/tests.py
index 7bb2321..8e0ab8e 100644
--- a/ooni/plugoo/tests.py
+++ b/ooni/plugoo/tests.py
@@ -44,7 +44,7 @@ class OONITest(object):
         result['start_time'] = self.start_time
         result['end_time'] = self.end_time
         result['run_time'] = self.end_time - self.start_time
-        result['control'] = control
+        result['result'] = control
         log.msg("FINISHED %s" % result)
         self.report(result)
         return result
diff --git a/tests/test_tests.py b/tests/test_tests.py
new file mode 100644
index 0000000..702e6a3
--- /dev/null
+++ b/tests/test_tests.py
@@ -0,0 +1,33 @@
+from twisted.trial import unittest
+
+from ooni.plugoo import work, tests
+
+class TestsTestCase(unittest.TestCase):
+    def setUp(self):
+        class dummyReport:
+            def __call__(self, *args, **kw):
+                pass
+        self.dummyreport = dummyReport()
+        self.callbackResults = None
+        self.errbackResults = None
+
+    def _callback(self, *args, **kw):
+        self.callbackResults = args, kw
+
+    def _errback(self, *args, **kw):
+        pass
+
+    def test_fallThrough(self):
+        """
+        This tests to make sure that what is returned from the experiment
+        method falls all the way through to control and finish.
+        """
+        test_dict = {"hello": "world"}
+        class DummyTest(tests.OONITest):
+            def experiment(self, args):
+                return test_dict
+
+        test = DummyTest(None, None, self.dummyreport)
+        test.startTest(None).addCallback(self._callback)
+        self.assertEqual(self.callbackResults[0][0]['result'], test_dict)
+



More information about the tor-commits mailing list