-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathtest_forward_ref.py
40 lines (27 loc) · 943 Bytes
/
test_forward_ref.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
from dataclasses import dataclass
from simple_parsing import field
from .testutils import TestSetup
@dataclass
class Foo(TestSetup):
a: int = 123
b: str = "fooobar"
c: tuple[int, float] = (123, 4.56)
d: list[bool] = field(default_factory=list)
@dataclass
class Bar(TestSetup):
barry: Foo = field(default_factory=Foo)
joe: "Foo" = field(default_factory=lambda: Foo(b="rrrrr"))
z: "float" = 123.456
some_list: "list[float]" = field(default_factory=[1.0, 2.0].copy)
def test_forward_ref():
foo = Foo.setup()
assert foo == Foo()
foo = Foo.setup("--a 2 --b heyo --c 1 7.89")
assert foo == Foo(a=2, b="heyo", c=(1, 7.89))
def test_forward_ref_nested():
bar = Bar.setup()
assert bar == Bar()
assert bar.barry == Foo()
bar = Bar.setup("--barry.a 2 --barry.b heyo --barry.c 1 7.89")
assert bar.barry == Foo(a=2, b="heyo", c=(1, 7.89))
assert isinstance(bar.joe, Foo)