def test_parameter_violation_error(self):
        @module
        def conf(self):
            self._constrain(m1(a=True))
            self._constrain(m1(a=False))

        @module
        def m1(self, a=False):
            pass

        with self.assertRaises(SolveError):
            resolve(conf)
    def test_solve(self):
        #(~A | A&~A)
        @module
        def conf(self):
            self._constrain(m1)

        @module
        def m1(self, a=False):
            if a:
                self._constrain(m2)
            else:
                self._constrain(m3(a=False))

        @module
        def m2(self):
            self._constrain(m3(a=True))
            self._constrain(m3(a=False))

        @module
        def m3(self, a=False):
            pass

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertNotIn(m2, modules)
        self.assertIn(m3, modules)
    def test_unused_module(self):
        @module
        def conf(self):
            self._constrain(m1(isM2=True))

        @module
        def m1(self, isM2=False):
            if isM2:
                self._constrain(m2)

        @module
        def m2(self):
            pass

        @module
        def m3(self):
            self._constrain(m4)
            pass

        @module
        def m4(self):
            pass

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertIn(m2, modules)
        self.assertNotIn(m3, modules)
        self.assertNotIn(m4, modules)
Exemple #4
0
    def test_solve(self):
        #(~A | A&~A)
        @module
        def conf(self):
            self._constrain(m1)

        @module
        def m1(self, a=False):
            if a:
                self._constrain(m2)
            else:
                self._constrain(m3(a=False))

        @module
        def m2(self):
            self._constrain(m3(a=True))
            self._constrain(m3(a=False))

        @module
        def m3(self, a=False):
            pass

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertNotIn(m2, modules)
        self.assertIn(m3, modules)
Exemple #5
0
    def test_unused_module(self):
        @module
        def conf(self):
            self._constrain(m1(isM2=True))

        @module
        def m1(self, isM2=False):
            if isM2:
                self._constrain(m2)

        @module
        def m2(self):
            pass

        @module
        def m3(self):
            self._constrain(m4)
            pass

        @module
        def m4(self):
            pass

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertIn(m2, modules)
        self.assertNotIn(m3, modules)
        self.assertNotIn(m4, modules)
Exemple #6
0
def my_resolve(ctx, conf_module):
    cache = ctx._my_resolve_cache
    try:
        instance_map = cache[conf_module]
    except KeyError:
        try:
            instance_map = resolve(conf_module)
        except SolveError as e:
            e.rgraph = get_error_rgraph(e)
            for reason, depth in traverse_error_rgraph(e.rgraph):
                print_reason(e.rgraph, reason, depth)
            raise e

        cache[conf_module] = instance_map

    return instance_map
Exemple #7
0
def my_resolve(ctx, conf_module):
    cache = ctx._my_resolve_cache
    try:
        instance_map = cache[conf_module]
    except KeyError:
        try:
            instance_map = resolve(conf_module)
        except SolveError as e:
            e.rgraph = get_error_rgraph(e)
            reason_generator = traversal(e.rgraph)
            for reason, depth in reason_generator:
                print_reason(e.rgraph, reason, depth)
            raise e

        cache[conf_module] = instance_map

    return instance_map
    def test_cyclic_dependence(self):
        @module
        def conf(self):
            self._constrain(m1)

        @module
        def m1(self):
            self._constrain(m2)

        @module
        def m2(self):
            self._constrain(m1)

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertIn(m2, modules)
Exemple #9
0
    def test_cyclic_dependence(self):
        @module
        def conf(self):
            self._constrain(m1)

        @module
        def m1(self):
            self._constrain(m2)

        @module
        def m2(self):
            self._constrain(m1)

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertIn(m2, modules)
    def test_simple_solution(self):
        @module
        def conf(self):
            self._constrain(m1(isM2=True))

        @module
        def m1(self, isM2=False):
            if isM2:
                self._constrain(m2)

        @module
        def m2(self):
            pass

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertIn(m2, modules)
Exemple #11
0
    def test_simple_solution(self):
        @module
        def conf(self):
            self._constrain(m1(isM2=True))

        @module
        def m1(self, isM2=False):
            if isM2:
                self._constrain(m2)

        @module
        def m2(self):
            pass

        modules = resolve(conf)

        self.assertIn(conf, modules)
        self.assertIn(m1, modules)
        self.assertIn(m2, modules)