diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-05-30 12:03:13 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-05-30 12:03:13 +1200 |
commit | 4ed5043c67848bf717e48bc509d959422c8faeb6 (patch) | |
tree | 92abe731c72d34bf6b43cbe1ecb46939953a6860 /test | |
parent | 904760c6c2927caf49b7cbe4027dd1c8dd8e9fdb (diff) | |
download | mitmproxy-4ed5043c67848bf717e48bc509d959422c8faeb6.tar.gz mitmproxy-4ed5043c67848bf717e48bc509d959422c8faeb6.tar.bz2 mitmproxy-4ed5043c67848bf717e48bc509d959422c8faeb6.zip |
Add coding style check, reformat.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_app.py | 7 | ||||
-rw-r--r-- | test/test_cmdline.py | 8 | ||||
-rw-r--r-- | test/test_language_actions.py | 3 | ||||
-rw-r--r-- | test/test_language_base.py | 4 | ||||
-rw-r--r-- | test/test_language_http.py | 8 | ||||
-rw-r--r-- | test/test_pathoc.py | 21 | ||||
-rw-r--r-- | test/test_pathod.py | 6 | ||||
-rw-r--r-- | test/test_test.py | 19 | ||||
-rw-r--r-- | test/test_utils.py | 5 | ||||
-rw-r--r-- | test/tutils.py | 12 |
10 files changed, 60 insertions, 33 deletions
diff --git a/test/test_app.py b/test/test_app.py index 7c7ac730..4536db8e 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -29,7 +29,7 @@ class TestApp(tutils.DaemonTests): assert self.get("200:da").status_code == 200 id = self.d.log()[0]["id"] assert self.getpath("/log").status_code == 200 - assert self.getpath("/log/%s"%id).status_code == 200 + assert self.getpath("/log/%s" % id).status_code == 200 assert self.getpath("/log/9999999").status_code == 404 def test_log_binary(self): @@ -52,7 +52,10 @@ class TestApp(tutils.DaemonTests): assert r.status_code == 200 assert 'Response' in r.content - r = self.getpath("/response_preview", params=dict(spec="200:b<nonexistent")) + r = self.getpath( + "/response_preview", + params=dict( + spec="200:b<nonexistent")) assert r.status_code == 200 assert 'File access denied' in r.content diff --git a/test/test_cmdline.py b/test/test_cmdline.py index c51b6cf0..5a9ee242 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -27,7 +27,6 @@ def test_pathod(perror): assert perror.called perror.reset_mock() - a = cmdline.args_pathod( [ "pathod", @@ -99,7 +98,9 @@ def test_pathod(perror): def test_pathoc(perror): assert cmdline.args_pathoc(["pathoc", "foo.com", "get:/"]) s = cStringIO.StringIO() - tutils.raises(SystemExit, cmdline.args_pathoc, ["pathoc", "--show-uas"], s, s) + tutils.raises( + SystemExit, cmdline.args_pathoc, [ + "pathoc", "--show-uas"], s, s) a = cmdline.args_pathoc(["pathoc", "foo.com:8888", "get:/"]) assert a.port == 8888 @@ -122,7 +123,8 @@ def test_pathoc(perror): assert perror.called perror.reset_mock() - a = cmdline.args_pathoc(["pathoc", "-c", "foo:bar", "foo.com:8888", "get:/"]) + a = cmdline.args_pathoc( + ["pathoc", "-c", "foo:bar", "foo.com:8888", "get:/"]) assert perror.called perror.reset_mock() diff --git a/test/test_language_actions.py b/test/test_language_actions.py index b7361dff..16d54806 100644 --- a/test/test_language_actions.py +++ b/test/test_language_actions.py @@ -113,8 +113,7 @@ class Test_Action: c = actions.DisconnectAt(0) assert a < b assert a == c - l = [b, a] - l.sort() + l = sorted([b, a]) assert l[0].offset == 0 def test_resolve(self): diff --git a/test/test_language_base.py b/test/test_language_base.py index 329778a9..d59ee88b 100644 --- a/test/test_language_base.py +++ b/test/test_language_base.py @@ -69,7 +69,7 @@ class TestTokValueLiteral: self.roundtrip('\'') self.roundtrip("a") self.roundtrip("\"") - #self.roundtrip("\\") + # self.roundtrip("\\") self.roundtrip("200:b'foo':i23,'\\''") self.roundtrip("\a") @@ -321,8 +321,6 @@ def test_integer(): assert BInt(3) - - class TBoolean(base.Boolean): name = "test" diff --git a/test/test_language_http.py b/test/test_language_http.py index 17bce802..3bdd0ec5 100644 --- a/test/test_language_http.py +++ b/test/test_language_http.py @@ -214,7 +214,7 @@ class TestResponse: ) try: language.parse_response("400'msg':b:") - except language.ParseException, v: + except language.ParseException as v: assert v.marked() assert str(v) @@ -293,8 +293,10 @@ def test_location_shortcut(): def test_shortcuts(): - assert language.parse_response("400:c'foo'").headers[0].key.val == "Content-Type" - assert language.parse_response("400:l'foo'").headers[0].key.val == "Location" + assert language.parse_response( + "400:c'foo'").headers[0].key.val == "Content-Type" + assert language.parse_response( + "400:l'foo'").headers[0].key.val == "Location" assert "Android" in tutils.render(parse_request("get:/:ua")) assert "User-Agent" in tutils.render(parse_request("get:/:ua")) diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 8d0d5972..1735f084 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -128,20 +128,33 @@ class TestDaemon(_TestDaemon): tutils.raises("ssl handshake", c.connect) def test_showssl(self): - assert not "certificate chain" in self.tval(["get:/p/200"], showssl=True) + assert not "certificate chain" in self.tval( + ["get:/p/200"], + showssl=True) def test_ignorecodes(self): assert "200" in self.tval(["get:'/p/200:b@1'"]) assert "200" in self.tval(["get:'/p/200:b@1'"]) assert "200" in self.tval(["get:'/p/200:b@1'"]) assert "200" not in self.tval(["get:'/p/200:b@1'"], ignorecodes=[200]) - assert "200" not in self.tval(["get:'/p/200:b@1'"], ignorecodes=[200, 201]) + assert "200" not in self.tval( + ["get:'/p/200:b@1'"], + ignorecodes=[ + 200, + 201]) assert "202" in self.tval(["get:'/p/202:b@1'"], ignorecodes=[200, 201]) def test_timeout(self): assert "Timeout" in self.tval(["get:'/p/200:p0,10'"], timeout=0.01) - assert "HTTP" in self.tval(["get:'/p/200:p5,10'"], showresp=True, timeout=0.01) - assert not "HTTP" in self.tval(["get:'/p/200:p3,10'"], showresp=True, timeout=0.01, ignoretimeout=True) + assert "HTTP" in self.tval( + ["get:'/p/200:p5,10'"], + showresp=True, + timeout=0.01) + assert not "HTTP" in self.tval( + ["get:'/p/200:p3,10'"], + showresp=True, + timeout=0.01, + ignoretimeout=True) def test_showresp(self): reqs = ["get:/api/info:p0,0", "get:/api/info:p0,0"] diff --git a/test/test_pathod.py b/test/test_pathod.py index bfff3274..7f07c041 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -53,6 +53,7 @@ class TestNotAfterConnect(tutils.DaemonTests): ssloptions = dict( not_after_connect = True ) + def test_connect(self): r = self.pathoc( r"get:'http://foo.com/p/202':da", @@ -66,6 +67,7 @@ class TestCustomCert(tutils.DaemonTests): ssloptions = dict( certs = [("*", tutils.test_data.path("data/testkey.pem"))], ) + def test_connect(self): r = self.pathoc(r"get:/p/202") assert r.status_code == 202 @@ -78,6 +80,7 @@ class TestSSLCN(tutils.DaemonTests): ssloptions = dict( cn = "foo.com" ) + def test_connect(self): r = self.pathoc(r"get:/p/202") assert r.status_code == 202 @@ -87,6 +90,7 @@ class TestSSLCN(tutils.DaemonTests): class TestNohang(tutils.DaemonTests): nohang = True + def test_nohang(self): r = self.get("200:p0,0") assert r.status_code == 800 @@ -96,6 +100,7 @@ class TestNohang(tutils.DaemonTests): class TestHexdump(tutils.DaemonTests): hexdump = True + def test_hexdump(self): r = self.get(r"200:b'\xf0'") @@ -194,6 +199,7 @@ class CommonTests(tutils.DaemonTests): class TestDaemon(CommonTests): ssl = False + def test_connect(self): r = self.pathoc( r"get:'http://foo.com/p/202':da", diff --git a/test/test_test.py b/test/test_test.py index 943fb270..681aa290 100644 --- a/test/test_test.py +++ b/test/test_test.py @@ -8,25 +8,28 @@ logging.disable(logging.CRITICAL) class TestDaemonManual: def test_simple(self): with test.Daemon() as d: - rsp = requests.get("http://localhost:%s/p/202:da"%d.port) + rsp = requests.get("http://localhost:%s/p/202:da" % d.port) assert rsp.ok assert rsp.status_code == 202 tutils.raises( "Connection aborted", requests.get, - "http://localhost:%s/p/202:da"%d.port + "http://localhost:%s/p/202:da" % d.port ) def test_startstop_ssl(self): d = test.Daemon(ssl=True) - rsp = requests.get("https://localhost:%s/p/202:da"%d.port, verify=False) + rsp = requests.get( + "https://localhost:%s/p/202:da" % + d.port, + verify=False) assert rsp.ok assert rsp.status_code == 202 d.shutdown() tutils.raises( "Connection aborted", requests.get, - "http://localhost:%s/p/202:da"%d.port + "http://localhost:%s/p/202:da" % d.port ) def test_startstop_ssl_explicit(self): @@ -36,13 +39,15 @@ class TestDaemonManual: ssl_after_connect = False ) d = test.Daemon(ssl=ssloptions) - rsp = requests.get("https://localhost:%s/p/202:da"%d.port, verify=False) + rsp = requests.get( + "https://localhost:%s/p/202:da" % + d.port, + verify=False) assert rsp.ok assert rsp.status_code == 202 d.shutdown() tutils.raises( "Connection aborted", requests.get, - "http://localhost:%s/p/202:da"%d.port + "http://localhost:%s/p/202:da" % d.port ) - diff --git a/test/test_utils.py b/test/test_utils.py index b8aa7f12..2a158a07 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -14,8 +14,8 @@ def test_membool(): def test_parse_size(): assert utils.parse_size("100") == 100 assert utils.parse_size("100k") == 100 * 1024 - tutils.raises("invalid size spec", utils.parse_size, "foo") - tutils.raises("invalid size spec", utils.parse_size, "100kk") + tutils.raises("invalid size spec", utils.parse_size, "foo") + tutils.raises("invalid size spec", utils.parse_size, "100kk") def test_parse_anchor_spec(): @@ -37,4 +37,3 @@ def test_escape_unprintables(): e = utils.escape_unprintables(s) assert e.encode('ascii') assert not "PATHOD_MARKER" in e - diff --git a/test/tutils.py b/test/tutils.py index 07252b53..933c7f59 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -30,7 +30,7 @@ class DaemonTests(object): ], ssl = klass.ssl, ssloptions = so, - sizelimit = 1*1024*1024, + sizelimit = 1 * 1024 * 1024, noweb = klass.noweb, noapi = klass.noapi, nohang = klass.nohang, @@ -53,7 +53,7 @@ class DaemonTests(object): def getpath(self, path, params=None): scheme = "https" if self.ssl else "http" return requests.get( - "%s://localhost:%s/%s"%( + "%s://localhost:%s/%s" % ( scheme, self.d.port, path @@ -115,14 +115,14 @@ def raises(exc, obj, *args, **kwargs): :kwargs Arguments to be passed to the callable. """ try: - apply(obj, args, kwargs) - except (Exception, SystemExit), v: + obj(*args, **kwargs) + except (Exception, SystemExit) as v: if isinstance(exc, basestring): if exc.lower() in str(v).lower(): return else: raise AssertionError( - "Expected %s, but caught %s"%( + "Expected %s, but caught %s" % ( repr(str(exc)), v ) ) @@ -131,7 +131,7 @@ def raises(exc, obj, *args, **kwargs): return else: raise AssertionError( - "Expected %s, but caught %s %s"%( + "Expected %s, but caught %s %s" % ( exc.__name__, v.__class__.__name__, str(v) ) ) |