コード例 #1
0
ファイル: test_nexus.py プロジェクト: cverstege/kafe2
    def test_node_add_parent(self):
        par = Parameter(3, name='par')
        par_2 = Parameter(2, name='par_2')

        with self.assertRaises(TypeError):
            par.add_parent("notanode")

        # Manually adding parents is not allowed:
        with self.assertRaises(NodeException):
            par.add_parent(par_2)

        par_2.add_child(par)
        self.assertEqual(par.get_parents(), [par_2])
コード例 #2
0
ファイル: test_nexus.py プロジェクト: cverstege/kafe2
    def test_node_remove_parent(self):
        par = Parameter(3, name='par')
        parent_1 = Parameter(1, name='parent_1')
        parent_2 = Parameter(2, name='parent_2')

        parent_1.add_child(par)
        parent_2.add_child(par)
        with self.assertRaises(NodeException):
            par.remove_parent(parent_1)
        self.assertEqual(par.get_parents(), [parent_1, parent_2])
        parent_1.remove_child(par)
        self.assertEqual(par.get_parents(), [parent_2])

        with self.assertRaises(TypeError):
            par.remove_parent("notanode")
コード例 #3
0
ファイル: test_nexus.py プロジェクト: cverstege/kafe2
 def test_replace_child(self):
     par_a = Parameter(4)
     par_b = Parameter(5)
     par_c = Parameter(6)
     par_a.add_child(par_b)
     self.assertEqual(par_a.get_children(), [par_b])
     with self.assertRaises(NodeException):
         par_a.replace_child(current_child=par_c, new_child=par_b)
     par_a.replace_child(current_child=par_b, new_child=par_c)
     with self.assertRaises(NodeException):
         par_a.replace_child(current_child=par_b, new_child=par_c)
     self.assertEqual(par_a.get_children(), [par_c])
     par_a.replace_child(current_child=par_c, new_child=7)
     self.assertNotEqual(par_a.get_children(), [par_b])
     self.assertNotEqual(par_a.get_children(), [par_c])
     self.assertIs(type(par_a.get_children()[0]), Parameter)
コード例 #4
0
ファイル: test_nexus.py プロジェクト: cverstege/kafe2
    def test_node_add_child(self):
        par = Parameter(3, name='par')
        par.add_child(1)
        par.add_child(2)

        self.assertEqual([p.value for p in par.iter_children()], [1, 2])