示例#1
0
def test_comment_and_no_newline_at_end():
    from py._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
示例#2
0
文件: code.py 项目: Coder206/servo
 def getsource(self, astcache=None):
     """ return failing source code. """
     # we use the passed in astcache to not reparse asttrees
     # within exception info printing
     from py._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]
示例#3
0
def getstatement(lineno, source):
    from py._code.source import getstatementrange_ast
    source = py.code.Source(source, deindent=False)
    ast, start, end = getstatementrange_ast(lineno, source)
    return source[start:end]
def test_getstatementrange_ast():
    source = py.code.Source(code)
    _, _, end = getstatementrange_ast(19, source)
    assert end == 31