2 new commits in py:
https://bitbucket.org/hpk42/py/changeset/8fb4e833f068/ changeset: 8fb4e833f068 user: hpk42 date: 2012-11-05 11:10:50 summary: minor cleanup affected #: 1 file diff -r 8cca692742d7c89697b25aaac7ee7dd9ff5343fc -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 py/_path/common.py --- a/py/_path/common.py +++ b/py/_path/common.py @@ -261,8 +261,8 @@ current = current.dirpath() if last == current: break - l.insert(0, current) - if reverse: + l.append(current) + if not reverse: l.reverse() return l https://bitbucket.org/hpk42/py/changeset/88c67bb04849/ changeset: 88c67bb04849 user: hpk42 date: 2012-11-05 12:11:00 summary: fix pytest issue209 - reintroduce old statementfinding algo for Pythons (e.g. cpython2.4) which don't come with an AST affected #: 6 files diff -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 -r 88c67bb0484990537681b03840cc488690719311 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changes between 1.4.11 and 1.4.12.dev ================================================== +- fix python2.4 support - for pre-AST interpreters re-introduce + old way to find statements in exceptions (closes pytest issue 209) - add tox.ini to distribution Changes between 1.4.10 and 1.4.11 diff -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 -r 88c67bb0484990537681b03840cc488690719311 py/__init__.py --- a/py/__init__.py +++ b/py/__init__.py @@ -8,7 +8,7 @@ (c) Holger Krekel and others, 2004-2010 """ -__version__ = '1.4.11' +__version__ = '1.4.12.dev1' from py import _apipkg diff -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 -r 88c67bb0484990537681b03840cc488690719311 py/_code/source.py --- a/py/_code/source.py +++ b/py/_code/source.py @@ -358,10 +358,14 @@ #print "returning nodelist", l return l -def getstatementrange_ast(lineno, source, astnode=None): +def getstatementrange_ast(lineno, source, assertion=False, astnode=None): if astnode is None: content = "\n".join(source.lines) - astnode = compile(content, "source", "exec", 1024) # 1024 for AST + try: + astnode = compile(content, "source", "exec", 1024) # 1024 for AST + except ValueError: + start, end = getstatementrange_old(lineno, source, assertion) + return None, start, end start, end = get_statement_startend(lineno, getnodelist(astnode)) # we need to correct the end: # - ast-parsing strips comments @@ -378,3 +382,38 @@ break return astnode, start, end +def getstatementrange_old(lineno, source, assertion=False): + """ return (start, end) tuple which spans the minimal + statement region which containing the given lineno. + raise an IndexError if no such statementrange can be found. + """ + # XXX this logic is only used on python2.4 and below + # 1. find the start of the statement + from codeop import compile_command + for start in range(lineno, -1, -1): + if assertion: + line = source.lines[start] + # the following lines are not fully tested, change with care + if 'super' in line and 'self' in line and '__init__' in line: + raise IndexError("likely a subclass") + if "assert" not in line and "raise" not in line: + continue + trylines = source.lines[start:lineno+1] + # quick hack to prepare parsing an indented line with + # compile_command() (which errors on "return" outside defs) + trylines.insert(0, 'def xxx():') + trysource = '\n '.join(trylines) + # ^ space here + try: + compile_command(trysource) + except (SyntaxError, OverflowError, ValueError): + continue + + # 2. find the end of the statement + for end in range(lineno+1, len(source)+1): + trysource = source[start:end] + if trysource.isparseable(): + return start, end + raise SyntaxError("no valid source range around line %d " % (lineno,)) + + diff -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 -r 88c67bb0484990537681b03840cc488690719311 setup.py --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ name='py', description='library with cross-python path, ini-parsing, io, code, log facilities', long_description = open('README.txt').read(), - version='1.4.11', + version='1.4.12.dev1', url='http://pylib.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 -r 88c67bb0484990537681b03840cc488690719311 testing/code/test_excinfo.py --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -4,6 +4,7 @@ queue = py.builtin._tryimport('queue', 'Queue') failsonjython = py.test.mark.xfail("sys.platform.startswith('java')") +from test_source import astonly try: import importlib @@ -91,6 +92,7 @@ assert s.startswith("def f():") assert s.endswith("raise ValueError") + @astonly @failsonjython def test_traceback_entry_getsource_in_construct(self): source = py.code.Source("""\ @@ -108,7 +110,7 @@ print (tb[-1].getsource()) s = str(tb[-1].getsource()) assert s.startswith("def xyz():\n try:") - assert s.endswith("except somenoname:") + assert s.strip().endswith("except somenoname:") def test_traceback_cut(self): co = py.code.Code(f) diff -r 8fb4e833f068de85606a9ea703f4244cfe140cd0 -r 88c67bb0484990537681b03840cc488690719311 testing/code/test_source.py --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -2,6 +2,12 @@ import py import sys +from py._code.source import _ast +if _ast is not None: + astonly = py.test.mark.nothing +else: + astonly = py.test.mark.xfail("True", reason="only works with AST-compile") + failsonjython = py.test.mark.xfail("sys.platform.startswith('java')") def test_source_str_function(): @@ -185,6 +191,7 @@ s = source.getstatement(1) assert s == str(source) + @astonly def test_getstatementrange_within_constructs(self): source = Source("""\ try: @@ -484,6 +491,7 @@ assert str(source) == "raise ValueError(\n 23\n)" class TestTry: + pytestmark = astonly source = """\ try: raise ValueError @@ -528,6 +536,7 @@ class TestIf: + pytestmark = astonly source = """\ if 1: y = 3 Repository URL: https://bitbucket.org/hpk42/py/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn