commit bbd6a1ada2d8dc2e3959b385408295d4c9970189 Author: kudrom kudrom@riseup.net Date: Sat Jun 21 20:44:44 2014 +0200
Safe config use between tests --- ooni/tests/__init__.py | 1 + ooni/tests/test_director.py | 3 +-- ooni/tests/test_geoip.py | 4 ---- ooni/tests/test_managers.py | 10 ++++++++++ ooni/tests/test_nettest.py | 1 + ooni/tests/test_oonibclient.py | 3 +++ ooni/tests/test_oonicli.py | 1 + 7 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/ooni/tests/__init__.py b/ooni/tests/__init__.py index b0bbfbd..e7fd48b 100644 --- a/ooni/tests/__init__.py +++ b/ooni/tests/__init__.py @@ -2,6 +2,7 @@ import socket from ooni.settings import config
config.initialize_ooni_home('ooni_home') +config.read_config_file() config.logging = False config.advanced.debug = False
diff --git a/ooni/tests/test_director.py b/ooni/tests/test_director.py index 1033f8e..cd0483b 100644 --- a/ooni/tests/test_director.py +++ b/ooni/tests/test_director.py @@ -29,8 +29,7 @@ mock_launch_tor.return_value = defer.succeed(proto) class TestDirector(unittest.TestCase): def tearDown(self): config.tor_state = None - config.tor.socks_port = None - config.tor.control_port = None + config.read_config_file()
def test_get_net_tests(self): director = Director() diff --git a/ooni/tests/test_geoip.py b/ooni/tests/test_geoip.py index affcea6..b801cff 100644 --- a/ooni/tests/test_geoip.py +++ b/ooni/tests/test_geoip.py @@ -9,10 +9,6 @@ from ooni import geoip
class TestGeoIP(unittest.TestCase): - def setUp(self): - config.initialize_ooni_home('ooni_home') - config.read_config_file() - def test_ip_to_location(self): location = geoip.IPToLocation('8.8.8.8') assert 'countrycode' in location diff --git a/ooni/tests/test_managers.py b/ooni/tests/test_managers.py index ce921e3..d7f3177 100644 --- a/ooni/tests/test_managers.py +++ b/ooni/tests/test_managers.py @@ -29,9 +29,19 @@ class TestTaskManager(unittest.TestCase): self.clock = task.Clock() data_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(data_dir, '..', '..', 'data') + self.old_datadir = "" + if hasattr(config.global_options, 'datadir'): + self.old_datadir = config.global_options['datadir'] config.global_options['datadir'] = data_dir config.set_paths()
+ def tearDown(self): + if self.old_datadir == "": + del config.global_options['datadir'] + else: + config.global_options['datadir'] = self.old_datadir + config.set_paths() + def schedule_successful_tasks(self, task_type, number=1): all_done = [] for x in range(number): diff --git a/ooni/tests/test_nettest.py b/ooni/tests/test_nettest.py index 5a871ee..92d6cea 100644 --- a/ooni/tests/test_nettest.py +++ b/ooni/tests/test_nettest.py @@ -304,6 +304,7 @@ class TestNettestTimeout(unittest.TestCase): def tearDown(self): self.factory.stopFactory() self.port.stopListening() + config.read_config_file()
def test_nettest_timeout(self): ntl = NetTestLoader(('-u', 'http://localhost:8007/')) diff --git a/ooni/tests/test_oonibclient.py b/ooni/tests/test_oonibclient.py index 872000e..c6615cb 100644 --- a/ooni/tests/test_oonibclient.py +++ b/ooni/tests/test_oonibclient.py @@ -37,6 +37,9 @@ class TestOONIBClient(unittest.TestCase): self.skipTest("OONIB must be listening on port 8888 to run this test (tor_hidden_service: false)") self.oonibclient = OONIBClient('http://' + host + ':' + str(port))
+ def tearDown(self): + config.read_config_file() + @defer.inlineCallbacks def test_query(self): res = yield self.oonibclient.queryBackend('GET', '/policy/input') diff --git a/ooni/tests/test_oonicli.py b/ooni/tests/test_oonicli.py index eebad28..4da63f0 100644 --- a/ooni/tests/test_oonicli.py +++ b/ooni/tests/test_oonicli.py @@ -38,6 +38,7 @@ class TestRunDirector(unittest.TestCase): f.write('http://blog.torproject.org/%5Cn')
def tearDown(self): + config.read_config_file() try: os.remove('test_report.yaml') except:
tor-commits@lists.torproject.org