예제 #1
0
 def setUp(self):
     self.nodes = [
         Node(pa="0", id="A"),
         Node(pa="0", id="B"),
         Node(pa="0", id="C"),
     ]
     self.ns = NodeStore()
     for node in self.nodes[0:2]:
         self.ns.add_node(node)
예제 #2
0
 def test_state(self):
     node = Node(pa="A", id="B")
     self.assertEqual(node.state, "item")
     node.complete = True
     self.assertEqual(node.state, "complete_item")
     node.children.append("CHILD")
     self.assertEqual(node.state, "complete_parent")
     node.complete = False
     self.assertEqual(node.state, "open")
     node.closed = True
     self.assertEqual(node.state, "closed")
예제 #3
0
 def _traverse_node(self, node, parent=0):
     this_node = Node(node['id'], node['nm'], parent)
     if 'ch' in node:
         for child in node['ch']:
             self._traverse_node(child, node['id'])
             this_node.children.append(child['id'])
     self.nodes[node['id']] = this_node
예제 #4
0
 def test_node_defaults(self, mocked_uuid):
     mocked_uuid.return_value = "fake_uuid"
     node = Node(pa="1")
     self.assertEqual(node.parent, "1")
     self.assertEqual(node.uuid, "fake_uuid")
     self.assertEqual(node.name, "")
     self.assertEqual(node.children, [])
     self.assertEqual(node.closed, False)
     self.assertEqual(node.complete, False)
예제 #5
0
 def test_close_open_compound_item(self):
     self.uf.nds.add_node(Node({"id": "5", "nm": "fifth", "pa": "4"}))
     self.uf.nds.get_node("4").children.append("5")
     self.uf.load_visible()
     self.assertEqual(len(self.uf.visible), 5)
     self.uf.cursor_y = 1
     self.uf.collapse_node()
     self.uf.load_visible()
     self.assertEqual(len(self.uf.visible), 2)
예제 #6
0
 def test_node_kwargs_need_parent(self):
     with self.assertRaises(KeyError):
         node = Node(
             id="id",
             nm="name",
             ch="child",
             cl="closed",
             cp="complete",
         )
예제 #7
0
 def test_node_def_needs_parent(self):
     with self.assertRaises(KeyError):
         node = Node(
             node_def={
                 "id": "id",
                 "nm": "name",
                 "ch": "child",
                 "cl": "closed",
                 "cp": "complete"
             })
예제 #8
0
 def test_open_compound_closed_item(self):
     # cursor is closed, but children are open
     self.uf.nds.add_node(Node({"id": "5", "nm": "fifth", "pa": "4"}))
     self.uf.nds.get_node("4").children.append("5")
     self.uf.nds.get_node("2").closed = True
     self.uf.load_visible()
     self.assertEqual(len(self.uf.visible), 2)
     self.uf.cursor_y = 1
     self.uf.expand_node()
     self.uf.load_visible()
     self.assertEqual(len(self.uf.visible), 5)
예제 #9
0
 def setUp(self, mocked_load_data):
     self.vm = ViewModel()
     self.vm.render = mock.MagicMock()
     mocked_load_data.assert_called_once()
     test_data = [
         {"id": "0", "nm": "root", "cl": False, "ch": ["1", "2"], "pa": None},
         {"id": "1", "nm": "henlo", "cl": False, "ch": [], "pa": "0"},
         {"id": "2", "nm": "goodbye", "cl": False, "ch": [], "pa": "0"},
     ]
     nds = NodeStore()
     for node_def in test_data:
         nds.add_node(Node(node_def))
     self.vm.m.nds = nds
     self.assertEqual(3, len(self.vm.m.nds))
     self.vm.v = View()
     self.lc = self.vm.v.lc  # purely an alias
예제 #10
0
 def test_node_def(self):
     node = Node(
         node_def={
             "pa": "parent",
             "id": "id",
             "nm": "name",
             "ch": "child",
             "cl": "closed",
             "cp": "complete"
         })
     self.assertEqual(node.parent, "parent")
     self.assertEqual(node.uuid, "id")
     self.assertEqual(node.name, "name")
     self.assertEqual(node.children, "child")
     self.assertEqual(node.closed, "closed")
     self.assertEqual(node.complete, "complete")
