From 71e0d7a1edc446ee14754c255647dfd94661fe6d Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Mon, 22 Jul 2024 23:10:23 +0200 Subject: [PATCH] feat(tests): use built-in typing New since python 3.9: https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections --- api/desecapi/tests/base.py | 5 ++--- test/e2e2/conftest.py | 14 +++++++------- test/e2e2/spec/test_api_rr.py | 4 +--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/api/desecapi/tests/base.py b/api/desecapi/tests/base.py index 678c6b60a..85c7c58ac 100644 --- a/api/desecapi/tests/base.py +++ b/api/desecapi/tests/base.py @@ -6,7 +6,6 @@ from contextlib import nullcontext from functools import partial, reduce from json import JSONDecodeError -from typing import Union, List, Dict, Set from unittest import mock from django.conf import settings @@ -422,7 +421,7 @@ def request_pdns_zone_update(cls, name=None): } def request_pdns_zone_update_assert_body( - self, name: str = None, updated_rr_sets: Union[List[RRset], Dict] = None + self, name: str = None, updated_rr_sets: list[RRset] | dict = None ): if updated_rr_sets is None: updated_rr_sets = [] @@ -1119,7 +1118,7 @@ def assertRRsetDB( subname: str, type_: str, ttl: int = None, - rr_contents: Set[str] = None, + rr_contents: set[str] = None, ): if rr_contents is not None: try: diff --git a/test/e2e2/conftest.py b/test/e2e2/conftest.py index 0ab35cb7a..134926650 100644 --- a/test/e2e2/conftest.py +++ b/test/e2e2/conftest.py @@ -8,7 +8,7 @@ import warnings from datetime import datetime from json import JSONDecodeError -from typing import Optional, Tuple, Iterable +from collections.abc import Iterable import dns import dns.name @@ -143,7 +143,7 @@ def _do_request(self, *args, **kwargs): tsprint(f'API <<< SSL could not be verified against any verification method') raise exc - def _request(self, method: str, *, path: str, data: Optional[dict] = None, headers: Optional[dict] = None, **kwargs) -> requests.Response: + def _request(self, method: str, *, path: str, data: dict | None = None, headers: dict | None = None, **kwargs) -> requests.Response: if data is not None: data = json.dumps(data) @@ -183,16 +183,16 @@ def get(self, path: str, **kwargs) -> requests.Response: def options(self, path: str, **kwargs) -> requests.Response: return self._request("OPTIONS", path=path, **kwargs) - def post(self, path: str, data: Optional[dict] = None, **kwargs) -> requests.Response: + def post(self, path: str, data: dict | None = None, **kwargs) -> requests.Response: return self._request("POST", path=path, data=data, **kwargs) - def patch(self, path: str, data: Optional[dict] = None, **kwargs) -> requests.Response: + def patch(self, path: str, data: dict | None = None, **kwargs) -> requests.Response: return self._request("PATCH", path=path, data=data, **kwargs) def delete(self, path: str, **kwargs) -> requests.Response: return self._request("DELETE", path=path, **kwargs) - def register(self, email: str, password: str) -> Tuple[requests.Response, requests.Response]: + def register(self, email: str, password: str) -> tuple[requests.Response, requests.Response]: self.email = email self.password = password captcha = self.post("/captcha/") @@ -458,7 +458,7 @@ class SecondaryNSClient(NSClient): def return_eventually(expression: callable, min_pause: float = .1, max_pause: float = 2, timeout: float = 5, - retry_on: Tuple[type] = (Exception,)): + retry_on: tuple[type] = (Exception,)): if not callable(expression): raise ValueError('Expression given not callable. Did you forget "lambda:"?') @@ -479,7 +479,7 @@ def return_eventually(expression: callable, min_pause: float = .1, max_pause: fl def assert_eventually(assertion: callable, min_pause: float = .1, max_pause: float = 2, timeout: float = 5, - retry_on: Tuple[type] = (AssertionError,), assertion_kwargs=None) -> None: + retry_on: tuple[type] = (AssertionError,), assertion_kwargs=None) -> None: def _assert(): assert assertion(**(assertion_kwargs or dict())) return_eventually(_assert, min_pause, max_pause, timeout, retry_on=retry_on) diff --git a/test/e2e2/spec/test_api_rr.py b/test/e2e2/spec/test_api_rr.py index 89bc118bb..549688677 100644 --- a/test/e2e2/spec/test_api_rr.py +++ b/test/e2e2/spec/test_api_rr.py @@ -1,11 +1,9 @@ -from typing import List, Tuple - import pytest from conftest import DeSECAPIV1Client, assert_all_ns -def generate_params(dict_value_lists_by_type: dict) -> List[Tuple[str, str]]: +def generate_params(dict_value_lists_by_type: dict) -> list[tuple[str, str]]: return [ (rr_type, value) for rr_type in dict_value_lists_by_type.keys()