Commits

holger krekel committed 2398985

fix getting statementrange/compiling a file ending
in a comment line without newline (on python2.5)

Comments (0)

Files changed (5)

 Changes between 1.4.12 and 1.4.13.dev
 ==================================================
 
+- fix getting statementrange/compiling a file ending
+  in a comment line without newline (on python2.5)
 - for local paths you can pass "mode=True" to a copy()
   in order to copy permission bits (underlying mechanism
   is using shutil.copymode)
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '1.4.13.dev5'
+__version__ = '1.4.13dev6'
 
 from py import _apipkg
 

py/_code/source.py

 
 def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
     if astnode is None:
-        content = "\n".join(source.lines)
+        content = str(source)
+        if sys.version_info < (2,6):
+            content += "\n"
         try:
             astnode = compile(content, "source", "exec", 1024)  # 1024 for AST
         except ValueError:
         name='py',
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.13.dev5',
+        version='1.4.13dev6',
         url='http://pylib.readthedocs.org/',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

testing/code/test_source.py

     source = getstatement(0, "raise ValueError")
     assert str(source) == "raise ValueError"
 
+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
+
 def test_oneline_and_comment():
     source = getstatement(0, "raise ValueError\n#hello")
     assert str(source) == "raise ValueError"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.