-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtest_struct.py
More file actions
70 lines (57 loc) · 1.87 KB
/
Copy pathtest_struct.py
File metadata and controls
70 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pytest
from hpack import HeaderTuple, NeverIndexedHeaderTuple
class TestHeaderTuple:
def test_is_tuple(self):
"""
HeaderTuple objects are tuples.
"""
h = HeaderTuple('name', 'value')
assert isinstance(h, tuple)
def test_unpacks_properly(self):
"""
HeaderTuple objects unpack like tuples.
"""
h = HeaderTuple('name', 'value')
k, v = h
assert k == 'name'
assert v == 'value'
def test_header_tuples_are_indexable(self):
"""
HeaderTuple objects can be indexed.
"""
h = HeaderTuple('name', 'value')
assert h.indexable
def test_never_indexed_tuples_are_not_indexable(self):
"""
NeverIndexedHeaderTuple objects cannot be indexed.
"""
h = NeverIndexedHeaderTuple('name', 'value')
assert not h.indexable
@pytest.mark.parametrize('cls', (HeaderTuple, NeverIndexedHeaderTuple))
def test_equal_to_tuples(self, cls):
"""
HeaderTuples and NeverIndexedHeaderTuples are equal to equivalent
tuples.
"""
t1 = ('name', 'value')
t2 = cls('name', 'value')
assert t1 == t2
assert t1 is not t2
@pytest.mark.parametrize('cls', (HeaderTuple, NeverIndexedHeaderTuple))
def test_equal_to_self(self, cls):
"""
HeaderTuples and NeverIndexedHeaderTuples are always equal when
compared to the same class.
"""
t1 = cls('name', 'value')
t2 = cls('name', 'value')
assert t1 == t2
assert t1 is not t2
def test_equal_for_different_indexes(self):
"""
HeaderTuples compare equal to equivalent NeverIndexedHeaderTuples.
"""
t1 = HeaderTuple('name', 'value')
t2 = NeverIndexedHeaderTuple('name', 'value')
assert t1 == t2
assert t1 is not t2