Use inline type hints in tests/ (#10350)

This PR is tantamount to running:

    python3.8 -m com2ann -v 6 tests/

(com2ann requires python 3.8 to run)
This commit is contained in:
Jonathan de Jong 2021-07-13 12:52:58 +02:00 committed by GitHub
parent 89cfc3dd98
commit 93729719b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 62 additions and 63 deletions

View file

@ -44,7 +44,7 @@ class ChunkSeqTests(TestCase):
)
def test_empty_input(self):
parts = chunk_seq([], 5) # type: Iterable[Sequence]
parts: Iterable[Sequence] = chunk_seq([], 5)
self.assertEqual(
list(parts),
@ -56,13 +56,13 @@ class SortTopologically(TestCase):
def test_empty(self):
"Test that an empty graph works correctly"
graph = {} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {}
self.assertEqual(list(sorted_topologically([], graph)), [])
def test_handle_empty_graph(self):
"Test that a graph where a node doesn't have an entry is treated as empty"
graph = {} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {}
# For disconnected nodes the output is simply sorted.
self.assertEqual(list(sorted_topologically([1, 2], graph)), [1, 2])
@ -70,7 +70,7 @@ class SortTopologically(TestCase):
def test_disconnected(self):
"Test that a graph with no edges work"
graph = {1: [], 2: []} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {1: [], 2: []}
# For disconnected nodes the output is simply sorted.
self.assertEqual(list(sorted_topologically([1, 2], graph)), [1, 2])
@ -78,19 +78,19 @@ class SortTopologically(TestCase):
def test_linear(self):
"Test that a simple `4 -> 3 -> 2 -> 1` graph works"
graph = {1: [], 2: [1], 3: [2], 4: [3]} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {1: [], 2: [1], 3: [2], 4: [3]}
self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])
def test_subset(self):
"Test that only sorting a subset of the graph works"
graph = {1: [], 2: [1], 3: [2], 4: [3]} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {1: [], 2: [1], 3: [2], 4: [3]}
self.assertEqual(list(sorted_topologically([4, 3], graph)), [3, 4])
def test_fork(self):
"Test that a forked graph works"
graph = {1: [], 2: [1], 3: [1], 4: [2, 3]} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {1: [], 2: [1], 3: [1], 4: [2, 3]}
# Valid orderings are `[1, 3, 2, 4]` or `[1, 2, 3, 4]`, but we should
# always get the same one.
@ -98,12 +98,12 @@ class SortTopologically(TestCase):
def test_duplicates(self):
"Test that a graph with duplicate edges work"
graph = {1: [], 2: [1, 1], 3: [2, 2], 4: [3]} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {1: [], 2: [1, 1], 3: [2, 2], 4: [3]}
self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])
def test_multiple_paths(self):
"Test that a graph with multiple paths between two nodes work"
graph = {1: [], 2: [1], 3: [2], 4: [3, 2, 1]} # type: Dict[int, List[int]]
graph: Dict[int, List[int]] = {1: [], 2: [1], 3: [2], 4: [3, 2, 1]}
self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])