From 292a0aa9e671748f0ad77a5e8f8f21d40314b030 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 20 Sep 2015 19:56:57 +0200 Subject: [PATCH] make tests compatible with py.test --- setup.py | 2 + test/test_odict.py | 144 +++++++++++++++++++++++---------------------- test/tservers.py | 4 +- 3 files changed, 79 insertions(+), 71 deletions(-) diff --git a/setup.py b/setup.py index 0c9fb07b5..ac0d36cfe 100644 --- a/setup.py +++ b/setup.py @@ -57,6 +57,8 @@ setup( extras_require={ 'dev': [ "mock>=1.0.1", + "pytest>=2.8.0", + "pytest-xdist>=1.13.1", "nose>=1.3.0", "nose-cov>=1.6", "coveralls>=0.4.1", diff --git a/test/test_odict.py b/test/test_odict.py index 962c0daac..881970263 100644 --- a/test/test_odict.py +++ b/test/test_odict.py @@ -3,9 +3,6 @@ from netlib import odict, tutils class TestODict(object): - def setUp(self): - self.od = odict.ODict() - def test_repr(self): h = odict.ODict() h["one"] = ["two"] @@ -19,72 +16,81 @@ class TestODict(object): h["key"] = b"foo" def test_getset_state(self): - self.od.add("foo", 1) - self.od.add("foo", 2) - self.od.add("bar", 3) - state = self.od.get_state() + od = odict.ODict() + od.add("foo", 1) + od.add("foo", 2) + od.add("bar", 3) + state = od.get_state() nd = odict.ODict.from_state(state) - assert nd == self.od + assert nd == od b = odict.ODict() b.load_state(state) - assert b == self.od + assert b == od def test_in_any(self): - self.od["one"] = ["atwoa", "athreea"] - assert self.od.in_any("one", "two") - assert self.od.in_any("one", "three") - assert not self.od.in_any("one", "four") - assert not self.od.in_any("nonexistent", "foo") - assert not self.od.in_any("one", "TWO") - assert self.od.in_any("one", "TWO", True) + od = odict.ODict() + od["one"] = ["atwoa", "athreea"] + assert od.in_any("one", "two") + assert od.in_any("one", "three") + assert not od.in_any("one", "four") + assert not od.in_any("nonexistent", "foo") + assert not od.in_any("one", "TWO") + assert od.in_any("one", "TWO", True) def test_iter(self): - assert not [i for i in self.od] - self.od.add("foo", 1) - assert [i for i in self.od] + od = odict.ODict() + assert not [i for i in od] + od.add("foo", 1) + assert [i for i in od] def test_keys(self): - assert not self.od.keys() - self.od.add("foo", 1) - assert self.od.keys() == ["foo"] - self.od.add("foo", 2) - assert self.od.keys() == ["foo"] - self.od.add("bar", 2) - assert len(self.od.keys()) == 2 + od = odict.ODict() + assert not od.keys() + od.add("foo", 1) + assert od.keys() == ["foo"] + od.add("foo", 2) + assert od.keys() == ["foo"] + od.add("bar", 2) + assert len(od.keys()) == 2 def test_copy(self): - self.od.add("foo", 1) - self.od.add("foo", 2) - self.od.add("bar", 3) - assert self.od == self.od.copy() - assert not self.od != self.od.copy() + od = odict.ODict() + od.add("foo", 1) + od.add("foo", 2) + od.add("bar", 3) + assert od == od.copy() + assert not od != od.copy() def test_del(self): - self.od.add("foo", 1) - self.od.add("Foo", 2) - self.od.add("bar", 3) - del self.od["foo"] - assert len(self.od.lst) == 2 + od = odict.ODict() + od.add("foo", 1) + od.add("Foo", 2) + od.add("bar", 3) + del od["foo"] + assert len(od.lst) == 2 def test_replace(self): - self.od.add("one", "two") - self.od.add("two", "one") - assert self.od.replace("one", "vun") == 2 - assert self.od.lst == [ + od = odict.ODict() + od.add("one", "two") + od.add("two", "one") + assert od.replace("one", "vun") == 2 + assert od.lst == [ ["vun", "two"], ["two", "vun"], ] def test_get(self): - self.od.add("one", "two") - assert self.od.get("one") == ["two"] - assert self.od.get("two") is None + od = odict.ODict() + od.add("one", "two") + assert od.get("one") == ["two"] + assert od.get("two") is None def test_get_first(self): - self.od.add("one", "two") - self.od.add("one", "three") - assert self.od.get_first("one") == "two" - assert self.od.get_first("two") is None + od = odict.ODict() + od.add("one", "two") + od.add("one", "three") + assert od.get_first("one") == "two" + assert od.get_first("two") is None def test_extend(self): a = odict.ODict([["a", "b"], ["c", "d"]]) @@ -96,9 +102,6 @@ class TestODict(object): class TestODictCaseless(object): - def setUp(self): - self.od = odict.ODictCaseless() - def test_override(self): o = odict.ODictCaseless() o.add('T', 'application/x-www-form-urlencoded; charset=UTF-8') @@ -106,29 +109,32 @@ class TestODictCaseless(object): assert o["T"] == ["foo"] def test_case_preservation(self): - self.od["Foo"] = ["1"] - assert "foo" in self.od - assert self.od.items()[0][0] == "Foo" - assert self.od.get("foo") == ["1"] - assert self.od.get("foo", [""]) == ["1"] - assert self.od.get("Foo", [""]) == ["1"] - assert self.od.get("xx", "yy") == "yy" + od = odict.ODictCaseless() + od["Foo"] = ["1"] + assert "foo" in od + assert od.items()[0][0] == "Foo" + assert od.get("foo") == ["1"] + assert od.get("foo", [""]) == ["1"] + assert od.get("Foo", [""]) == ["1"] + assert od.get("xx", "yy") == "yy" def test_del(self): - self.od.add("foo", 1) - self.od.add("Foo", 2) - self.od.add("bar", 3) - del self.od["foo"] - assert len(self.od) == 1 + od = odict.ODictCaseless() + od.add("foo", 1) + od.add("Foo", 2) + od.add("bar", 3) + del od["foo"] + assert len(od) == 1 def test_keys(self): - assert not self.od.keys() - self.od.add("foo", 1) - assert self.od.keys() == ["foo"] - self.od.add("Foo", 2) - assert self.od.keys() == ["foo"] - self.od.add("bar", 2) - assert len(self.od.keys()) == 2 + od = odict.ODictCaseless() + assert not od.keys() + od.add("foo", 1) + assert od.keys() == ["foo"] + od.add("Foo", 2) + assert od.keys() == ["foo"] + od.add("bar", 2) + assert len(od.keys()) == 2 def test_add_order(self): od = odict.ODict( diff --git a/test/tservers.py b/test/tservers.py index 1f4ce725b..c47d6a5f7 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -26,7 +26,7 @@ class ServerTestBase(object): addr = ("localhost", 0) @classmethod - def setupAll(cls): + def setup_class(cls): cls.q = queue.Queue() s = cls.makeserver() cls.port = s.address.port @@ -38,7 +38,7 @@ class ServerTestBase(object): return TServer(cls.ssl, cls.q, cls.handler, cls.addr) @classmethod - def teardownAll(cls): + def teardown_class(cls): cls.server.shutdown() @property