[tor-commits] [ooni-probe/master] Add support for having multiple test classes in a single nettest file
art at torproject.org
art at torproject.org
Sun Aug 24 17:51:33 UTC 2014
commit 7e14b11eb3cbfabfb9bb1b51e91cfd52a257f6c0
Author: kudrom <kudrom at riseup.net>
Date: Mon Aug 18 20:19:17 2014 +0200
Add support for having multiple test classes in a single nettest file
---
ooni/tests/test_nettest.py | 39 +++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/ooni/tests/test_nettest.py b/ooni/tests/test_nettest.py
index 5015c64..ccbe2dd 100644
--- a/ooni/tests/test_nettest.py
+++ b/ooni/tests/test_nettest.py
@@ -31,6 +31,29 @@ class DummyTestCase(NetTestCase):
self.report['foo'] = 'foo'
"""
+double_net_test_string = """
+from twisted.python import usage
+from ooni.nettest import NetTestCase
+
+class UsageOptions(usage.Options):
+ optParameters = [['spam', 's', None, 'ham']]
+
+class DummyTestCaseA(NetTestCase):
+
+ usageOptions = UsageOptions
+
+ def test_a(self):
+ self.report['bar'] = 'bar'
+
+
+class DummyTestCaseB(NetTestCase):
+
+ usageOptions = UsageOptions
+
+ def test_b(self):
+ self.report['foo'] = 'foo'
+"""
+
net_test_root_required = net_test_string + """
requiresRoot = True
"""
@@ -137,6 +160,13 @@ class TestNetTest(unittest.TestCase):
uniq_test_methods.add(test_method)
self.assertEqual(set(['test_a', 'test_b']), uniq_test_methods)
+ def verifyClasses(self, test_cases, control_classes):
+ actual_classes = set()
+ for test_class, test_methods in test_cases:
+ actual_classes.add(test_class.__name__)
+
+ self.assertEqual(actual_classes, control_classes)
+
def test_load_net_test_from_file(self):
"""
Given a file verify that the net test cases are properly
@@ -163,15 +193,12 @@ class TestNetTest(unittest.TestCase):
self.verifyMethods(ntl.testCases)
- def test_load_net_test_from_StringIO(self):
- """
- Given a file like object verify that the net test cases are properly
- generated.
- """
+ def test_load_net_test_multiple(self):
ntl = NetTestLoader(dummyArgs)
- ntl.loadNetTestString(net_test_string)
+ ntl.loadNetTestString(double_net_test_string)
self.verifyMethods(ntl.testCases)
+ self.verifyClasses(ntl.testCases, set(('DummyTestCaseA', 'DummyTestCaseB')))
def test_load_with_option(self):
ntl = NetTestLoader(dummyArgs)
More information about the tor-commits
mailing list