예제 #11
0
 def test_node_def_with_good_overrides(self):
     node = Node(
         pa="parent",
         id="id",
         nm="name",
         ch="child",
         cl="closed",
         cp="complete",
     )
     # overrides don't do anything if node_def is defined
     self.assertEqual(node.parent, "parent")
     self.assertEqual(node.uuid, "id")
     self.assertEqual(node.name, "name")
     self.assertEqual(node.children, "child")
     self.assertEqual(node.closed, "closed")
     self.assertEqual(node.complete, "complete")
예제 #12
0
 def test_digest(self):
     node = Node(
         node_def={
             "pa": "parent",
             "id": "id",
             "nm": "nm",
             "ch": ["C", "N"],
             "cl": "closed",
             "cp": "complete"
         })
     expected_digest_format = [("pa", "parent"), ("id", "id"), ("nm", "nm"),
                               ("ch", ("C", "N")), ("cl", "closed"),
                               ("cp", "complete")]
     self.assertSequenceEqual(node.digestable_format,
                              expected_digest_format)
     self.assertEqual(frozenset(node.digestable_format),
                      frozenset(expected_digest_format))
     self.assertEqual(hash(frozenset(node.digestable_format)),
                      hash(frozenset(expected_digest_format)))
     self.assertEqual(node.digest, hash(frozenset(expected_digest_format)))
예제 #13
0
 def setUp(self, mocked_load_data):
     self.uf = UserFile()
     mocked_load_data.assert_called_once()
     self.assertEqual(0, len(self.uf.nds))
     test_data = [{
         "id": "0",
         "nm": "root",
         "cl": False,
         "ch": ["1", "2"],
         "pa": None
     }, {
         "id": "1",
         "nm": "henlo",
         "cl": False,
         "ch": [],
         "pa": "0"
     }, {
         "id": "2",
         "nm": "goodbye",
         "cl": False,
         "ch": ["3", "4"],
         "pa": "0"
     }, {
         "id": "3",
         "nm": "sayonara",
         "cl": False,
         "ch": [],
         "pa": "2"
     }, {
         "id": "4",
         "nm": "nice",
         "cl": False,
         "ch": [],
         "pa": "2"
     }]
     nds = NodeStore()
     for node_def in test_data:
         nds.add_node(Node(node_def))
     self.uf.nds = nds
     self.assertEqual(5, len(self.uf.nds))
예제 #14
0
 def test_node_def_with_bad_overrides(self):
     node = Node(
         node_def={
             "pa": "parent",
             "id": "id",
             "nm": "name",
             "ch": "child",
             "cl": "closed",
             "cp": "complete"
         },
         pa="parent2",
         id="id2",
         nm="name2",
         ch="child2",
         cl="closed2",
         cp="complete2",
     )
     # overrides don't do anything if node_def is defined
     self.assertEqual(node.parent, "parent")
     self.assertEqual(node.uuid, "id")
     self.assertEqual(node.name, "name")
     self.assertEqual(node.children, "child")
     self.assertEqual(node.closed, "closed")
     self.assertEqual(node.complete, "complete")
예제 #15
0
 def test_state_open_closed(self):
     node = Node(pa="1", ch=["0"])
     self.assertEqual(node.state, "open")
     node.closed = True
     self.assertEqual(node.state, "closed")
예제 #16
0
 def test_is_root(self):
     with_parent = Node(pa=None)
     self.assertTrue(with_parent.is_root)
     without_parent = Node(pa="A")
     self.assertFalse(without_parent.is_root)
예제 #17
0
 def data_from_file_object(self, fo):
     data = json.load(fo)
     for node_def in data:
         node = Node(node_def=node_def)
         self.nds.add_node(node)
예제 #18
0
 def create_node(self, parent, **kwargs):
     node = Node(pa=parent, **kwargs)
     self.nds.add_node(node)
     return node
예제 #19
0
 def test_state_item(self):
     node = Node(pa="1")
     self.assertEqual(node.state, "item")
     node.closed = True
     self.assertEqual(node.state, "item")