commit 4f169919d41e60fd91709e8e7a3ca351c7945870 Author: Arturo Filastò arturo@filasto.net Date: Tue Jun 21 18:38:14 2016 +0200
Add support for specifying the test name without the category prefix. (#532)
* Add support for specifying the test name without the category prefix.
This implements: https://github.com/TheTorProject/ooni-probe/issues/483
* Remove redundant code --- ooni/deck.py | 25 +++++++++++++++++++++---- ooni/tests/test_deck.py | 11 ++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/ooni/deck.py b/ooni/deck.py index 657589d..82f98a1 100644 --- a/ooni/deck.py +++ b/ooni/deck.py @@ -73,6 +73,9 @@ def nettest_to_path(path, allow_arbitrary_paths=False): """ Takes as input either a path or a nettest name.
+ The nettest name may either be prefixed by the category of the nettest ( + blocking, experimental, manipulation or third_party) or not. + Args:
allow_arbitrary_paths: @@ -85,11 +88,25 @@ def nettest_to_path(path, allow_arbitrary_paths=False): if allow_arbitrary_paths and os.path.exists(path): return path
- fp = FilePath(config.nettest_directory).preauthChild(path + '.py') - if fp.exists(): - return fp.path - else: + test_name = path.rsplit("/", 1)[-1] + test_categories = [ + "blocking", + "experimental", + "manipulation", + "third_party" + ] + nettest_dir = FilePath(config.nettest_directory) + found_path = None + for category in test_categories: + p = nettest_dir.preauthChild(os.path.join(category, test_name) + '.py') + if p.exists(): + if found_path is not None: + raise Exception("Found two tests named %s" % test_name) + found_path = p.path + + if not found_path: raise e.NetTestNotFound(path) + return found_path
class Deck(InputFile): diff --git a/ooni/tests/test_deck.py b/ooni/tests/test_deck.py index 1e311cf..e4f661f 100644 --- a/ooni/tests/test_deck.py +++ b/ooni/tests/test_deck.py @@ -4,7 +4,8 @@ from twisted.internet import defer from twisted.trial import unittest
from hashlib import sha256 -from ooni.deck import InputFile, Deck +from ooni import errors +from ooni.deck import InputFile, Deck, nettest_to_path from ooni.tests.mocks import MockBouncerClient, MockCollectorClient
net_test_string = """ @@ -202,3 +203,11 @@ class TestDeck(BaseTestCase): deck.netTestLoaders[1].localOptions['backend'], '2.2.2.2' ) + + def test_nettest_to_path(self): + path_a = nettest_to_path("blocking/http_requests") + path_b = nettest_to_path("http_requests") + self.assertEqual(path_a, path_b) + self.assertRaises(errors.NetTestNotFound, + nettest_to_path, + "invalid_test")
tor-commits@lists.torproject.org