示例#1
0
    def getsource(self, astcache=None):
        """ return failing source code. """
        # we use the passed in astcache to not reparse asttrees
        # within exception info printing
        from _pytest._code.source import getstatementrange_ast

        source = self.frame.code.fullsource
        if source is None:
            return None
        key = astnode = None
        if astcache is not None:
            key = self.frame.code.path
            if key is not None:
                astnode = astcache.get(key, None)
        start = self.getfirstlinesource()
        try:
            astnode, _, end = getstatementrange_ast(
                self.lineno, source, astnode=astnode
            )
        except SyntaxError:
            end = self.lineno + 1
        else:
            if key is not None:
                astcache[key] = astnode
        return source[start:end]
示例#2
0
 def getsource(
     self,
     astcache: Optional[Dict[Union[str, Path], ast.AST]] = None
 ) -> Optional["Source"]:
     """Return failing source code."""
     # we use the passed in astcache to not reparse asttrees
     # within exception info printing
     source = self.frame.code.fullsource
     if source is None:
         return None
     key = astnode = None
     if astcache is not None:
         key = self.frame.code.path
         if key is not None:
             astnode = astcache.get(key, None)
     start = self.getfirstlinesource()
     try:
         astnode, _, end = getstatementrange_ast(self.lineno,
                                                 source,
                                                 astnode=astnode)
     except SyntaxError:
         end = self.lineno + 1
     else:
         if key is not None and astcache is not None:
             astcache[key] = astnode
     return source[start:end]
示例#3
0
def test_comment_and_no_newline_at_end():
    from _pytest._code.source import getstatementrange_ast
    source = Source(['def test_basic_complex():',
                     '    assert 1 == 2',
                     '# vim: filetype=pyopencl:fdm=marker'])
    ast, start, end = getstatementrange_ast(1, source)
    assert end == 2
示例#4
0
def test_comment_and_no_newline_at_end():
    from _pytest._code.source import getstatementrange_ast
    source = Source(['def test_basic_complex():',
                     '    assert 1 == 2',
                     '# vim: filetype=pyopencl:fdm=marker'])
    ast, start, end = getstatementrange_ast(1, source)
    assert end == 2
示例#5
0
    def getsource(self, astcache=None):
        """ return failing source code. """
        # we use the passed in astcache to not reparse asttrees
        # within exception info printing
        from _pytest._code.source import getstatementrange_ast

        source = self.frame.code.fullsource
        if source is None:
            return None
        key = astnode = None
        if astcache is not None:
            key = self.frame.code.path
            if key is not None:
                astnode = astcache.get(key, None)
        start = self.getfirstlinesource()
        try:
            astnode, _, end = getstatementrange_ast(
                self.lineno, source, astnode=astnode
            )
        except SyntaxError:
            end = self.lineno + 1
        else:
            if key is not None:
                astcache[key] = astnode
        return source[start:end]
示例#6
0
def getstatement(lineno, source):
    from _pytest._code.source import getstatementrange_ast

    source = _pytest._code.Source(source, deindent=False)
    ast, start, end = getstatementrange_ast(lineno, source)
    return source[start:end]
示例#7
0
def getstatement(lineno: int, source) -> Source:
    from _pytest._code.source import getstatementrange_ast

    src = Source(source)
    ast, start, end = getstatementrange_ast(lineno, src)
    return src[start:end]
示例#8
0
def getstatement(lineno, source):
    from _pytest._code.source import getstatementrange_ast

    source = _pytest._code.Source(source, deindent=False)
    ast, start, end = getstatementrange_ast(lineno, source)
    return source[start:end]