def test_eval_attr(self):
        if not compat_24:
            warn("No support for eval attributes in python versions older"
                 " than 2.4")
            return

        def f():
            pass

        f.monkey = 2

        def g():
            pass

        g.monkey = 6

        def h():
            pass

        h.monkey = 5

        cnf = Config()
        opt = Bucket()
        opt.eval_attr = "monkey > 5"
        plug = AttributeSelector()
        plug.configure(opt, cnf)

        assert not plug.wantFunction(f)
        assert plug.wantFunction(g) is not False
        assert not plug.wantFunction(h)
예제 #2
0
    def test_eval_attr(self):
        if not compat_24:
            warn("No support for eval attributes in python versions older"
                 " than 2.4")
            return
        def f():
            pass
        f.monkey = 2

        def g():
            pass
        g.monkey = 6

        def h():
            pass
        h.monkey = 5

        cnf = Config()
        opt = Bucket()
        opt.eval_attr = "monkey > 5"
        plug = AttributeSelector()
        plug.configure(opt, cnf)

        assert not plug.wantFunction(f)
        assert plug.wantFunction(g) is not False
        assert not plug.wantFunction(h)
예제 #3
0
    def test_basic_attr(self):
        def f():
            pass
        f.a = 1

        def g():
            pass

        plug = AttributeSelector()
        plug.attribs = [[('a', True)]]
        assert plug.wantFunction(f) is not False
        assert not plug.wantFunction(g)
    def test_basic_attr(self):
        def f():
            pass

        f.a = 1

        def g():
            pass

        plug = AttributeSelector()
        plug.attribs = [[('a', True)]]
        assert plug.wantFunction(f) is not False
        assert not plug.wantFunction(g)
예제 #5
0
    def test_class_and_method_str_attr(self):
        class TestP(object):
            foo = 'a'

            def h(self):
                pass
            h.foo = 'b'

        def i():
            pass
        i.foo = 'a'

        plug = AttributeSelector()
        plug.attribs = [[('foo', 'a'), ('foo', 'b')]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False

        plug.attribs = [[('foo', 'b')]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False
예제 #6
0
    def test_class_attr(self):
        class TestP:
            foo = True
            def h():
                pass

        def i():
            pass

        plug = AttributeSelector()
        plug.attribs = [[('foo', True)]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False
    def test_class_attr(self):
        class TestP:
            foo = True

            def h():
                pass

        def i():
            pass

        plug = AttributeSelector()
        plug.attribs = [[('foo', True)]]
        assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False
        assert plug.wantFunction(i) is False
예제 #8
0
    def test_attr_a_b(self):
        def f1():
            pass

        f1.tags = ['a', 'b']

        def f2():
            pass

        f2.tags = ['a', 'c']

        def f3():
            pass

        f3.tags = ['b', 'c']

        def f4():
            pass

        f4.tags = ['c', 'd']

        cnf = Config()
        parser = OptionParser()
        plug = AttributeSelector()

        plug.add_options(parser)

        # OR
        opt, args = parser.parse_args(['test', '-a', 'tags=a',
                                       '-a', 'tags=b'])
        print
        opt
        plug.configure(opt, cnf)

        assert plug.wantFunction(f1) is None
        assert plug.wantFunction(f2) is None
        assert plug.wantFunction(f3) is None
        assert not plug.wantFunction(f4)

        # AND
        opt, args = parser.parse_args(['test', '-a', 'tags=a,tags=b'])
        print
        opt
        plug.configure(opt, cnf)

        assert plug.wantFunction(f1) is None
        assert not plug.wantFunction(f2)
        assert not plug.wantFunction(f3)
        assert not plug.wantFunction(f4)
예제 #9
0
    def test_attr_a_b(self):
        def f1():
            pass

        f1.tags = ["a", "b"]

        def f2():
            pass

        f2.tags = ["a", "c"]

        def f3():
            pass

        f3.tags = ["b", "c"]

        def f4():
            pass

        f4.tags = ["c", "d"]

        cnf = Config()
        parser = OptionParser()
        plug = AttributeSelector()

        plug.add_options(parser)

        # OR
        opt, args = parser.parse_args(["test", "-a", "tags=a", "-a", "tags=b"])
        print opt
        plug.configure(opt, cnf)

        assert plug.wantFunction(f1) is None
        assert plug.wantFunction(f2) is None
        assert plug.wantFunction(f3) is None
        assert not plug.wantFunction(f4)

        # AND
        opt, args = parser.parse_args(["test", "-a", "tags=a,tags=b"])
        print opt
        plug.configure(opt, cnf)

        assert plug.wantFunction(f1) is None
        assert not plug.wantFunction(f2)
        assert not plug.wantFunction(f3)
        assert not plug.wantFunction(f4)
예제 #10
0
    def test_attr_a_b(self):
        def f1():
            pass
        f1.tags = ['a', 'b']

        def f2():
            pass
        f2.tags = ['a', 'c']

        def f3():
            pass
        f3.tags = ['b', 'c']

        def f4():
            pass
        f4.tags = ['c', 'd']

        cnf = Config()
        parser = OptionParser()
        plug = AttributeSelector()

        plug.add_options(parser)

        # OR
        opt, args = parser.parse_args(['test', '-a', 'tags=a',
                                       '-a', 'tags=b'])
        print opt
        plug.configure(opt, cnf)

        assert plug.wantFunction(f1) is None
        assert plug.wantFunction(f2) is None
        assert plug.wantFunction(f3) is None
        assert not plug.wantFunction(f4)

        # AND
        opt, args = parser.parse_args(['test', '-a', 'tags=a,tags=b'])
        print opt
        plug.configure(opt, cnf)

        assert plug.wantFunction(f1) is None
        assert not plug.wantFunction(f2)
        assert not plug.wantFunction(f3)
        assert not plug.wantFunction(f4)