示例#1
0
    def test_single_line_function(self):
        @njit
        def foo():
            pass  # noqa: E704

        first_def_line = get_func_body_first_lineno(foo)
        self.assert_line_location(first_def_line, 2)
示例#2
0
    def test_pass_statement(self):
        @njit
        def foo():
            pass

        first_def_line = get_func_body_first_lineno(foo)
        self.assert_line_location(first_def_line, 3)
示例#3
0
    def test_undecorated_odd_comment_indent(self):
        def foo():
            # NOTE: THIS COMMENT MUST START AT COLUMN 0 FOR THIS SAMPLE CODE TO BE VALID # noqa: E115, E501
            return 1

        first_def_line = get_func_body_first_lineno(njit(foo))
        self.assert_line_location(first_def_line, 3)
示例#4
0
    def test_docstring(self):
        @njit
        def foo():
            """Docstring
            """
            pass

        first_def_line = get_func_body_first_lineno(foo)
        self.assert_line_location(first_def_line, 5)
示例#5
0
    def test_string_eval(self):
        source = """def foo():
            pass
        """

        globalns = {}
        exec(source, globalns)
        foo = globalns['foo']

        first_def_line = get_func_body_first_lineno(foo)
        # Cannot determine first line of string evaled functions
        self.assertIsNone(first_def_line)
示例#6
0
    def test_nested_function(self):
        def foo():
            @njit
            def foo():
                # This function is intentionally named the same as the parent
                return 1

            return foo

        inner = foo()
        first_def_line = get_func_body_first_lineno(inner)
        self.assert_line_location(first_def_line, 5)
示例#7
0
    def test_docstring_2(self):
        @njit
        def foo():
            """Docstring
            """
            """Not Docstring, but a bare string literal
            """
            pass

        # Variation on test_docstring but with a "fake" docstring following
        # the true docstring.
        first_def_line = get_func_body_first_lineno(foo)
        if PYVERSION == (3, 7):
            # Python 3.7 oddly uses the last line for string literal AST nodes
            self.assert_line_location(first_def_line, 6)
        else:
            self.assert_line_location(first_def_line, 5)
示例#8
0
 def test_unnamed_lambda(self):
     foo = lambda: 1
     first_def_line = get_func_body_first_lineno(njit(foo))
     # Cannot determine first line of lambda function
     self.assertIsNone(first_def_line)