def test_dependency_instanciation(self): """Test instanciation of a dependency.""" service = BaseEntity("PARENT") service = BaseEntity("CHILD") self.assertRaises(AssertionError, Dependency, None) self.assertRaises(AssertionError, Dependency, service, "TEST") self.assertTrue(Dependency(service)) self.assertTrue(Dependency(service, CHECK)) self.assertTrue(Dependency(service, CHECK, True))
def test_remove_dep(self): """Test method remove_dep.""" ent = BaseEntity('foo') ent_dep = BaseEntity('child') ent.children['child'] = Dependency(ent_dep) ent_dep.parents['foo'] = Dependency(ent) ent.remove_dep('child', parent=False) self.assertTrue('child' not in ent.children) self.assertTrue('foo' not in ent.parents) self.assertRaises(AssertionError, ent.remove_dep, None)
def test_is_strong_dependency(self): """Test the behaviour of is_strong method.""" dep_a = Dependency(BaseEntity("Base"), CHECK) dep_b = Dependency(BaseEntity("Base"), REQUIRE) dep_c = Dependency(BaseEntity("Base"), REQUIRE_WEAK) self.assertTrue(dep_a.is_strong()) self.assertTrue(dep_b.is_strong()) self.assertFalse(dep_c.is_strong())
def test_graph_dep_type(self): """Test the DOT output of a dependency type""" ent = BaseEntity("ENTITY") dep_c = Dependency(BaseEntity("Base"), CHECK) dep_r = Dependency(BaseEntity("Base"), REQUIRE) dep_rw = Dependency(BaseEntity("Base"), REQUIRE_WEAK) self.assertEqual(dep_c.graph(ent), '"ENTITY" -> "Base";\n') self.assertEqual(dep_r.graph(ent), '"ENTITY" -> "Base";\n') self.assertEqual(dep_rw.graph(ent), '"ENTITY" -> "Base" [style=dashed];\n')
def test_has_parent_dep(self): """Test method has_parent_dep""" ent = BaseEntity('foo') ent_dep = BaseEntity('parent') ent.parents['parent'] = Dependency(ent_dep) self.assertTrue(ent.has_parent_dep('parent')) del ent.parents['parent'] self.assertFalse(ent.has_parent_dep('parent'))
def test_has_child_dep(self): """Test method has_child_dep""" ent = BaseEntity('foo') ent_dep = BaseEntity('child') ent.children['child'] = Dependency(ent_dep) self.assertTrue(ent.has_child_dep('child')) del ent.children['child'] self.assertFalse(ent.has_child_dep('child'))
def test_graph(self): """Test the DOT output of a dependency""" p_service = BaseEntity("PARENT") c_service = BaseEntity("CHILD") dep = Dependency(c_service, REQUIRE) #self.assertEqual(dep.graph(p_service), '"CHILD" -> "PARENT";\n') self.assertEqual(dep.graph(p_service), '"PARENT" -> "CHILD";\n') p_group = ServiceGroup('P_Group') c_group = ServiceGroup('C_Group') p_dep = Dependency(p_group) c_dep = Dependency(c_group) self.assertEqual( c_dep.graph(p_group), '"P_Group.__hook" -> "C_Group.__hook" ' '[ltail="cluster_P_Group",lhead="cluster_C_Group"];\n') self.assertEqual( c_dep.graph(p_service), '"PARENT" -> "C_Group.__hook" ' '[lhead="cluster_C_Group"];\n') self.assertEqual( dep.graph(p_group), '"P_Group.__hook" -> "CHILD" ' '[ltail="cluster_P_Group"];\n')
def test_graph(self): """Test the DOT output of a dependency""" p_service = BaseEntity("PARENT") c_service = BaseEntity("CHILD") dep = Dependency(c_service, REQUIRE) #self.assertEqual(dep.graph(p_service), '"CHILD" -> "PARENT";\n') self.assertEqual(dep.graph(p_service), '"PARENT" -> "CHILD";\n') p_group = ServiceGroup('P_Group') c_group = ServiceGroup('C_Group') p_dep = Dependency(p_group) c_dep = Dependency(c_group) self.assertEqual(c_dep.graph(p_group), '"P_Group.__hook" -> "C_Group.__hook" ' '[ltail="cluster_P_Group",lhead="cluster_C_Group"];\n') self.assertEqual(c_dep.graph(p_service), '"PARENT" -> "C_Group.__hook" ' '[lhead="cluster_C_Group"];\n') self.assertEqual(dep.graph(p_group), '"P_Group.__hook" -> "CHILD" ' '[ltail="cluster_P_Group"];\n')
def test_is_internal(self): """Test the behaviour of the method is internal""" dep = Dependency(target=BaseEntity('Group'), intr=True) self.assertTrue(dep.is_internal()) dep = Dependency(target=BaseEntity('Group'), intr=False) self.assertFalse(dep.is_internal())