From 069119364d6490e52ba26f2d8001c6b2bf50ab7b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 20 Oct 2016 09:35:55 +1300 Subject: Create mitmproxy.utils hierarchy - Add mitproxy.utils.lrucache, mitproxy.utils.data --- test/mitmproxy/test_examples.py | 5 ++--- test/mitmproxy/test_utils.py | 42 ----------------------------------- test/mitmproxy/test_utils_data.py | 7 ++++++ test/mitmproxy/test_utils_lrucache.py | 34 ++++++++++++++++++++++++++++ test/mitmproxy/tutils.py | 3 ++- test/pathod/tutils.py | 5 +++-- 6 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 test/mitmproxy/test_utils.py create mode 100644 test/mitmproxy/test_utils_data.py create mode 100644 test/mitmproxy/test_utils_lrucache.py (limited to 'test') diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 7551c1c8..60d4a1a5 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -6,17 +6,16 @@ from mitmproxy import options from mitmproxy import contentviews from mitmproxy import proxy from mitmproxy.addons import script +from mitmproxy.utils import data from mitmproxy import master -import netlib.utils - from netlib import tutils as netutils from netlib.http import Headers from netlib.http import cookies from . import tutils, mastertest -example_dir = netlib.utils.Data(__name__).push("../../examples") +example_dir = data.Data(__name__).push("../../examples") class ScriptError(Exception): diff --git a/test/mitmproxy/test_utils.py b/test/mitmproxy/test_utils.py deleted file mode 100644 index ed59f484..00000000 --- a/test/mitmproxy/test_utils.py +++ /dev/null @@ -1,42 +0,0 @@ -from mitmproxy import utils -from . import tutils - -utils.CERT_SLEEP_TIME = 0 - - -def test_pkg_data(): - assert utils.pkg_data.path("tools/console") - tutils.raises("does not exist", utils.pkg_data.path, "nonexistent") - - -def test_LRUCache(): - cache = utils.LRUCache(2) - - class Foo: - ran = False - - def gen(self, x): - self.ran = True - return x - f = Foo() - - assert not f.ran - assert cache.get(f.gen, 1) == 1 - assert f.ran - f.ran = False - assert cache.get(f.gen, 1) == 1 - assert not f.ran - - f.ran = False - assert cache.get(f.gen, 1) == 1 - assert not f.ran - assert cache.get(f.gen, 2) == 2 - assert cache.get(f.gen, 3) == 3 - assert f.ran - - f.ran = False - assert cache.get(f.gen, 1) == 1 - assert f.ran - - assert len(cache.cacheList) == 2 - assert len(cache.cache) == 2 diff --git a/test/mitmproxy/test_utils_data.py b/test/mitmproxy/test_utils_data.py new file mode 100644 index 00000000..c6e4420e --- /dev/null +++ b/test/mitmproxy/test_utils_data.py @@ -0,0 +1,7 @@ +from mitmproxy.utils import data +from . import tutils + + +def test_pkg_data(): + assert data.pkg_data.path("tools/console") + tutils.raises("does not exist", data.pkg_data.path, "nonexistent") diff --git a/test/mitmproxy/test_utils_lrucache.py b/test/mitmproxy/test_utils_lrucache.py new file mode 100644 index 00000000..f75fb5e8 --- /dev/null +++ b/test/mitmproxy/test_utils_lrucache.py @@ -0,0 +1,34 @@ +from mitmproxy import utils + + +def test_LRUCache(): + cache = utils.LRUCache(2) + + class Foo: + ran = False + + def gen(self, x): + self.ran = True + return x + f = Foo() + + assert not f.ran + assert cache.get(f.gen, 1) == 1 + assert f.ran + f.ran = False + assert cache.get(f.gen, 1) == 1 + assert not f.ran + + f.ran = False + assert cache.get(f.gen, 1) == 1 + assert not f.ran + assert cache.get(f.gen, 2) == 2 + assert cache.get(f.gen, 3) == 3 + assert f.ran + + f.ran = False + assert cache.get(f.gen, 1) == 1 + assert f.ran + + assert len(cache.cacheList) == 2 + assert len(cache.cache) == 2 diff --git a/test/mitmproxy/tutils.py b/test/mitmproxy/tutils.py index eb0c90e9..71dd20a4 100644 --- a/test/mitmproxy/tutils.py +++ b/test/mitmproxy/tutils.py @@ -16,6 +16,7 @@ from mitmproxy import connections from mitmproxy import flow from mitmproxy import http from mitmproxy import tcp +from mitmproxy.utils import data def _skip_windows(*args): @@ -208,4 +209,4 @@ def capture_stderr(command, *args, **kwargs): sys.stderr = out -test_data = netlib.utils.Data(__name__) +test_data = data.Data(__name__) diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index c2243578..171d97a4 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -5,8 +5,9 @@ import requests import io import urllib +from mitmproxy.utils import data + from netlib import tcp -from netlib import utils from netlib import tutils from pathod import language @@ -142,7 +143,7 @@ tmpdir = tutils.tmpdir raises = tutils.raises -test_data = utils.Data(__name__) +test_data = data.Data(__name__) def render(r, settings=language.Settings()): -- cgit v1.2.3