From 538e5923794d87862e6b44f4ded7e3fd34435f50 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 21 Jan 2025 10:13:42 +0100 Subject: [PATCH] Cleanup tests --- tests/testextensions.py | 44 +++++++++++------------------------------ 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/tests/testextensions.py b/tests/testextensions.py index a41f5f6..f2236c8 100644 --- a/tests/testextensions.py +++ b/tests/testextensions.py @@ -1,9 +1,9 @@ -import sys +import collections.abc import pickle import typing +import warnings from contextlib import contextmanager -from textwrap import dedent -from unittest import TestCase, main, skipUnless +from unittest import TestCase, main from mypy_extensions import TypedDict, i64, i32, i16, u8 @@ -24,11 +24,6 @@ def assertNotIsSubclass(self, cls, class_or_tuple, msg=None): raise self.failureException(message) -PY36 = sys.version_info[:2] >= (3, 6) - -PY36_TESTS = """ -import warnings - with warnings.catch_warnings(): warnings.simplefilter("ignore", category=DeprecationWarning) @@ -43,10 +38,6 @@ class LabelPoint2D(Point2D, Label): ... class Options(TypedDict, total=False): log_level: int log_path: str -""" - -if PY36: - exec(PY36_TESTS) class TypedDictTests(BaseTestCase): @@ -62,9 +53,7 @@ def test_basics_iterable_syntax(self): Emp = TypedDict('Emp', {'name': str, 'id': int}) self.assertIsSubclass(Emp, dict) self.assertIsSubclass(Emp, typing.MutableMapping) - if sys.version_info[0] >= 3: - import collections.abc - self.assertNotIsSubclass(Emp, collections.abc.Sequence) + self.assertNotIsSubclass(Emp, collections.abc.Sequence) jim = Emp(name='Jim', id=1) self.assertIs(type(jim), dict) self.assertEqual(jim['name'], 'Jim') @@ -80,9 +69,7 @@ def test_basics_keywords_syntax(self): Emp = TypedDict('Emp', name=str, id=int) self.assertIsSubclass(Emp, dict) self.assertIsSubclass(Emp, typing.MutableMapping) - if sys.version_info[0] >= 3: - import collections.abc - self.assertNotIsSubclass(Emp, collections.abc.Sequence) + self.assertNotIsSubclass(Emp, collections.abc.Sequence) jim = Emp(name='Jim', id=1) # type: ignore # mypy doesn't support keyword syntax yet self.assertIs(type(jim), dict) self.assertEqual(jim['name'], 'Jim') @@ -111,7 +98,6 @@ def test_typeddict_errors(self): with self.assertRaises(TypeError): TypedDict('Hi', [('x', int)], y=int) - @skipUnless(PY36, 'Python 3.6 required') def test_py36_class_syntax_usage(self): self.assertEqual(LabelPoint2D.__name__, 'LabelPoint2D') # noqa self.assertEqual(LabelPoint2D.__module__, __name__) # noqa @@ -125,15 +111,10 @@ def test_py36_class_syntax_usage(self): other = LabelPoint2D(x=0, y=1, label='hi') # noqa self.assertEqual(other['label'], 'hi') - if PY36: - exec(dedent( - """ - def test_py36_class_usage_emits_deprecations(self): - with self.assert_typeddict_deprecated(): - class Foo(TypedDict): - bar: int - """ - )) + def test_py36_class_usage_emits_deprecations(self): + with self.assert_typeddict_deprecated(): + class Foo(TypedDict): + bar: int def test_pickle(self): global EmpD # pickle wants to reference the class by name @@ -163,10 +144,9 @@ def test_total(self): self.assertEqual(D(x=1), {'x': 1}) self.assertEqual(D.__total__, False) - if PY36: - self.assertEqual(Options(), {}) # noqa - self.assertEqual(Options(log_level=2), {'log_level': 2}) # noqa - self.assertEqual(Options.__total__, False) # noqa + self.assertEqual(Options(), {}) # noqa + self.assertEqual(Options(log_level=2), {'log_level': 2}) # noqa + self.assertEqual(Options.__total__, False) # noqa native_int_types = [i64, i32, i16, u8]