-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathbase.py
More file actions
43 lines (32 loc) · 1.57 KB
/
Copy pathbase.py
File metadata and controls
43 lines (32 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from typing import Generic, TypeVar
from nameparser import HumanName
T = TypeVar('T')
class HumanNameTestBase(Generic[T]):
"""Shared assert helpers for the parsing tests.
Formerly subclassed unittest.TestCase. It is now a plain class so pytest can
apply the parametrized dual-run fixture in conftest.py — parametrized
fixtures do not apply to unittest.TestCase subclasses. The assert* methods
are thin shims so existing test bodies move over unchanged.
"""
def m(self, actual: T, expected: T, hn: HumanName) -> None:
"""assertEqual with a better message and awareness of hn.C.empty_attribute_default"""
expected_ = expected or hn.C.empty_attribute_default
try:
assert actual == expected_, "'%s' != '%s' for '%s'\n%r" % (
actual,
expected,
hn.original,
hn,
)
except UnicodeDecodeError:
assert actual == expected_
def assertEqual(self, first: object, second: object, msg: object = None) -> None:
assert first == second, msg
def assertTrue(self, expr: object, msg: object = None) -> None:
assert expr, msg
def assertFalse(self, expr: object, msg: object = None) -> None:
assert not expr, msg
def assertIn(self, member: object, container: object, msg: object = None) -> None:
assert member in container, msg # type: ignore[operator]
def assertNotIn(self, member: object, container: object, msg: object = None) -> None:
assert member not in container, msg # type: ignore[operator]