diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-03-22 21:00:41 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-03-22 21:00:41 +1300 |
commit | 842e23d3e386169d9a90cef2a634c55a3e5fdd8e (patch) | |
tree | 4932fa82faf92d36fbe7a8d56741a892c7003119 /test | |
parent | a2da38cc8339887abef4efa23cc54fa02c981f3f (diff) | |
download | mitmproxy-842e23d3e386169d9a90cef2a634c55a3e5fdd8e.tar.gz mitmproxy-842e23d3e386169d9a90cef2a634c55a3e5fdd8e.tar.bz2 mitmproxy-842e23d3e386169d9a90cef2a634c55a3e5fdd8e.zip |
Replace far-too-clever decorator LRU cache with something simpler
Diffstat (limited to 'test')
-rw-r--r-- | test/test_utils.py | 26 | ||||
-rwxr-xr-x | test/tools/testpatt | 10 |
2 files changed, 18 insertions, 18 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index 78d1c072..1678a7de 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -62,38 +62,39 @@ def test_pretty_duration(): assert utils.pretty_duration(10) == "10.0s" assert utils.pretty_duration(100) == "100s" assert utils.pretty_duration(1000) == "1000s" - assert utils.pretty_duration(10000) == "10000s" + assert utils.pretty_duration(10000) == "10000s" assert utils.pretty_duration(1.123) == "1.12s" assert utils.pretty_duration(0.123) == "123ms" def test_LRUCache(): + cache = utils.LRUCache(2) class Foo: ran = False - @utils.LRUCache(2) - def one(self, x): + def gen(self, x): self.ran = True return x - f = Foo() - assert f.one(1) == 1 + + assert not f.ran + assert cache.get(f.gen, 1) == 1 assert f.ran f.ran = False - assert f.one(1) == 1 + assert cache.get(f.gen, 1) == 1 assert not f.ran f.ran = False - assert f.one(1) == 1 + assert cache.get(f.gen, 1) == 1 assert not f.ran - assert f.one(2) == 2 - assert f.one(3) == 3 + assert cache.get(f.gen, 2) == 2 + assert cache.get(f.gen, 3) == 3 assert f.ran f.ran = False - assert f.one(1) == 1 + assert cache.get(f.gen, 1) == 1 assert f.ran - assert len(f._cached_one) == 2 - assert len(f._cachelist_one) == 2 + assert len(cache.cacheList) == 2 + assert len(cache.cache) == 2 def test_unparse_url(): @@ -128,4 +129,3 @@ def test_safe_subn(): def test_urlencode(): assert utils.urlencode([('foo','bar')]) - diff --git a/test/tools/testpatt b/test/tools/testpatt index d4546d48..5ee1ea02 100755 --- a/test/tools/testpatt +++ b/test/tools/testpatt @@ -2,8 +2,8 @@ # Generate a test pattern with pathoc PATHOD=http://localhost:9999 -pathoc localhost:8080 "get:'$PATHOD/p/200:p0,1:b@200b':b@200b" -pathoc localhost:8080 "get:'$PATHOD/p/300:p0,1:b@200b':b@200b" -pathoc localhost:8080 "get:'$PATHOD/p/400:p0,1:b@200b':b@200b" -pathoc localhost:8080 "get:'$PATHOD/p/500:p0,1:b@200b':b@200b" -pathoc localhost:8080 "get:'$PATHOD/p/600:p0,1:b@200b':b@200b" +pathoc localhost:8080 "get:'$PATHOD/p/200:p0,1:b@2048b':b@2048b" +pathoc localhost:8080 "get:'$PATHOD/p/300:p0,1:b@2048b':b@2048b" +pathoc localhost:8080 "get:'$PATHOD/p/400:p0,1:b@2048b':b@2048b" +pathoc localhost:8080 "get:'$PATHOD/p/500:p0,1:b@2048b':b@2048b" +pathoc localhost:8080 "get:'$PATHOD/p/600:p0,1:b@2048b':b@2048b" |