|
5 | 5 |
|
6 | 6 | Tests for the Priority trees |
7 | 7 | """ |
| 8 | +import itertools |
| 9 | + |
8 | 10 | from hypothesis import given |
9 | 11 | from hypothesis.strategies import integers, lists, tuples |
10 | 12 |
|
|
19 | 21 | ) |
20 | 22 |
|
21 | 23 |
|
| 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 | + |
22 | 33 | class TestPriorityTree(object): |
23 | 34 | def test_priority_tree_one_stream(self): |
24 | 35 | """ |
@@ -65,6 +76,30 @@ def test_priorities_stream_weights(self, stream_data): |
65 | 76 | for stream_id, weight in stream_data: |
66 | 77 | assert weight == priorities.stream_weight(stream_id) |
67 | 78 |
|
| 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 | + |
68 | 103 | def test_drilling_down(self, readme_tree): |
69 | 104 | """ |
70 | 105 | We can drill down each layer of the tree by stream ID. |
|
0 commit comments