summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-10-20 19:34:34 +0200
committerLV-426 <lv-426@taproot.org.il>2014-10-20 19:34:34 +0200
commit7095cc48865cc46ad20f28de79ba62d80e8d2153 (patch)
tree9581dff808975fddf0d13e8b45cdcae4763c94c1
parent182827506334e8ebe4e8478a49c4e0c9b0187677 (diff)
Attr_Diff:
- add_node_attr_write() - add_node_attr_rm()
-rw-r--r--src-py/model/graph.py33
-rw-r--r--src-py/test_db_controller.py2
2 files changed, 28 insertions, 7 deletions
diff --git a/src-py/model/graph.py b/src-py/model/graph.py
index 9ad4601c..52ed39b1 100644
--- a/src-py/model/graph.py
+++ b/src-py/model/graph.py
@@ -1,14 +1,35 @@
-class Attribute_Diff():
+class Attr_Diff(dict):
"""
Represents a change to note attributes, where nodes can represent
either logical nodes or logical links, and attributes can be added,
changed or removed
+
+ Example:
+ attr_diff = {n_id: {'attr_write': {'attr_0': 0,
+ 'attr_1': 'a'},
+ 'attr_remove': ['attr_2'] }
+ }
"""
- def __init__(self, id_to_attr_diff_map={}):
- """
- @param id_to_attr_diff_map
- """
- self.id_to_attr_diff_map = id_to_attr_diff_map
+ def __init__(self):
+ pass
+
+ def init_node_attr_diff(self, n_id):
+ ret = {'attr_write': {},
+ 'attr_remove': []}
+ self[n_id] = ret
+ return ret
+
+ def add_node_attr_write(self, n_id, attr_name, attr_val):
+ n_attr_diff = self.get(n_id)
+ if None == n_attr_diff:
+ n_attr_diff = self.init_node_attr_diff(n_id)
+ n_attr_diff['attr_write'][attr_name] = attr_val
+
+ def add_node_attr_rm(self, n_id, attr_name):
+ n_attr_diff = self.get(n_id)
+ if None == n_attr_diff:
+ n_attr_diff = self.init_node_attr_diff(n_id)
+ n_attr_diff['attr_remove'].append(attr_name)
class Topo_Diff():
"""
diff --git a/src-py/test_db_controller.py b/src-py/test_db_controller.py
index 502768a3..4af4cabc 100644
--- a/src-py/test_db_controller.py
+++ b/src-py/test_db_controller.py
@@ -167,7 +167,7 @@ class TestDBController(unittest.TestCase):
op.add_statement("non-valid statement #1", {})
op.add_statement("non-valid statement #2", {})
- self.db_ctl.exec_op(op)
+ self.assertRaises(Neo4JException, self.db_ctl.exec_op, op)
self.assertEqual(len(op.result_set), 2)
self.assertEqual(len(op.error_set), 1)