Пример #1
0
    def test_parse_method_decorators(self):
        """Multiple method decorators are accumulated along with their args."""
        code = textwrap.dedent("""\
            class Foo:
                @first_decorator
                @second.decorator(argument)
                @third.multi.line(
                    decorator,
                    key=value,
                    )
                def method(self):
                    pass
        """)

        module = checker.parse(io.StringIO(code), 'dummy.py')
        defined_class = module.children[0]
        decorators = defined_class.children[0].decorators

        assert 3 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
        assert 'second.decorator' == decorators[1].name
        assert 'argument' == decorators[1].arguments
        assert 'third.multi.line' == decorators[2].name
        assert 'decorator,key=value,' == decorators[2].arguments
Пример #2
0
    def test_parse_method_decorators(self):
        """Multiple method decorators are accumulated along with their args."""
        code = textwrap.dedent("""\
            class Foo:
                @first_decorator
                @second.decorator(argument)
                @third.multi.line(
                    decorator,
                    key=value,
                    )
                def method(self):
                    pass
        """)

        module = checker.parse(StringIO(code), 'dummy.py')
        defined_class = module.children[0]
        decorators = defined_class.children[0].decorators

        assert 3 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
        assert 'second.decorator' == decorators[1].name
        assert 'argument' == decorators[1].arguments
        assert 'third.multi.line' == decorators[2].name
        assert 'decorator,key=value,' == decorators[2].arguments
Пример #3
0
    def test_parse_class_single_decorator(self):
        """Class decorator is recorded in class instance."""
        code = textwrap.dedent("""\
            @first_decorator
            class Foo:
                pass
        """)
        module = checker.parse(io.StringIO(code), 'dummy.py')
        decorators = module.children[0].decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #4
0
    def test_parse_class_single_decorator(self):
        """Class decorator is recorded in class instance."""
        code = textwrap.dedent("""\
            @first_decorator
            class Foo:
                pass
        """)
        module = checker.parse(StringIO(code), 'dummy.py')
        decorators = module.children[0].decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #5
0
    def test_parse_function_decorator(self):
        """A function decorator is also accumulated."""
        code = textwrap.dedent("""\
            @first_decorator
            def some_method(self):
                pass
        """)

        module = checker.parse(io.StringIO(code), 'dummy.py')
        decorators = module.children[0].decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #6
0
    def test_parse_function_decorator(self):
        """A function decorator is also accumulated."""
        code = textwrap.dedent("""\
            @first_decorator
            def some_method(self):
                pass
        """)

        module = checker.parse(StringIO(code), 'dummy.py')
        decorators = module.children[0].decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #7
0
    def test_parse_method_single_decorator(self):
        """Method decorators are accumulated."""
        code = textwrap.dedent("""\
            class Foo:
                @first_decorator
                def method(self):
                    pass
        """)

        module = checker.parse(io.StringIO(code), 'dummy.py')
        defined_class = module.children[0]
        decorators = defined_class.children[0].decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #8
0
    def test_parse_method_single_decorator(self):
        """Method decorators are accumulated."""
        code = textwrap.dedent("""\
            class Foo:
                @first_decorator
                def method(self):
                    pass
        """)

        module = checker.parse(StringIO(code), 'dummy.py')
        defined_class = module.children[0]
        decorators = defined_class.children[0].decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #9
0
    def test_parse_class_nested_decorator(self):
        """Class decorator is recorded even for nested classes."""
        code = textwrap.dedent("""\
            @parent_decorator
            class Foo:
                pass
                @first_decorator
                class NestedClass:
                    pass
        """)
        module = checker.parse(io.StringIO(code), 'dummy.py')
        nested_class = module.children[0].children[0]
        decorators = nested_class.decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments
Пример #10
0
    def test_parse_class_nested_decorator(self):
        """Class decorator is recorded even for nested classes."""
        code = textwrap.dedent("""\
            @parent_decorator
            class Foo:
                pass
                @first_decorator
                class NestedClass:
                    pass
        """)
        module = checker.parse(StringIO(code), 'dummy.py')
        nested_class = module.children[0].children[0]
        decorators = nested_class.decorators

        assert 1 == len(decorators)
        assert 'first_decorator' == decorators[0].name
        assert '' == decorators[0].arguments