[svn r57321] merging the event branch:
* moving in test, misc, code, io directories and py/__init__.py * py/bin/_find.py does not print to stderr anymore * a few fixes to conftest files in other dirs some more fixes and adjustments pending --HG-- branch : trunk
This commit is contained in:
34
py/code/testing/test_safe_repr.py
Normal file
34
py/code/testing/test_safe_repr.py
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
import py
|
||||
from py.__.code import safe_repr
|
||||
|
||||
def test_simple_repr():
|
||||
assert safe_repr._repr(1) == '1'
|
||||
assert safe_repr._repr(None) == 'None'
|
||||
|
||||
class BrokenRepr:
|
||||
def __init__(self, ex):
|
||||
self.ex = ex
|
||||
foo = 0
|
||||
def __repr__(self):
|
||||
raise self.ex
|
||||
|
||||
def test_exception():
|
||||
assert 'Exception' in safe_repr._repr(BrokenRepr(Exception("broken")))
|
||||
|
||||
class BrokenReprException(Exception):
|
||||
__str__ = None
|
||||
__repr__ = None
|
||||
|
||||
def test_broken_exception():
|
||||
assert 'Exception' in safe_repr._repr(BrokenRepr(BrokenReprException("really broken")))
|
||||
|
||||
def test_string_exception():
|
||||
assert 'unknown' in safe_repr._repr(BrokenRepr("string"))
|
||||
|
||||
def test_big_repr():
|
||||
assert len(safe_repr._repr(range(1000))) <= \
|
||||
len('[' + safe_repr.SafeRepr().maxlist * "1000" + ']')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user