0.12.6 add unittest to dei_args()

This commit is contained in:
Yusur 2026-05-27 12:46:13 +02:00
parent e5a8c6bd61
commit d0701599fe
5 changed files with 41 additions and 11 deletions

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.12.6
+ Added unittests to `dei_args()`
## 0.12.5 ## 0.12.5
+ Optimized dependencies: `setuptools` now no more a dependency + Optimized dependencies: `setuptools` now no more a dependency

View file

@ -38,7 +38,7 @@ from .http import WantsContentType
from .color import OKLabColor, chalk, WebColor, RGBColor, LinearRGBColor, XYZColor, OKLCHColor from .color import OKLabColor, chalk, WebColor, RGBColor, LinearRGBColor, XYZColor, OKLCHColor
from .mat import Matrix from .mat import Matrix
__version__ = "0.12.5" __version__ = "0.12.6"
__all__ = ( __all__ = (
'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue', 'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue',

View file

@ -19,7 +19,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
from __future__ import annotations from __future__ import annotations
from functools import wraps from functools import wraps
from typing import Callable, TypeVar from typing import Callable, Collection, TypeVar, Any
_T = TypeVar('_T') _T = TypeVar('_T')
_U = TypeVar('_U') _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'. 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 Dear conservatives, this does not influence the ability to call the wrapped function
with the original parameter names. with the original parameter names.
""" """
def decorator(func: Callable[_T, _U]) -> Callable[_T, _U]: def decorator(func: Callable[..., _U]) -> Callable[..., _U]:
@wraps(func) @wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
for alias_name, actual_name in renames.items(): for alias_name, actual_name in renames.items():

31
tests/test_dei.py Normal file
View file

@ -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")

View file

@ -1,6 +1,4 @@
import unittest import unittest
from suou.strtools import PrefixIdentifier from suou.strtools import PrefixIdentifier
@ -27,8 +25,7 @@ class TestStrtools(unittest.TestCase):
def test_PrefixIdentifier_get_nostr(self): def test_PrefixIdentifier_get_nostr(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pi = PrefixIdentifier(1) PrefixIdentifier(1)
pi.hello
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
PrefixIdentifier([99182]) PrefixIdentifier([99182])
@ -36,5 +33,3 @@ class TestStrtools(unittest.TestCase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
PrefixIdentifier(b'alpha_') PrefixIdentifier(b'alpha_')