-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
44 lines (31 loc) · 1.47 KB
/
test.py
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
44
from pathlib import Path
import unittest
from undataclass import undataclass
class TestUndataclass(unittest.TestCase):
maxDiff = 10_000
def validate(self, module_name):
tests = Path(__file__).parent / "test_files"
filename = f"{module_name}.py"
before = Path(tests / "before" / filename).read_text()
after = Path(tests / "after" / filename).read_text()
self.assertEqual(undataclass(before) + "\n", after)
def test_from_import_no_args_no_fields_or_defaults(self):
"""Tests no-args dataclass, docstring, and no defaults."""
self.validate("simple")
def test_slots_and_frozen_args_with_default_and_factory(self):
"""Tests slots, frozen, order, default value, & default_factory."""
self.validate("frozen_and_slots")
def test_post_init(self):
"""Tests dataclasses.dataclass, __post_init__ & manual __slots__."""
self.validate("post_init")
def test_kw_only_initvar_and_match_args(self):
"""Tests KW_ONLY pseudo-field, InitVar, and match_args."""
self.validate("kw_only_and_initvar")
def test_inheritance_and_more_default_factories(self):
"""Tests dataclass inheritance and lambda factories."""
self.validate("inheritance")
def test_with_functions_and_regular_class(self):
"""Tests non-dataclass and also regular methods."""
self.validate("with_functions_and_regular_class")
if __name__ == "__main__":
unittest.main(verbosity=2)