[tor-commits] [ooni-probe/master] Check to see if the test methods are callables

isis at torproject.org isis at torproject.org
Sun Mar 10 01:57:01 UTC 2013


commit 606df6ea2010a2d0a172149bbbfd263e58d67cb7
Author: Arturo Filastò <art at fuffa.org>
Date:   Sat Jan 12 19:06:30 2013 +0100

    Check to see if the test methods are callables
---
 tests/test_nettest.py |   40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/tests/test_nettest.py b/tests/test_nettest.py
index af1f8d0..8546031 100644
--- a/tests/test_nettest.py
+++ b/tests/test_nettest.py
@@ -67,9 +67,12 @@ class DummyReporter(object):
         pass
 
 class TestNetTest(unittest.TestCase):
+    def assertCallable(self, thing):
+        self.assertIn('__call__', dir(thing))
+
     def test_load_net_test_from_file(self):
         """
-        Given a file like object verify that the net test cases are properly
+        Given a file verify that the net test cases are properly
         generated.
         """
         __, net_test_file = mkstemp()
@@ -77,17 +80,36 @@ class TestNetTest(unittest.TestCase):
             f.write(net_test_string)
         f.close()
 
-        net_test_from_string = NetTest(StringIO(net_test_string),
-                dummyInputs, dummyOptions, DummyReporter())
         net_test_from_file = NetTest(net_test_file, dummyInputs,
                 dummyOptions, DummyReporter())
 
-        # XXX: the returned classes are not the same because the
-        # module path is not correct, so the test below fails.
-        # TODO: figure out how to verify that the instantiated
-        # classes are done so properly.
+        test_methods = set()
+        for test_class, test_method in net_test_from_file.test_cases:
+            instance = test_class()
+            c = getattr(instance, test_method)
+            self.assertCallable(c)
+
+            test_methods.add(test_method)
+
+        self.assertEqual(set(['test_a', 'test_b']), test_methods)
 
-        #self.assertEqual(net_test_from_string.test_cases,
-        #        net_test_from_file.test_cases)
         os.unlink(net_test_file)
 
+    def test_load_net_test_from_string(self):
+        """
+        Given a file like object verify that the net test cases are properly
+        generated.
+        """
+        net_test_from_string = NetTest(StringIO(net_test_string),
+                dummyInputs, dummyOptions, DummyReporter())
+
+        test_methods = set()
+        for test_class, test_method in net_test_from_string.test_cases:
+            instance = test_class()
+            c = getattr(instance, test_method)
+            self.assertCallable(c)
+
+            test_methods.add(test_method)
+
+        self.assertEqual(set(['test_a', 'test_b']), test_methods)
+





More information about the tor-commits mailing list