Skip to content

Commit 424e8b1

Browse files
committed
Add tests for representations.
1 parent 9b69f1d commit 424e8b1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/test_priority.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
Tests for the Priority trees
77
"""
8+
import itertools
9+
810
from hypothesis import given
911
from hypothesis.strategies import integers, lists, tuples
1012

@@ -19,6 +21,15 @@
1921
)
2022

2123

24+
class TestStream(object):
25+
def test_stream_repr(self):
26+
"""
27+
The stream representation renders according to the README.
28+
"""
29+
s = priority.Stream(stream_id=80, weight=16)
30+
assert repr(s) == "Stream<id=80, weight=16>"
31+
32+
2233
class TestPriorityTree(object):
2334
def test_priority_tree_one_stream(self):
2435
"""
@@ -65,6 +76,30 @@ def test_priorities_stream_weights(self, stream_data):
6576
for stream_id, weight in stream_data:
6677
assert weight == priorities.stream_weight(stream_id)
6778

79+
def test_priorities_repr(self, readme_tree):
80+
"""
81+
The priorities representation renders according to the README.
82+
"""
83+
priorities = readme_tree.priorities()
84+
r = repr(priorities)
85+
86+
# Dictionaries hurt ordering, so just check all possible orderings.
87+
stream_reprs = [
88+
'Stream<id=1, weight=16>',
89+
'Stream<id=3, weight=16>',
90+
'Stream<id=7, weight=32>',
91+
]
92+
possible_orderings = [
93+
', '.join(permutation)
94+
for permutation in itertools.permutations(stream_reprs)
95+
]
96+
base_repr = "Priorities<total_weight=64, streams=[%s]>"
97+
all_reprs = [
98+
base_repr % streams for streams in possible_orderings
99+
]
100+
101+
assert any(r == representation for representation in all_reprs)
102+
68103
def test_drilling_down(self, readme_tree):
69104
"""
70105
We can drill down each layer of the tree by stream ID.

0 commit comments

Comments
 (0)