mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
make tests compatible with py.test
This commit is contained in:
parent
0ad5cbc6bf
commit
292a0aa9e6
2
setup.py
2
setup.py
@ -57,6 +57,8 @@ setup(
|
|||||||
extras_require={
|
extras_require={
|
||||||
'dev': [
|
'dev': [
|
||||||
"mock>=1.0.1",
|
"mock>=1.0.1",
|
||||||
|
"pytest>=2.8.0",
|
||||||
|
"pytest-xdist>=1.13.1",
|
||||||
"nose>=1.3.0",
|
"nose>=1.3.0",
|
||||||
"nose-cov>=1.6",
|
"nose-cov>=1.6",
|
||||||
"coveralls>=0.4.1",
|
"coveralls>=0.4.1",
|
||||||
|
@ -3,9 +3,6 @@ from netlib import odict, tutils
|
|||||||
|
|
||||||
class TestODict(object):
|
class TestODict(object):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.od = odict.ODict()
|
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
h = odict.ODict()
|
h = odict.ODict()
|
||||||
h["one"] = ["two"]
|
h["one"] = ["two"]
|
||||||
@ -19,72 +16,81 @@ class TestODict(object):
|
|||||||
h["key"] = b"foo"
|
h["key"] = b"foo"
|
||||||
|
|
||||||
def test_getset_state(self):
|
def test_getset_state(self):
|
||||||
self.od.add("foo", 1)
|
od = odict.ODict()
|
||||||
self.od.add("foo", 2)
|
od.add("foo", 1)
|
||||||
self.od.add("bar", 3)
|
od.add("foo", 2)
|
||||||
state = self.od.get_state()
|
od.add("bar", 3)
|
||||||
|
state = od.get_state()
|
||||||
nd = odict.ODict.from_state(state)
|
nd = odict.ODict.from_state(state)
|
||||||
assert nd == self.od
|
assert nd == od
|
||||||
b = odict.ODict()
|
b = odict.ODict()
|
||||||
b.load_state(state)
|
b.load_state(state)
|
||||||
assert b == self.od
|
assert b == od
|
||||||
|
|
||||||
def test_in_any(self):
|
def test_in_any(self):
|
||||||
self.od["one"] = ["atwoa", "athreea"]
|
od = odict.ODict()
|
||||||
assert self.od.in_any("one", "two")
|
od["one"] = ["atwoa", "athreea"]
|
||||||
assert self.od.in_any("one", "three")
|
assert od.in_any("one", "two")
|
||||||
assert not self.od.in_any("one", "four")
|
assert od.in_any("one", "three")
|
||||||
assert not self.od.in_any("nonexistent", "foo")
|
assert not od.in_any("one", "four")
|
||||||
assert not self.od.in_any("one", "TWO")
|
assert not od.in_any("nonexistent", "foo")
|
||||||
assert self.od.in_any("one", "TWO", True)
|
assert not od.in_any("one", "TWO")
|
||||||
|
assert od.in_any("one", "TWO", True)
|
||||||
|
|
||||||
def test_iter(self):
|
def test_iter(self):
|
||||||
assert not [i for i in self.od]
|
od = odict.ODict()
|
||||||
self.od.add("foo", 1)
|
assert not [i for i in od]
|
||||||
assert [i for i in self.od]
|
od.add("foo", 1)
|
||||||
|
assert [i for i in od]
|
||||||
|
|
||||||
def test_keys(self):
|
def test_keys(self):
|
||||||
assert not self.od.keys()
|
od = odict.ODict()
|
||||||
self.od.add("foo", 1)
|
assert not od.keys()
|
||||||
assert self.od.keys() == ["foo"]
|
od.add("foo", 1)
|
||||||
self.od.add("foo", 2)
|
assert od.keys() == ["foo"]
|
||||||
assert self.od.keys() == ["foo"]
|
od.add("foo", 2)
|
||||||
self.od.add("bar", 2)
|
assert od.keys() == ["foo"]
|
||||||
assert len(self.od.keys()) == 2
|
od.add("bar", 2)
|
||||||
|
assert len(od.keys()) == 2
|
||||||
|
|
||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
self.od.add("foo", 1)
|
od = odict.ODict()
|
||||||
self.od.add("foo", 2)
|
od.add("foo", 1)
|
||||||
self.od.add("bar", 3)
|
od.add("foo", 2)
|
||||||
assert self.od == self.od.copy()
|
od.add("bar", 3)
|
||||||
assert not self.od != self.od.copy()
|
assert od == od.copy()
|
||||||
|
assert not od != od.copy()
|
||||||
|
|
||||||
def test_del(self):
|
def test_del(self):
|
||||||
self.od.add("foo", 1)
|
od = odict.ODict()
|
||||||
self.od.add("Foo", 2)
|
od.add("foo", 1)
|
||||||
self.od.add("bar", 3)
|
od.add("Foo", 2)
|
||||||
del self.od["foo"]
|
od.add("bar", 3)
|
||||||
assert len(self.od.lst) == 2
|
del od["foo"]
|
||||||
|
assert len(od.lst) == 2
|
||||||
|
|
||||||
def test_replace(self):
|
def test_replace(self):
|
||||||
self.od.add("one", "two")
|
od = odict.ODict()
|
||||||
self.od.add("two", "one")
|
od.add("one", "two")
|
||||||
assert self.od.replace("one", "vun") == 2
|
od.add("two", "one")
|
||||||
assert self.od.lst == [
|
assert od.replace("one", "vun") == 2
|
||||||
|
assert od.lst == [
|
||||||
["vun", "two"],
|
["vun", "two"],
|
||||||
["two", "vun"],
|
["two", "vun"],
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
self.od.add("one", "two")
|
od = odict.ODict()
|
||||||
assert self.od.get("one") == ["two"]
|
od.add("one", "two")
|
||||||
assert self.od.get("two") is None
|
assert od.get("one") == ["two"]
|
||||||
|
assert od.get("two") is None
|
||||||
|
|
||||||
def test_get_first(self):
|
def test_get_first(self):
|
||||||
self.od.add("one", "two")
|
od = odict.ODict()
|
||||||
self.od.add("one", "three")
|
od.add("one", "two")
|
||||||
assert self.od.get_first("one") == "two"
|
od.add("one", "three")
|
||||||
assert self.od.get_first("two") is None
|
assert od.get_first("one") == "two"
|
||||||
|
assert od.get_first("two") is None
|
||||||
|
|
||||||
def test_extend(self):
|
def test_extend(self):
|
||||||
a = odict.ODict([["a", "b"], ["c", "d"]])
|
a = odict.ODict([["a", "b"], ["c", "d"]])
|
||||||
@ -96,9 +102,6 @@ class TestODict(object):
|
|||||||
|
|
||||||
class TestODictCaseless(object):
|
class TestODictCaseless(object):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.od = odict.ODictCaseless()
|
|
||||||
|
|
||||||
def test_override(self):
|
def test_override(self):
|
||||||
o = odict.ODictCaseless()
|
o = odict.ODictCaseless()
|
||||||
o.add('T', 'application/x-www-form-urlencoded; charset=UTF-8')
|
o.add('T', 'application/x-www-form-urlencoded; charset=UTF-8')
|
||||||
@ -106,29 +109,32 @@ class TestODictCaseless(object):
|
|||||||
assert o["T"] == ["foo"]
|
assert o["T"] == ["foo"]
|
||||||
|
|
||||||
def test_case_preservation(self):
|
def test_case_preservation(self):
|
||||||
self.od["Foo"] = ["1"]
|
od = odict.ODictCaseless()
|
||||||
assert "foo" in self.od
|
od["Foo"] = ["1"]
|
||||||
assert self.od.items()[0][0] == "Foo"
|
assert "foo" in od
|
||||||
assert self.od.get("foo") == ["1"]
|
assert od.items()[0][0] == "Foo"
|
||||||
assert self.od.get("foo", [""]) == ["1"]
|
assert od.get("foo") == ["1"]
|
||||||
assert self.od.get("Foo", [""]) == ["1"]
|
assert od.get("foo", [""]) == ["1"]
|
||||||
assert self.od.get("xx", "yy") == "yy"
|
assert od.get("Foo", [""]) == ["1"]
|
||||||
|
assert od.get("xx", "yy") == "yy"
|
||||||
|
|
||||||
def test_del(self):
|
def test_del(self):
|
||||||
self.od.add("foo", 1)
|
od = odict.ODictCaseless()
|
||||||
self.od.add("Foo", 2)
|
od.add("foo", 1)
|
||||||
self.od.add("bar", 3)
|
od.add("Foo", 2)
|
||||||
del self.od["foo"]
|
od.add("bar", 3)
|
||||||
assert len(self.od) == 1
|
del od["foo"]
|
||||||
|
assert len(od) == 1
|
||||||
|
|
||||||
def test_keys(self):
|
def test_keys(self):
|
||||||
assert not self.od.keys()
|
od = odict.ODictCaseless()
|
||||||
self.od.add("foo", 1)
|
assert not od.keys()
|
||||||
assert self.od.keys() == ["foo"]
|
od.add("foo", 1)
|
||||||
self.od.add("Foo", 2)
|
assert od.keys() == ["foo"]
|
||||||
assert self.od.keys() == ["foo"]
|
od.add("Foo", 2)
|
||||||
self.od.add("bar", 2)
|
assert od.keys() == ["foo"]
|
||||||
assert len(self.od.keys()) == 2
|
od.add("bar", 2)
|
||||||
|
assert len(od.keys()) == 2
|
||||||
|
|
||||||
def test_add_order(self):
|
def test_add_order(self):
|
||||||
od = odict.ODict(
|
od = odict.ODict(
|
||||||
|
@ -26,7 +26,7 @@ class ServerTestBase(object):
|
|||||||
addr = ("localhost", 0)
|
addr = ("localhost", 0)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setupAll(cls):
|
def setup_class(cls):
|
||||||
cls.q = queue.Queue()
|
cls.q = queue.Queue()
|
||||||
s = cls.makeserver()
|
s = cls.makeserver()
|
||||||
cls.port = s.address.port
|
cls.port = s.address.port
|
||||||
@ -38,7 +38,7 @@ class ServerTestBase(object):
|
|||||||
return TServer(cls.ssl, cls.q, cls.handler, cls.addr)
|
return TServer(cls.ssl, cls.q, cls.handler, cls.addr)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def teardownAll(cls):
|
def teardown_class(cls):
|
||||||
cls.server.shutdown()
|
cls.server.shutdown()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user