summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJess Shapiro <jess@x86.wtf>2021-03-08 18:16:44 -0800
committerGitHub <noreply@github.com>2021-03-08 20:16:44 -0600
commit6d799ce26a6a565c1921a930e1dbd41de1f45f62 (patch)
treef43fa4f92f48a29fc713d511c75c81fea5e52af3 /test
parent3a46093f89d14584b8437c0844c05579151acfbf (diff)
downloadurllib3-6d799ce26a6a565c1921a930e1dbd41de1f45f62.tar.gz
Add type hints to collections and exceptions modules
Diffstat (limited to 'test')
-rw-r--r--test/test_collections.py51
1 files changed, 41 insertions, 10 deletions
diff --git a/test/test_collections.py b/test/test_collections.py
index 6f6e7b19..7cc1b868 100644
--- a/test/test_collections.py
+++ b/test/test_collections.py
@@ -35,7 +35,7 @@ class TestLRUContainer:
d[5] = "5"
# Check state
- assert list(d.keys()) == [2, 3, 4, 0, 5]
+ assert list(d._container.keys()) == [2, 3, 4, 0, 5]
def test_same_key(self):
d = Container(5)
@@ -43,7 +43,7 @@ class TestLRUContainer:
for i in range(10):
d["foo"] = i
- assert list(d.keys()) == ["foo"]
+ assert list(d._container.keys()) == ["foo"]
assert len(d) == 1
def test_access_ordering(self):
@@ -53,13 +53,13 @@ class TestLRUContainer:
d[i] = True
# Keys should be ordered by access time
- assert list(d.keys()) == [5, 6, 7, 8, 9]
+ assert list(d._container.keys()) == [5, 6, 7, 8, 9]
new_order = [7, 8, 6, 9, 5]
for k in new_order:
d[k]
- assert list(d.keys()) == new_order
+ assert list(d._container.keys()) == new_order
def test_delete(self):
d = Container(5)
@@ -103,11 +103,11 @@ class TestLRUContainer:
d = Container(5, dispose_func=dispose_func)
for i in range(5):
d[i] = i
- assert list(d.keys()) == list(range(5))
+ assert list(d._container.keys()) == list(range(5))
assert evicted_items == [] # Nothing disposed
d[5] = 5
- assert list(d.keys()) == list(range(1, 6))
+ assert list(d._container.keys()) == list(range(1, 6))
assert evicted_items == [0]
del d[1]
@@ -272,15 +272,19 @@ class TestHTTPHeaderDict:
def test_equal(self, d):
b = HTTPHeaderDict(cookie="foo, bar")
c = NonMappingHeaderContainer(cookie="foo, bar")
+ e = [("cookie", "foo, bar")]
assert d == b
assert d == c
+ assert d == e
assert d != 2
def test_not_equal(self, d):
b = HTTPHeaderDict(cookie="foo, bar")
c = NonMappingHeaderContainer(cookie="foo, bar")
+ e = [("cookie", "foo, bar")]
assert not (d != b)
assert not (d != c)
+ assert not (d != e)
assert d != 2
def test_pop(self, d):
@@ -313,10 +317,16 @@ class TestHTTPHeaderDict:
def test_items(self, d):
items = d.items()
assert len(items) == 2
- assert items[0][0] == "Cookie"
- assert items[0][1] == "foo"
- assert items[1][0] == "Cookie"
- assert items[1][1] == "bar"
+ assert list(items) == [
+ ("Cookie", "foo"),
+ ("Cookie", "bar"),
+ ]
+ assert ("Cookie", "foo") in items
+ assert ("Cookie", "bar") in items
+ assert ("X-Some-Header", "foo") not in items
+ assert ("Cookie", "not_present") not in items
+ assert ("Cookie", 1) not in items
+ assert "Cookie" not in items
def test_dict_conversion(self, d):
# Also tested in connectionpool, needs to preserve case
@@ -340,3 +350,24 @@ class TestHTTPHeaderDict:
del d[3]
with pytest.raises(Exception):
HTTPHeaderDict({3: 3})
+
+ def test_dunder_contains(self, d):
+ """
+ Test:
+
+ HTTPHeaderDict.__contains__ returns True
+ - for matched string objects
+ - for case-similar string objects
+ HTTPHeaderDict.__contains__ returns False
+ - for non-similar strings
+ - for non-strings, even if they are keys
+ in the underlying datastructure
+ """
+ assert "cookie" in d
+ assert "CoOkIe" in d
+ assert "Not a cookie" not in d
+
+ marker = object()
+ d._container[marker] = ["some", "strings"]
+ assert marker not in d
+ assert marker in d._container