From d998790c2f12594e6d0edc5a98e908677b60b31f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 17 Sep 2014 11:35:14 +1200 Subject: Clean up and clarify StateObject - Flatten the class hierarchy - get_state, load_state, from_state are public - Simplify code - Remove __eq__ and __neq__. This fundamentally changes the semantics of inherited objects in a way that's not part of the core function of the class --- test/test_flow.py | 54 +++++++++++++++++++++++++++--------------------------- test/tutils.py | 4 ++-- 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'test') diff --git a/test/test_flow.py b/test/test_flow.py index cb899e2a..c5254d11 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -175,18 +175,18 @@ class TestServerPlaybackState: class TestFlow: def test_copy(self): f = tutils.tflow(resp=True) - a0 = f._get_state() + a0 = f.get_state() f2 = f.copy() - a = f._get_state() - b = f2._get_state() - assert f._get_state() == f2._get_state() + a = f.get_state() + b = f2.get_state() + assert f.get_state() == f2.get_state() assert not f == f2 assert not f is f2 - assert f.request == f2.request + assert f.request.get_state() == f2.request.get_state() assert not f.request is f2.request assert f.request.headers == f2.request.headers assert not f.request.headers is f2.request.headers - assert f.response == f2.response + assert f.response.get_state() == f2.response.get_state() assert not f.response is f2.response f = tutils.tflow(err=True) @@ -195,7 +195,7 @@ class TestFlow: assert not f.request is f2.request assert f.request.headers == f2.request.headers assert not f.request.headers is f2.request.headers - assert f.error == f2.error + assert f.error.get_state() == f2.error.get_state() assert not f.error is f2.error def test_match(self): @@ -229,21 +229,21 @@ class TestFlow: def test_getset_state(self): f = tutils.tflow(resp=True) - state = f._get_state() - assert f._get_state() == protocol.http.HTTPFlow._from_state(state)._get_state() + state = f.get_state() + assert f.get_state() == protocol.http.HTTPFlow.from_state(state).get_state() f.response = None f.error = Error("error") - state = f._get_state() - assert f._get_state() == protocol.http.HTTPFlow._from_state(state)._get_state() + state = f.get_state() + assert f.get_state() == protocol.http.HTTPFlow.from_state(state).get_state() f2 = f.copy() - assert f._get_state() == f2._get_state() + assert f.get_state() == f2.get_state() assert not f == f2 f2.error = Error("e2") assert not f == f2 - f._load_state(f2._get_state()) - assert f._get_state() == f2._get_state() + f.load_state(f2.get_state()) + assert f.get_state() == f2.get_state() def test_kill(self): s = flow.State() @@ -481,7 +481,7 @@ class TestSerialize: assert len(l) == 1 f2 = l[0] - assert f2._get_state() == f._get_state() + assert f2.get_state() == f.get_state() assert f2.request.assemble() == f.request.assemble() def test_load_flows(self): @@ -521,7 +521,7 @@ class TestSerialize: def test_versioncheck(self): f = tutils.tflow() - d = f._get_state() + d = f.get_state() d["version"] = (0, 0) sio = StringIO() tnetstring.dump(d, sio) @@ -770,7 +770,7 @@ class TestRequest: assert r.size() == len(r.assemble()) r2 = r.copy() - assert r == r2 + assert r.get_state() == r2.get_state() r.content = None assert r.assemble() @@ -979,7 +979,7 @@ class TestResponse: assert resp.size() == len(resp.assemble()) resp2 = resp.copy() - assert resp2 == resp + assert resp2.get_state() == resp.get_state() resp.content = None assert resp.assemble() @@ -1122,37 +1122,37 @@ class TestResponse: class TestError: def test_getset_state(self): e = Error("Error") - state = e._get_state() - assert Error._from_state(state) == e + state = e.get_state() + assert Error.from_state(state).get_state() == e.get_state() assert e.copy() e2 = Error("bar") assert not e == e2 - e._load_state(e2._get_state()) - assert e == e2 - + e.load_state(e2.get_state()) + assert e.get_state() == e2.get_state() e3 = e.copy() - assert e3 == e + assert e3.get_state() == e.get_state() class TestClientConnection: def test_state(self): c = tutils.tclient_conn() - assert ClientConnection._from_state(c._get_state()) == c + assert ClientConnection.from_state(c.get_state()).get_state() ==\ + c.get_state() c2 = tutils.tclient_conn() c2.address.address = (c2.address.host, 4242) assert not c == c2 c2.timestamp_start = 42 - c._load_state(c2._get_state()) + c.load_state(c2.get_state()) assert c.timestamp_start == 42 c3 = c.copy() - assert c3 == c + assert c3.get_state() == c.get_state() assert str(c) diff --git a/test/tutils.py b/test/tutils.py index 69f79a91..e7720d33 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -55,7 +55,7 @@ def tclient_conn(): """ @return: libmproxy.proxy.connection.ClientConnection """ - c = ClientConnection._from_state(dict( + c = ClientConnection.from_state(dict( address=dict(address=("address", 22), use_ipv6=True), clientcert=None )) @@ -67,7 +67,7 @@ def tserver_conn(): """ @return: libmproxy.proxy.connection.ServerConnection """ - c = ServerConnection._from_state(dict( + c = ServerConnection.from_state(dict( address=dict(address=("address", 22), use_ipv6=True), state=[], source_address=dict(address=("address", 22), use_ipv6=True), -- cgit v1.2.3