コード例 #1
0
    def test_add_child(self):

        trb = TreeBuilder('_', "queen")
        son = trb.create_node("Bill")
        relationship = trb.add_child(trb.queen, son)
        self.assertEqual(trb.queen, relationship.start_node)
        self.assertEqual(son, relationship.end_node)
コード例 #2
0
 def test_add_person_command(self):
     trb_mock = TreeBuilder("_")
     trb_mock.create_node = MagicMock()
     command = AddPersonCommnad(trb_mock, ["joan", "Female"])
     result = command.execute()
     self.assertEqual("PERSON_ADDED", result)
     trb_mock.create_node.assert_called_with("joan", Gender["Female"])
コード例 #3
0
 def test_add_child_command(self):
     trb_mock = TreeBuilder("k","q")
     trb_mock.add_child = MagicMock()
     command = AddChildCommnad(trb_mock, ["q", "joan", "Female"])
     result = command.execute()
     self.assertEqual("CHILD_ADDED", result)
     called_args = trb_mock.add_child.call_args_list[0]
     self.assertEqual("q", called_args[0][0].name)
     self.assertEqual("joan", called_args[0][1].name)
コード例 #4
0
    def test_couple_nodes(self):

        trb = TreeBuilder()
        relationhip = trb.king.edges[0]

        self.assertEqual(trb.king, relationhip.start_node)
        self.assertEqual(trb.queen, relationhip.end_node)
コード例 #5
0
def main():

    # init 
    builder = TreeBuilder()
    relashions = RelationshipExplorer(builder)
    manager = CommandsManager(builder, relashions)
    load_with_file("./family_tree/default_input.txt", manager)

    # act
    if len(sys.argv) == 2 :

        input_file_name =sys.argv[1]
        load_with_file(input_file_name,manager, lambda x: print(x))
コード例 #6
0
 def test_add_child_command_add_failed(self):
     trb = TreeBuilder("k","q")
     command = AddChildCommnad(trb, ["k", "joan", "Female"])
     self.assertRaises(AddChildException, command.execute)
コード例 #7
0
 def test_add_child_command_not_found(self):
     trb = TreeBuilder("k","q")
 
     command = AddChildCommnad(trb, ["not_exist", "joan", "Female"])
     self.assertRaises(PersonNotFoundException,command.execute)
コード例 #8
0
 def test_one_node(self):
     king_name = "Jonnhy"
     trb = TreeBuilder(king_name)
     self.assertEqual(king_name, trb.king.name,
                      "could not build one node tree")