diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b08334..0734c65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.12.6 + ++ Added unittests to `dei_args()` + ## 0.12.5 + Optimized dependencies: `setuptools` now no more a dependency diff --git a/src/suou/__init__.py b/src/suou/__init__.py index 0d1dc2d..6a434e4 100644 --- a/src/suou/__init__.py +++ b/src/suou/__init__.py @@ -38,7 +38,7 @@ from .http import WantsContentType from .color import OKLabColor, chalk, WebColor, RGBColor, LinearRGBColor, XYZColor, OKLCHColor from .mat import Matrix -__version__ = "0.12.5" +__version__ = "0.12.6" __all__ = ( 'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue', diff --git a/src/suou/dei.py b/src/suou/dei.py index d114289..8d0f326 100644 --- a/src/suou/dei.py +++ b/src/suou/dei.py @@ -19,7 +19,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. from __future__ import annotations from functools import wraps -from typing import Callable, TypeVar +from typing import Callable, Collection, TypeVar, Any _T = TypeVar('_T') _U = TypeVar('_U') @@ -115,7 +115,7 @@ class Pronoun(int): -def dei_args(**renames): +def dei_args(**renames: dict[str, str]): """ Allow for aliases in the keyword argument names, in form alias='real_name'. @@ -125,7 +125,7 @@ def dei_args(**renames): Dear conservatives, this does not influence the ability to call the wrapped function with the original parameter names. """ - def decorator(func: Callable[_T, _U]) -> Callable[_T, _U]: + def decorator(func: Callable[..., _U]) -> Callable[..., _U]: @wraps(func) def wrapper(*args, **kwargs): for alias_name, actual_name in renames.items(): diff --git a/tests/test_dei.py b/tests/test_dei.py new file mode 100644 index 0000000..603e7f4 --- /dev/null +++ b/tests/test_dei.py @@ -0,0 +1,31 @@ + + +import unittest + +from suou import dei_args + +class TestDei(unittest.TestCase): + def setUp(self) -> None: + ... + + def tearDown(self) -> None: + ... + + def test_dei_args(self): + + def func_a(*, a: int, b: int): + """Trivial function for the purpose of the test""" + return a - b == 0 + + func_b = dei_args(c='a', d='b')(func_a) + + with self.assertRaises(TypeError): + func_a(c=1, b=2) + + self.assertTrue(func_a(a=1, b=1)) + self.assertFalse(func_b(c=1, b=2)) + self.assertFalse(func_b(a=1, d=2)) + self.assertFalse(func_b(a=1, b=2)) + + with self.assertRaises(TypeError): + func_b(c=1, b="a") \ No newline at end of file diff --git a/tests/test_strtools.py b/tests/test_strtools.py index e3ef328..ceaef12 100644 --- a/tests/test_strtools.py +++ b/tests/test_strtools.py @@ -1,6 +1,4 @@ - - import unittest from suou.strtools import PrefixIdentifier @@ -27,14 +25,11 @@ class TestStrtools(unittest.TestCase): def test_PrefixIdentifier_get_nostr(self): with self.assertRaises(TypeError): - pi = PrefixIdentifier(1) - pi.hello + PrefixIdentifier(1) with self.assertRaises(TypeError): PrefixIdentifier([99182]) with self.assertRaises(TypeError): PrefixIdentifier(b'alpha_') - - - \ No newline at end of file + \ No newline at end of file