-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_modello.py
40 lines (28 loc) · 1.19 KB
/
test_modello.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
"""Functional tests for Modello instances."""
from modello import BoundInstanceDummy, InstanceDummy, Modello
from sympy import simplify
def test_no_constraints():
"""A model with no constraints just has dummy attributes."""
class ExampleClass(Modello):
thing = InstanceDummy("thing")
instance = ExampleClass("Example")
assert isinstance(instance.thing, BoundInstanceDummy)
instance = ExampleClass("Example", thing=1)
expected = simplify(1)
assert isinstance(instance.thing, type(expected))
assert instance.thing == expected
def test_multiple_inheritance_expr_conflict():
"""Overrided modello attributes are replaced with new values."""
class ExampleA(Modello):
conflicted = InstanceDummy("conflicted")
a = conflicted
class ExampleB(Modello):
conflicted = InstanceDummy("conflicted")
b = conflicted
class ExampleC(ExampleA, ExampleB):
pass
instance = ExampleC("Example")
assert instance.a == instance.b # dummy is different but value is the same
assert instance.a == instance.conflicted
assert ExampleC.conflicted == ExampleB.conflicted
assert ExampleC.conflicted != ExampleA.conflicted