def test_default_link_prefix(self): """ Tests that the link function adds the default prefixes when missing :return: """ simple = self._build_simple() (simple .map("company", "Organization.name") .map("ceo", "Person.name") .map("city", DataNode(ClassNode("City", prefix=simple.default_namespace), "name")) .map("state", DataNode(ClassNode("State", prefix=simple.default_namespace), "name")) .link("City", "isPartOf", "State")) # the last link should use default namespace, if not, there will be an # ambiguity error... prefixes = [z.prefix for z in simple.data_nodes] self.assertEqual(prefixes, [simple.default_namespace for _ in prefixes]) prefixes = [z.prefix for z in simple.class_nodes] self.assertEqual(prefixes, [simple.default_namespace for _ in prefixes]) self.assertEqual(len(simple.class_nodes), 4) self.assertEqual(len(simple.data_nodes), 4) self.assertEqual(len(simple.data_links), 4) self.assertEqual(len(simple.object_links), 1)
def test_map_multi_instance_links(self): """ Tests the map function with multiple instances in the links :return: """ simple = self._build_simple() (simple .map(Column("company"), DataNode(ClassNode("City", 0), "name")) .map(Column("ceo"), DataNode(ClassNode("City", 1), "name")) .map(Column("city"), DataNode(ClassNode("City", 2), "name")) .map(Column("state"), DataNode(ClassNode("City", 3), "name")) .link(ClassNode("City", 0), "nearby", ClassNode("City", 1)) .link(ClassNode("City", 1), "nearby", ClassNode("City", 2)) .link(ClassNode("City", 2), "nearby", ClassNode("City", 3))) self.assertEqual(len(simple.class_nodes), 4) self.assertEqual(len(simple.data_nodes), 4) self.assertEqual(len(simple.data_links), 4) self.assertEqual(len(simple.object_links), 3)
def test_map_multi_data_prop(self): """ Multiple data properties should be allowed on a single class if index is specified """ simple = self._build_simple() # should be ok. (simple .map("company", DataNode(ClassNode("Place"), "name", 0)) .map("ceo", DataNode(ClassNode("Place"), "name", 1)) .map("city", DataNode(ClassNode("Place"), "name", 2)) .map("state", DataNode(ClassNode("Place"), "name", 3))) self.assertEqual(len(simple.class_nodes), 1) self.assertEqual(len(simple.data_nodes), 4) self.assertEqual(len(simple.data_links), 4) self.assertEqual(len(simple.object_links), 0)
def test_map_full(self): """ Tests the map function for SSD mapping with full map :return: """ simple = self._build_simple() (simple .map(Column("company"), DataNode(ClassNode("Organization"), "name")) .map(Column("ceo"), DataNode(ClassNode("Person"), "name")) .map(Column("city"), DataNode(ClassNode("City"), "name")) .map(Column("state"), DataNode(ClassNode("State"), "name"))) self.assertEqual(len(simple.class_nodes), 4) self.assertEqual(len(simple.data_nodes), 4) self.assertEqual(len(simple.data_links), 4) self.assertEqual(len(simple.object_links), 0)
def test_map_simple(self): """ Tests the map function for SSD mapping with one map :return: """ simple = self._build_simple() simple.map(Column("ceo"), DataNode(ClassNode("Person"), "name")) self.assertEqual(len(simple.class_nodes), 1) self.assertEqual(len(simple.data_nodes), 1) self.assertEqual(len(simple.data_links), 1) self.assertEqual(len(simple.object_links), 0)
def test_remove(self): """ Tests the removal function when removing data nodes and columns :return: """ simple = self._build_simple() (simple .map("company", "Organization.name") .map("ceo", "Person.name") .map("city", "City.name") .map("state", "State.name") .remove(DataNode(ClassNode("Person"), "name"))) self.assertEqual(len(simple.class_nodes), 3) self.assertEqual(len(simple.data_nodes), 3) self.assertEqual(len(simple.data_links), 3) self.assertEqual(len(simple.object_links), 0)