1- # -*- coding: utf-8 -*-
21"""
32test_priority
43~~~~~~~~~~~~~
54
65Tests for the Priority trees
76"""
87
9- import operator
108import collections
119import itertools
10+ import operator
11+ from collections .abc import Iterable
12+ from typing import Any
1213
1314import pytest
14-
1515from hypothesis import given , settings
16- from hypothesis .stateful import invariant , RuleBasedStateMachine , rule
17- from hypothesis .strategies import integers , lists , tuples , sampled_from
16+ from hypothesis .stateful import RuleBasedStateMachine , invariant , rule
17+ from hypothesis .strategies import integers , lists , sampled_from , tuples
1818
1919import priority
2020
21- from typing import Iterable , List , Dict , Any
22-
23-
2421STREAMS_AND_WEIGHTS = lists (
2522 elements = tuples (integers (min_value = 1 ), integers (min_value = 1 , max_value = 255 )),
2623 unique_by = operator .itemgetter (0 ),
@@ -59,7 +56,7 @@ def readme_tree():
5956def active_readme_streams_from_filter (
6057 filtered : Iterable [int ],
6158 blocked : bool = True ,
62- ) -> List [int ]:
59+ ) -> list [int ]:
6360 """
6461 Given a collection of filtered streams, determine which ones are active.
6562 This applies only to the readme tree at this time, though in future it
@@ -81,13 +78,11 @@ def active_readme_streams_from_filter(
8178 }
8279 filtered = set (filtered )
8380
84- def get_expected (tree : Dict [Any , Any ]) -> List [int ]:
81+ def get_expected (tree : dict [Any , Any ]) -> list [int ]:
8582 expected = []
8683
8784 for stream_id in tree :
88- if stream_id not in filtered and blocked :
89- expected .append (stream_id )
90- elif stream_id in filtered and not blocked :
85+ if (stream_id not in filtered and blocked ) or (stream_id in filtered and not blocked ):
9186 expected .append (stream_id )
9287 else :
9388 expected .extend (get_expected (tree [stream_id ]))
@@ -311,22 +306,22 @@ def test_priority_allows_inserting_stream_with_absent_parent(self, exclusive):
311306 p .insert_stream (stream_id = 3 , depends_on = 1 , exclusive = exclusive , weight = 32 )
312307
313308 # Iterate 10 times to prove that the parent stream starts blocked.
314- first_ten_ids = [next (p ) for _ in range (0 , 10 )]
309+ first_ten_ids = [next (p ) for _ in range (10 )]
315310 assert first_ten_ids == [3 ] * 10
316311
317312 # Unblock the parent.
318313 p .unblock (1 )
319314
320315 # Iterate 10 times, expecting only the parent.
321- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
316+ next_ten_ids = [next (p ) for _ in range (10 )]
322317 assert next_ten_ids == [1 ] * 10
323318
324319 # Insert a new stream into the tree with default priority.
325320 p .insert_stream (stream_id = 5 )
326321
327322 # Iterate 10 more times. Expect the parent, and the new stream, in
328323 # equal amounts.
329- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
324+ next_ten_ids = [next (p ) for _ in range (10 )]
330325 assert next_ten_ids == [5 , 1 ] * 5
331326
332327 @pytest .mark .parametrize ("exclusive" , [True , False ])
@@ -341,22 +336,22 @@ def test_priority_reprioritizing_stream_with_absent_parent(self, exclusive):
341336 p .reprioritize (stream_id = 3 , depends_on = 1 , exclusive = exclusive , weight = 32 )
342337
343338 # Iterate 10 times to prove that the parent stream starts blocked.
344- first_ten_ids = [next (p ) for _ in range (0 , 10 )]
339+ first_ten_ids = [next (p ) for _ in range (10 )]
345340 assert first_ten_ids == [3 ] * 10
346341
347342 # Unblock the parent.
348343 p .unblock (1 )
349344
350345 # Iterate 10 times, expecting only the parent.
351- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
346+ next_ten_ids = [next (p ) for _ in range (10 )]
352347 assert next_ten_ids == [1 ] * 10
353348
354349 # Insert a new stream into the tree with default priority.
355350 p .insert_stream (stream_id = 5 )
356351
357352 # Iterate 10 more times. Expect the parent, and the new stream, in
358353 # equal amounts.
359- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
354+ next_ten_ids = [next (p ) for _ in range (10 )]
360355 assert next_ten_ids == [5 , 1 ] * 5
361356
362357 @pytest .mark .parametrize ("count" , range (2 , 10000 , 100 ))
@@ -386,7 +381,7 @@ def test_can_insert_stream_with_exclusive_dependency_on_0(self, depends_on):
386381
387382 p .insert_stream (stream_id = 5 , depends_on = depends_on , exclusive = True )
388383
389- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
384+ next_ten_ids = [next (p ) for _ in range (10 )]
390385 assert next_ten_ids == [5 ] * 10
391386
392387 @pytest .mark .parametrize ("weight" , [None , 0.5 , float ("inf" ), "priority" , object ])
0 commit comments