Exemplo n.º 1
0
 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})
Exemplo n.º 2
0
 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
     })
Exemplo n.º 3
0
 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
     })
Exemplo n.º 4
0
 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
                                          })