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

[tor-commits] [ooni-probe/master] Start outlining unittests for director



commit a90f2d1e06f707c8cc86efb8d17dbff59b86e90b
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sun Jan 13 20:23:34 2013 +0100

    Start outlining unittests for director
---
 ooni/director.py       |    8 ++---
 tests/test_director.py |   66 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/ooni/director.py b/ooni/director.py
index 1ef5aab..582bb84 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -143,10 +143,8 @@ class Director(object):
         report.reportEntryManager = self.reportEntryManager
 
         net_test = NetTest(net_test_file, options, report)
-        net_test.measurmentManager = self.measurementManager
+        net_test.measurementManager = self.measurementManager
 
-        try:
-            net_test.start()
-        except Exception, e:
-            pass
+        d = net_test.start()
+        return d
 
diff --git a/tests/test_director.py b/tests/test_director.py
new file mode 100644
index 0000000..fa13d9e
--- /dev/null
+++ b/tests/test_director.py
@@ -0,0 +1,66 @@
+from twisted.internet import defer, base
+from twisted.trial import unittest
+
+from ooni.director import Director
+base.DelayedCall.debug = True
+class MockMeasurement(object):
+    def run(self):
+        return defer.succeed(42)
+
+net_test_string = """
+from twisted.python import usage
+from ooni.nettest import NetTestCase
+
+class UsageOptions(usage.Options):
+    optParameters = [['spam', 's', None, 'ham']]
+
+class DummyTestCase(NetTestCase):
+    inputFile = ['file', 'f', None, 'The input File']
+
+    usageOptions = UsageOptions
+
+    def test_a(self):
+        self.report['bar'] = 'bar'
+
+    def test_b(self):
+        self.report['foo'] = 'foo'
+"""
+
+
+dummyOptions = {'spam': 1, 'file': 'dummyInputFile.txt'}
+
+class MockReporter(object):
+    def __init__(self):
+        self.created = defer.succeed(None)
+
+    def createReport(self):
+        pass
+
+    def write(self):
+        pass
+
+class TestDirector(unittest.TestCase):
+    def setUp(self):
+        with open('dummyInputFile.txt', 'w') as f:
+            for i in range(10):
+                f.write("%s\n" % i)
+
+        reporters = [MockReporter]
+        self.director = Director(reporters)
+
+    def tearDown(self):
+        pass
+
+    def test_start_net_test(self):
+        d = self.director.startTest(net_test_string, dummyOptions)
+
+        @d.addCallback
+        def done(result):
+            print "SOMETHING"
+            self.assertEqual(self.director.successfulMeasurements, 20)
+
+        return d
+
+    def test_stop_net_test(self):
+        pass
+



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