-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_util.py
37 lines (28 loc) · 1 KB
/
test_util.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
# test_util.py -- Unit tests for util.py
import unittest
from pprint import pprint as pp
import inspect
from dataclasses import dataclass, field, InitVar
from types import SimpleNamespace
from typing import Union, List, Tuple, Dict, Set, FrozenSet, Iterable, Any, \
NewType, Type, ClassVar, Sequence, Callable, Hashable, Collection, \
Sequence, Literal, Protocol, runtime_checkable
from util import PushAttr, asdict_with_classvars
class TestUtil(unittest.TestCase):
def test_with_pushattr(self):
o = SimpleNamespace()
o.myattr = 'FIRST'
with PushAttr(o, 'myattr'):
o.myattr = 'SECOND'
self.assertEqual(o.myattr, 'SECOND')
self.assertEqual(o.myattr, 'FIRST')
def test_asdict_with_classvars(self):
@dataclass
class Blah:
x: int
y: ClassVar[str] = 'the classvar'
blah = Blah(22)
self.assertEqual(
asdict_with_classvars(blah),
{'x': 22, 'y': 'the classvar'}
)