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,13 @@ 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 (
86+ stream_id in filtered and not blocked
87+ ) :
9188 expected .append (stream_id )
9289 else :
9390 expected .extend (get_expected (tree [stream_id ]))
@@ -311,22 +308,22 @@ def test_priority_allows_inserting_stream_with_absent_parent(self, exclusive):
311308 p .insert_stream (stream_id = 3 , depends_on = 1 , exclusive = exclusive , weight = 32 )
312309
313310 # Iterate 10 times to prove that the parent stream starts blocked.
314- first_ten_ids = [next (p ) for _ in range (0 , 10 )]
311+ first_ten_ids = [next (p ) for _ in range (10 )]
315312 assert first_ten_ids == [3 ] * 10
316313
317314 # Unblock the parent.
318315 p .unblock (1 )
319316
320317 # Iterate 10 times, expecting only the parent.
321- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
318+ next_ten_ids = [next (p ) for _ in range (10 )]
322319 assert next_ten_ids == [1 ] * 10
323320
324321 # Insert a new stream into the tree with default priority.
325322 p .insert_stream (stream_id = 5 )
326323
327324 # Iterate 10 more times. Expect the parent, and the new stream, in
328325 # equal amounts.
329- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
326+ next_ten_ids = [next (p ) for _ in range (10 )]
330327 assert next_ten_ids == [5 , 1 ] * 5
331328
332329 @pytest .mark .parametrize ("exclusive" , [True , False ])
@@ -341,22 +338,22 @@ def test_priority_reprioritizing_stream_with_absent_parent(self, exclusive):
341338 p .reprioritize (stream_id = 3 , depends_on = 1 , exclusive = exclusive , weight = 32 )
342339
343340 # Iterate 10 times to prove that the parent stream starts blocked.
344- first_ten_ids = [next (p ) for _ in range (0 , 10 )]
341+ first_ten_ids = [next (p ) for _ in range (10 )]
345342 assert first_ten_ids == [3 ] * 10
346343
347344 # Unblock the parent.
348345 p .unblock (1 )
349346
350347 # Iterate 10 times, expecting only the parent.
351- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
348+ next_ten_ids = [next (p ) for _ in range (10 )]
352349 assert next_ten_ids == [1 ] * 10
353350
354351 # Insert a new stream into the tree with default priority.
355352 p .insert_stream (stream_id = 5 )
356353
357354 # Iterate 10 more times. Expect the parent, and the new stream, in
358355 # equal amounts.
359- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
356+ next_ten_ids = [next (p ) for _ in range (10 )]
360357 assert next_ten_ids == [5 , 1 ] * 5
361358
362359 @pytest .mark .parametrize ("count" , range (2 , 10000 , 100 ))
@@ -386,7 +383,7 @@ def test_can_insert_stream_with_exclusive_dependency_on_0(self, depends_on):
386383
387384 p .insert_stream (stream_id = 5 , depends_on = depends_on , exclusive = True )
388385
389- next_ten_ids = [next (p ) for _ in range (0 , 10 )]
386+ next_ten_ids = [next (p ) for _ in range (10 )]
390387 assert next_ten_ids == [5 ] * 10
391388
392389 @pytest .mark .parametrize ("weight" , [None , 0.5 , float ("inf" ), "priority" , object ])
0 commit comments