0.12.6 add unittest to dei_args()
This commit is contained in:
parent
e5a8c6bd61
commit
d0701599fe
5 changed files with 41 additions and 11 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 0.12.6
|
||||
|
||||
+ Added unittests to `dei_args()`
|
||||
|
||||
## 0.12.5
|
||||
|
||||
+ Optimized dependencies: `setuptools` now no more a dependency
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
31
tests/test_dei.py
Normal file
31
tests/test_dei.py
Normal 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")
|
||||
|
|
@ -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_')
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue