summaryrefslogtreecommitdiff
path: root/reconfigure/builders/bound_tests.py
diff options
context:
space:
mode:
authorAndrew Shadura <andrew@shadura.me>2015-08-20 15:58:26 +0200
committerAndrew Shadura <andrew@shadura.me>2015-08-20 15:58:26 +0200
commitff1408420159488a106492ccd11dd234967029b6 (patch)
tree473420cee1c5229a427ec4cafead1aa6c0a26800 /reconfigure/builders/bound_tests.py
Imported Upstream version 0.1.29
Diffstat (limited to 'reconfigure/builders/bound_tests.py')
-rw-r--r--reconfigure/builders/bound_tests.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/reconfigure/builders/bound_tests.py b/reconfigure/builders/bound_tests.py
new file mode 100644
index 0000000..8c1faa6
--- /dev/null
+++ b/reconfigure/builders/bound_tests.py
@@ -0,0 +1,52 @@
+from reconfigure.items.bound import BoundData
+from reconfigure.nodes import Node, PropertyNode
+import unittest
+
+
+class BoundDataTest (unittest.TestCase):
+
+ def test_bind_property(self):
+ class TestBoundData (BoundData):
+ pass
+ TestBoundData.bind_property('prop', 'dataprop', getter=lambda x: 'd' + x, setter=lambda x: x[1:])
+
+ n = Node('name', children=[
+ PropertyNode('prop', 'value')
+ ])
+
+ d = TestBoundData(n)
+
+ self.assertEqual(d.dataprop, 'dvalue')
+ d.dataprop = 'dnew'
+ self.assertEqual(d.dataprop, 'dnew')
+ self.assertEqual(n.get('prop').value, 'new')
+
+ def test_bind_collection(self):
+ class TestBoundData (BoundData):
+ pass
+
+ class TestChildData (BoundData):
+ def template(self):
+ return Node('', children=[PropertyNode('value', None)])
+
+ TestBoundData.bind_collection('items', item_class=TestChildData, selector=lambda x: x.name != 'test')
+ TestChildData.bind_property('value', 'value')
+ n = Node('name', children=[
+ Node('1', children=[PropertyNode('value', 1)]),
+ Node('2', children=[PropertyNode('value', 2)]),
+ Node('test', children=[PropertyNode('value', 3)]),
+ Node('3', children=[PropertyNode('value', 3)]),
+ ])
+
+ d = TestBoundData(n)
+ self.assertEqual(d.items[0].value, 1)
+ self.assertEqual(len(d.items), 3)
+ c = TestChildData()
+ c.value = 4
+ d.items.append(c)
+ self.assertEqual(len(d.items), 4)
+ self.assertEqual(d.items[-1].value, 4)
+
+
+if __name__ == '__main__':
+ unittest.main()