aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-06-07 17:12:52 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-06-07 17:12:52 +1200
commit1ffc273c9433fc8840b71c79879ae427c93313bd (patch)
treea656cb3f336a64d37967dbd4c36cad040370d72a /test
parentb180bfcf35302cb37f93be60ff954c6d645002b0 (diff)
downloadmitmproxy-1ffc273c9433fc8840b71c79879ae427c93313bd.tar.gz
mitmproxy-1ffc273c9433fc8840b71c79879ae427c93313bd.tar.bz2
mitmproxy-1ffc273c9433fc8840b71c79879ae427c93313bd.zip
Utils cleanups
- Move more stuff that belongs in netlib.human - Move some stuff to near the only use - Zap mitmproxy.utils.timestamp(). I see the rationale, but we used it interchangeably with time.time() throughout the project. Since time.time() dominates in the codebase and timestamp() is such low utility, away it goes.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_contentview.py8
-rw-r--r--test/mitmproxy/test_utils.py15
-rw-r--r--test/netlib/test_human.py9
-rw-r--r--test/pathod/test_pathod_cmdline.py5
-rw-r--r--test/pathod/test_utils.py5
5 files changed, 22 insertions, 20 deletions
diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py
index 9142bdad..48d6c307 100644
--- a/test/mitmproxy/test_contentview.py
+++ b/test/mitmproxy/test_contentview.py
@@ -1,3 +1,5 @@
+import json
+
from mitmproxy.exceptions import ContentViewException
from netlib.http import Headers
from netlib.odict import ODict
@@ -274,3 +276,9 @@ if cv.ViewProtobuf.is_available():
def test_get_by_shortcut():
assert cv.get_by_shortcut("h")
+
+
+def test_pretty_json():
+ s = json.dumps({"foo": 1})
+ assert cv.pretty_json(s)
+ assert not cv.pretty_json("moo")
diff --git a/test/mitmproxy/test_utils.py b/test/mitmproxy/test_utils.py
index c01b5f2a..79b72eec 100644
--- a/test/mitmproxy/test_utils.py
+++ b/test/mitmproxy/test_utils.py
@@ -1,29 +1,14 @@
-import json
from mitmproxy import utils
from . import tutils
utils.CERT_SLEEP_TIME = 0
-def test_format_timestamp():
- assert utils.format_timestamp(utils.timestamp())
-
-
-def test_format_timestamp_with_milli():
- assert utils.format_timestamp_with_milli(utils.timestamp())
-
-
def test_pkg_data():
assert utils.pkg_data.path("console")
tutils.raises("does not exist", utils.pkg_data.path, "nonexistent")
-def test_pretty_json():
- s = json.dumps({"foo": 1})
- assert utils.pretty_json(s)
- assert not utils.pretty_json("moo")
-
-
def test_LRUCache():
cache = utils.LRUCache(2)
diff --git a/test/netlib/test_human.py b/test/netlib/test_human.py
index 2a5c2a85..bb97dc54 100644
--- a/test/netlib/test_human.py
+++ b/test/netlib/test_human.py
@@ -1,6 +1,15 @@
+import time
from netlib import human, tutils
+def test_format_timestamp():
+ assert human.format_timestamp(time.time())
+
+
+def test_format_timestamp_with_milli():
+ assert human.format_timestamp_with_milli(time.time())
+
+
def test_parse_size():
assert human.parse_size("0") == 0
assert human.parse_size("0b") == 0
diff --git a/test/pathod/test_pathod_cmdline.py b/test/pathod/test_pathod_cmdline.py
index 3c0918ef..18d54c82 100644
--- a/test/pathod/test_pathod_cmdline.py
+++ b/test/pathod/test_pathod_cmdline.py
@@ -3,6 +3,11 @@ import tutils
import mock
+def test_parse_anchor_spec():
+ assert cmdline.parse_anchor_spec("foo=200") == ("foo", "200")
+ assert cmdline.parse_anchor_spec("foo") is None
+
+
@mock.patch("argparse.ArgumentParser.error")
def test_pathod(perror):
assert cmdline.args_pathod(["pathod"])
diff --git a/test/pathod/test_utils.py b/test/pathod/test_utils.py
index a46a523a..2bb82fe7 100644
--- a/test/pathod/test_utils.py
+++ b/test/pathod/test_utils.py
@@ -11,10 +11,5 @@ def test_membool():
assert m.v == 2
-def test_parse_anchor_spec():
- assert utils.parse_anchor_spec("foo=200") == ("foo", "200")
- assert utils.parse_anchor_spec("foo") is None
-
-
def test_data_path():
tutils.raises(ValueError, utils.data.path, "nonexistent")