[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Add tests for NetTest
commit 7cdfc6f6dd0dbee7ac18384d5f37b1a365763ad8
Author: aagbsn <aagbsn@xxxxxxxx>
Date: Sat Jan 12 20:35:46 2013 +0000
Add tests for NetTest
Test loading NetTestCase with required options and verify that
the appropriate exceptions are raised.
---
tests/test_nettest.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 57 insertions(+), 1 deletions(-)
diff --git a/tests/test_nettest.py b/tests/test_nettest.py
index 8546031..6ef214c 100644
--- a/tests/test_nettest.py
+++ b/tests/test_nettest.py
@@ -5,7 +5,8 @@ from tempfile import TemporaryFile, mkstemp
from twisted.trial import unittest
from twisted.internet import defer, reactor
-from ooni.nettest import NetTest
+from ooni.nettest import NetTest, InvalidOption, MissingRequiredOption
+from ooni.nettest import FailureToLoadNetTest
from ooni.tasks import BaseTask
net_test_string = """
@@ -25,8 +26,17 @@ class DummyTestCase(NetTestCase):
self.report['foo'] = 'foo'
"""
+net_test_root_required = net_test_string+"""
+ requiresRoot = True
+"""
+
+#XXX you should actually implement this
+net_test_with_required_option = net_test_string
+
dummyInputs = range(1)
dummyOptions = {'spam': 'notham'}
+dummyInvalidOptions = {'':''} # XXX: make invalid options
+dummyOptionsWithRequiredOptions = {'':''} #XXX: set required options here
#dummyNetTest = NetTest(net_test_file, inputs, options)
@@ -113,3 +123,49 @@ class TestNetTest(unittest.TestCase):
self.assertEqual(set(['test_a', 'test_b']), test_methods)
+ def test_load_with_option(self):
+ self.assertIsInstance(NetTest(StringIO(net_test_string),
+ dummyInputs, dummyOptions, None), NetTest)
+
+ #def test_load_with_invalid_option(self):
+ # #XXX: raises TypeError??
+ # self.assertRaises(InvalidOption, NetTest(StringIO(net_test_string), dummyInputs,
+ # dummyInvalidOptions, None))
+
+ def test_load_with_required_option(self):
+ self.assertIsInstance(NetTest(StringIO(net_test_with_required_option),
+ dummyInputs, dummyOptionsWithRequiredOptions, None), NetTest)
+
+ #def test_load_with_missing_required_option(self):
+ # #XXX: raises TypeError
+ # self.assertRaises(MissingRequiredOption,
+ # NetTest(StringIO(net_test_with_required_option), dummyInputs,
+ # dummyOptions, None))
+
+ def test_require_root_succeed(self):
+ #XXX: make root succeed
+ NetTest(StringIO(net_test_root_required),
+ dummyInputs, dummyOptions, None)
+
+ def test_require_root_failed(self):
+ #XXX: make root fail
+ NetTest(StringIO(net_test_root_required),
+ dummyInputs, dummyOptions, None)
+
+ #def test_create_report_succeed(self):
+ # pass
+
+ #def test_create_report_failed(self):
+ # pass
+
+ #def test_run_all_test(self):
+ # raise NotImplementedError
+
+ #def test_resume_test(self):
+ # pass
+
+ #def test_progress(self):
+ # pass
+
+ #def test_time_out(self):
+ # raise NotImplementedError
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits