fix issue94 make reporting more robust against bogus source code

(and internally be more careful when presenting unexpected byte sequences)
also make py.code.Source accept a list of lines directly.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2010-05-21 16:42:46 +02:00
parent 93f91c9607
commit 578cba20d4
4 changed files with 34 additions and 4 deletions

View File

@@ -36,6 +36,19 @@ def test_source_from_function():
source = py.code.Source(test_source_str_function)
assert str(source).startswith('def test_source_str_function():')
def test_source_from_method():
class TestClass:
def test_method(self):
pass
source = py.code.Source(TestClass().test_method)
assert source.lines == ["def test_method(self):",
" pass"]
def test_source_from_lines():
lines = ["a \n", "b\n", "c"]
source = py.code.Source(lines)
assert source.lines == ['a ', 'b', 'c']
def test_source_from_inner_function():
def f():
pass
@@ -92,6 +105,7 @@ def test_isparseable():
assert Source(" \nif 1:\n pass").isparseable()
assert not Source("if 1:\n").isparseable()
assert not Source(" \nif 1:\npass").isparseable()
assert not Source(chr(0)).isparseable()
class TestAccesses:
source = Source("""\