예제 #1
0
 def setUp(self):
     # Build test setup, diamond shape graph
     # |--ancestor
     #    |--child1
     #       |--grandchild
     #    |--child2
     #       |--grandchild
     self.competitor = Competitor('ancestor')
     self.child1 = Competitor('child1')
     self.child2 = Competitor('child2')
     self.competitor.add_child(self.child1)
     self.competitor.add_child(self.child2)
     self.grandchild = Competitor('grandchild')
     self.child1.add_child(self.grandchild)
     self.child2.add_child(self.grandchild)
예제 #2
0
class TestLatchPony(unittest.TestCase):

    def setUp(self):
        # Build test setup, diamond shape graph
        # |--ancestor
        #    |--child1
        #       |--grandchild
        #    |--child2
        #       |--grandchild
        self.competitor = Competitor('ancestor')
        self.child1 = Competitor('child1')
        self.child2 = Competitor('child2')
        self.competitor.add_child(self.child1)
        self.competitor.add_child(self.child2)
        self.grandchild = Competitor('grandchild')
        self.child1.add_child(self.grandchild)
        self.child2.add_child(self.grandchild)

    def tearDown(self):
        pass

    def test_base_item_has_id_of_correct_length(self):
        self.assertEqual(len(self.competitor.item_id), 8)

    def test_get_children_one_level(self):
        expected_children = [self.child1, self.child2]
        self.assertEqual(self.competitor.get_children(), expected_children)

    def test_get_children_two_levels(self):
        pass
        # How do we want to get back the whole graph?

    def test_get_parents(self):
        expected_parents = [self.child1, self.child2]
        self.assertEqual(self.grandchild.get_parents(), expected_parents)
        self.assertEqual(self.competitor.get_parents(), [])

    def test_add_duplicate_child_gives_error(self):
        with self.assertRaises(LatchPonyError):
            self.child1.add_child(self.grandchild)

    def test_remove_child(self):
        expected_children_remaining = [self.child2]
        self.competitor.remove_child(self.child1)
        self.assertEqual(self.competitor.get_children(),
                         expected_children_remaining)