-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_bindings_tests.py
71 lines (60 loc) · 1.82 KB
/
data_bindings_tests.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
import unittest
import data_bindings as DB
class Thing:
def __init__(self, value):
self.set(value)
def set(self, value):
self.value = value
def get(self):
return self.value
class FacetedThing:
def __init__(self, x, y):
self.x = x
self.y = y
class TestDataBindings(unittest.TestCase):
def test_push1(self):
db = DB.DataBindings()
src = Thing(23)
dest = Thing(42)
db.add_binding(src, dest)
self.assertEqual(src.get(), 23)
self.assertEqual(dest.get(), 42)
db.push()
self.assertEqual(src.get(), 23)
self.assertEqual(dest.get(), 23)
def test_pull1(self):
db = DB.DataBindings()
src = Thing(23)
dest = Thing(42)
db.add_binding(src, dest)
self.assertEqual(src.get(), 23)
self.assertEqual(dest.get(), 42)
db.pull()
self.assertEqual(src.get(), 42)
self.assertEqual(dest.get(), 42)
def test_push_facet(self):
v = FacetedThing(23, 27)
db = DB.DataBindings()
src = DB.Facet(v, 'x')
# src = DB.(lambda: v, lambda x: v := x)
dest = Thing(42)
db.add_binding(src, dest)
self.assertEqual(src.get(), 23)
self.assertEqual(dest.get(), 42)
db.push()
self.assertEqual(v.x, 23)
self.assertEqual(dest.get(), 23)
def test_pull_facet(self):
v = FacetedThing(23, 27)
db = DB.DataBindings()
src = DB.Facet(v, 'x')
# src = DB.(lambda: v, lambda x: v := x)
dest = Thing(42)
db.add_binding(src, dest)
self.assertEqual(src.get(), 23)
self.assertEqual(dest.get(), 42)
db.pull()
self.assertEqual(v.x, 42)
self.assertEqual(dest.get(), 42)
if __name__ == '__main__':
unittest.main()