def test_filter(self): """Test the filter method.""" registry = Cuds._session._registry registry.reset() c, p1, p2, p3, n1, n2, s1 = get_test_city() found = registry.filter( lambda x: hasattr(x, "name") and x.name == "Freiburg") self.assertEqual(found, {c.uid: c}) found = registry.filter(lambda x: x.uid == n1.uid) self.assertEqual(found, {n1.uid: n1}) found = registry.filter(lambda x: city.isPartOf in x._neighbors) self.assertEqual(found, {n1.uid: n1, n2.uid: n2, s1.uid: s1})
def test_filter_by_attribute(self): """Test filter_by_attribute method.""" registry = Cuds._session._registry registry.reset() c, p1, p2, p3, n1, n2, s1 = get_test_city() self.assertEqual(registry.filter_by_attribute("name", "Freiburg"), {c.uid: c}) self.assertEqual(registry.filter_by_attribute("age", 25), { p1.uid: p1, p2.uid: p2, p3.uid: p3 })
def test_filter_by_oclass(self): """Test filtering by ontology class.""" registry = Cuds._session._registry registry.reset() c, p1, p2, p3, n1, n2, s1 = get_test_city() self.assertEqual(registry.filter_by_oclass(city.City), {c.uid: c}) self.assertEqual(registry.filter_by_oclass(city.Citizen), { p1.uid: p1, p2.uid: p2, p3.uid: p3 }) self.assertEqual(registry.filter_by_oclass(city.Neighborhood), { n1.uid: n1, n2.uid: n2 })
def test_filter_by_relationship(self): """Test filter_by_relationships.""" registry = Cuds._session._registry registry.reset() c, p1, p2, p3, n1, n2, s1 = get_test_city() self.maxDiff = 2000 self.assertEqual( registry.filter_by_relationships(city.INVERSE_OF_hasInhabitant), { p1.uid: p1, p2.uid: p2, p3.uid: p3 }) self.assertEqual( registry.filter_by_relationships(city.isPartOf, consider_subrelationships=True), { p3.uid: p3, n1.uid: n1, n2.uid: n2, s1.uid: s1 })