forked from fossilfree/numerous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_binding.py
108 lines (78 loc) · 4.31 KB
/
test_binding.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pytest
from numerous.engine.variables import VariableDescription, VariableType
from numerous.engine.system import ConnectorTwoWay, Item
@pytest.fixture
def simple_item_1():
class TestItem(Item):
def __init__(self, tag):
super().__init__(tag)
test_namespace = self.create_namespace('test_namespace')
var_desc = VariableDescription(tag='T', initial_value=0,
type=VariableType.PARAMETER)
test_namespace.create_variable_from_desc(var_desc)
var_desc = VariableDescription(tag='T1', initial_value=0,
type=VariableType.PARAMETER)
var_desc = VariableDescription(tag='P', initial_value=0,
type=VariableType.PARAMETER)
test_namespace.create_variable_from_desc(var_desc)
return TestItem('test_item')
@pytest.fixture
def simple_item_2():
class TestItem(Item):
def __init__(self, tag):
super().__init__(tag)
test_namespace = self.create_namespace('test_namespace')
var_desc = VariableDescription(tag='T', initial_value=11,
type=VariableType.PARAMETER)
test_namespace.create_variable_from_desc(var_desc)
var_desc = VariableDescription(tag='T1', initial_value=11,
type=VariableType.PARAMETER)
test_namespace.create_variable_from_desc(var_desc)
return TestItem('test_item')
@pytest.fixture
def two_way_connector_item():
class TestConductor(ConnectorTwoWay):
def __init__(self, tag):
super(TestConductor, self).__init__(tag)
self.create_namespace('test_namespace')
self.side1.test_namespace.create_variable(name='T', value=-1)
self.side1.test_namespace.create_variable(name='P')
var_desc = VariableDescription(tag='P1', initial_value=11,
type=VariableType.PARAMETER)
self.test_namespace.create_variable_from_desc(var_desc)
self.side2.test_namespace.create_variable(name='T', value=-1)
return TestConductor('test_connector')
def test_binding_multiple_add(two_way_connector_item, simple_item_1):
with pytest.raises(ValueError, match=r".*already binded to binding.*"):
two_way_connector_item.bind(side1=simple_item_1)
two_way_connector_item.bind(side1=simple_item_1)
def test_binding_1(two_way_connector_item, simple_item_1):
assert two_way_connector_item.side1.test_namespace.T.value == -1
two_way_connector_item.bind(side1=simple_item_1)
assert two_way_connector_item.side1.test_namespace.T.value == 0
simple_item_1.test_namespace.T.value = 10
assert two_way_connector_item.side1.test_namespace.T.value == 10
two_way_connector_item.side1.test_namespace.T.value = 1
assert simple_item_1.test_namespace.T.value == 1
def test_binding_2(two_way_connector_item, simple_item_1):
assert two_way_connector_item.side1.test_namespace.T.value == -1
two_way_connector_item.side1.test_namespace.P = two_way_connector_item.test_namespace.P1
assert simple_item_1.test_namespace.P.value == 0
two_way_connector_item.bind(side1=simple_item_1)
assert simple_item_1.test_namespace.P.get_value() == 11
two_way_connector_item.test_namespace.P1.value = 10
assert simple_item_1.test_namespace.P.get_value() == 10
def test_binding_3(two_way_connector_item, simple_item_1, simple_item_2):
assert two_way_connector_item.side1.test_namespace.T.value == -1
assert two_way_connector_item.side2.test_namespace.T.value == -1
two_way_connector_item.bind(side1=simple_item_1, side2=simple_item_2)
assert two_way_connector_item.side1.test_namespace.T.value == 0
simple_item_1.test_namespace.T.value = 10
assert two_way_connector_item.side1.test_namespace.T.value == 10
two_way_connector_item.side1.test_namespace.T.value = 1
assert simple_item_1.test_namespace.T.value == 1
assert two_way_connector_item.side2.test_namespace.T.value == 11
simple_item_2.test_namespace.T.value = 10
assert two_way_connector_item.side2.test_namespace.T.value == 10
two_way_connector_item.side2.test_namespace.T.value = 1
assert simple_item_2.test_namespace.T.value == 1