From d8c214b1d195ffc1b50ac10c36ac18a681c5e092 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 4 Oct 2023 09:47:07 +1300 Subject: [PATCH] Upgrade typing for tests (via pyupgrade) --- tests/test_index.py | 14 +++++++------- tests/test_tpr.py | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/test_index.py b/tests/test_index.py index 6590b3e9..71dbb766 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -4,7 +4,7 @@ import pickle import tempfile import unittest -from typing import Dict, Iterator, Tuple +from typing import Iterator import numpy as np import pytest @@ -23,7 +23,7 @@ def setUp(self) -> None: def boxes15_stream( self, interleaved: bool = True - ) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]: + ) -> Iterator[tuple[int, tuple[float, float, float, float], int]]: boxes15 = np.genfromtxt("boxes_15x15.data") for i, (minx, miny, maxx, maxy) in enumerate(boxes15): if interleaved: @@ -394,7 +394,7 @@ def setUp(self) -> None: def boxes15_stream( self, interleaved: bool = True - ) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]: + ) -> Iterator[tuple[int, tuple[float, float, float, float], int]]: for i, (minx, miny, maxx, maxy) in enumerate(self.boxes15): if interleaved: yield (i, (minx, miny, maxx, maxy), 42) @@ -456,7 +456,7 @@ def test_interleaving(self) -> None: def data_gen( interleaved: bool = True, - ) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]: + ) -> Iterator[tuple[int, tuple[float, float, float, float], int]]: for i, (minx, miny, maxx, maxy) in enumerate(self.boxes15): if interleaved: yield (i, (minx, miny, maxx, maxy), 42) @@ -590,7 +590,7 @@ def data_gen( # go through the traversal and see if everything is close assert all( - all(np.allclose(a, b) for a, b in zip(L, E)) + all(np.allclose(a, b) for a, b in zip(L, E)) # type: ignore for L, E in zip(leaves, expected) ) @@ -724,7 +724,7 @@ class TestException(Exception): pass def create_index() -> index.Index: - def gen() -> Iterator[Tuple[int, Tuple[int, int, int, int], None]]: + def gen() -> Iterator[tuple[int, tuple[int, int, int, int], None]]: # insert at least 6 or so before the exception for i in range(10): yield (i, (1, 2, 3, 4), None) @@ -767,7 +767,7 @@ def destroy(self, returnError): def clear(self) -> None: """Clear all our data""" - self.dict: Dict = {} + self.dict: dict = {} def loadByteArray(self, page, returnError): """Returns the data for page or returns an error""" diff --git a/tests/test_tpr.py b/tests/test_tpr.py index a93d54f1..b9c0bbc2 100644 --- a/tests/test_tpr.py +++ b/tests/test_tpr.py @@ -4,7 +4,7 @@ import unittest from collections import defaultdict, namedtuple from math import ceil -from typing import Any, Iterator, Optional, Tuple, Union +from typing import Any, Iterator import numpy as np @@ -25,15 +25,15 @@ def getX(self, t: float) -> float: def getY(self, t: float) -> float: return self.y + self.y_vel * (t - self.time) - def getXY(self, t: float) -> Tuple[float, float]: + def getXY(self, t: float) -> tuple[float, float]: return self.getX(t), self.getY(t) def get_coordinates( - self, t_now: Optional[float] = None - ) -> Tuple[ - Tuple[float, float, float, float], - Tuple[float, float, float, float], - Union[float, Tuple[float, float]], + self, t_now: float | None = None + ) -> tuple[ + tuple[float, float, float, float], + tuple[float, float, float, float], + float | tuple[float, float], ]: return ( (self.x, self.y, self.x, self.y), @@ -49,10 +49,10 @@ class QueryCartesian( def get_coordinates( self, - ) -> Tuple[ - Tuple[float, float, float, float], - Tuple[float, float, float, float], - Tuple[float, float], + ) -> tuple[ + tuple[float, float, float, float], + tuple[float, float, float, float], + tuple[float, float], ]: return ( (self.x - self.dx, self.y - self.dy, self.x + self.dx, self.y + self.dy), @@ -78,9 +78,9 @@ def data_generator( min_y: int = 0, max_x: int = 1, max_y: int = 1, -) -> Iterator[Tuple[str, int, Any]]: +) -> Iterator[tuple[str, int, Any]]: def create_object( - id_: float, time: float, x: Optional[float] = None, y: Optional[float] = None + id_: float, time: float, x: float | None = None, y: float | None = None ) -> Cartesian: # Create object with random or defined x, y and random velocity if x is None: