Пример #1
0
 def on_model3(model):
     cmodel = cclingo.Model(model=model)
     with self.assertRaises(ValueError) as ctx:
         fb = cmodel.facts(atoms=True)
Пример #2
0
 def on_model(model):
     cmodel = cclingo.Model(model=model)
     self.assertTrue(cmodel.contains(af1))
     self.assertTrue(model.contains(af1.raw))
Пример #3
0
 def on_model2(model):
     cmodel = cclingo.Model(model=model, unifier=[])
     fb = cmodel.facts(atoms=True)
     self.assertEqual(len(fb.facts()), 0)
Пример #4
0
    def test_control_and_model_wrapper(self):

        # Test a control wrapper of a wrapper
        ctrl0 = oclingo.Control()
        ctrl1 = cclingo.Control(control_=ctrl0)
        ctrl2 = cclingo.Control(control_=ctrl1)
        ctrl2.ground([("base", [])])
        with ctrl2.solve(yield_=True) as sh:
            tmp = [m.facts(unifier=[], atoms=True) for m in sh]
            self.assertEqual(len(tmp), 1)
            self.assertEqual(len(tmp[0]), 0)

        # Test a model wrapper
        ctrl = oclingo.Control()
        ctrl.ground([("base", [])])
        with ctrl.solve(yield_=True) as sh:
            for n, m_ in enumerate(sh):
                self.assertEqual(n, 0)
                m = cclingo.Model(model=m_, unifier=[])
                self.assertEqual(len(m.facts()), 0)

        # Test wrapping a bad object - missing attributes and functions

        # Missing ground function
        with self.assertRaises(AttributeError) as ctx:

            class Bad(object):
                def solve(self):
                    pass

            bad = Bad()
            ctrl = cclingo.Control(control_=bad)
        check_errmsg("'Bad' object has no attribute 'ground'", ctx)

        # Missing solve function
        with self.assertRaises(AttributeError) as ctx:

            class Bad(object):
                def ground(self):
                    pass

            bad = Bad()
            ctrl = cclingo.Control(control_=bad)
        check_errmsg("'Bad' object has no attribute 'solve'", ctx)

        # Ground is an attribute but not a function
        with self.assertRaises(AttributeError) as ctx:

            class Bad(object):
                def __init__(self):
                    self.ground = 4

                def solve(self):
                    pass

            bad = Bad()
            ctrl = cclingo.Control(control_=bad)
        check_errmsg(("Wrapped object of type '{}' does not have a "
                      "function 'ground()'").format(type(bad)), ctx)

        # Solve is an attribute but not a function
        with self.assertRaises(AttributeError) as ctx:

            class Bad(object):
                def __init__(self):
                    self.solve = 4

                def ground(self):
                    pass

            bad = Bad()
            ctrl = cclingo.Control(control_=bad)
        check_errmsg(("Wrapped object of type '{}' does not have a "
                      "function 'solve()'").format(type(bad)), ctx)

        # Model wrapper with no "symbols" function or attribute
        with self.assertRaises(AttributeError) as ctx:

            class Bad(object):
                def __init__(self):
                    self.symbols = 2

            bad = Bad()
            m = cclingo.Model(model=bad)
        check_errmsg(("Wrapped object of type '{}' does not have a "
                      "function 'symbols()'").format(type(bad)), ctx)

        with self.assertRaises(AttributeError) as ctx:

            class Bad(object):
                def __init__(self):
                    pass

            bad = Bad()
            m = cclingo.Model(model=bad)
        check_errmsg("'Bad' object has no attribute 'symbols'", ctx)