[svn r57440] various fixes for python2.6

--HG--
branch : trunk
This commit is contained in:
hpk 2008-08-18 19:33:31 +02:00
parent fc3721259f
commit a20731b111
5 changed files with 30 additions and 9 deletions

View File

@ -24,7 +24,12 @@ 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"))
if py.std.sys.version_info < (2,6):
assert 'unknown' in safe_repr._repr(BrokenRepr("string"))
else:
assert 'TypeError' in safe_repr._repr(BrokenRepr("string"))
def test_big_repr():
assert len(safe_repr._repr(range(1000))) <= \

View File

@ -1,6 +1,9 @@
import py, os, stat, md5
import py, os, stat
from Queue import Queue
try:
from hashlib import md5
except ImportError:
from md5 import md5
class RSync(object):
""" This class allows to send a directory structure (recursively)

View File

@ -431,7 +431,7 @@ def relativeimport(p, name, parent=None):
old_import_hook = None
def custom_import_hook(name, glob=None, loc=None, fromlist=None):
def custom_import_hook(name, glob=None, loc=None, fromlist=None, extra=None, level=None):
__tracebackhide__ = False
__file__ = glob and glob.get('__file__')
if isinstance(__file__, PathStr):
@ -457,5 +457,9 @@ def custom_import_hook(name, glob=None, loc=None, fromlist=None):
return modules[0] # outermost package
# fall-back
__tracebackhide__ = True
return old_import_hook(name, glob, loc, fromlist)
try:
return old_import_hook(name, glob, loc, fromlist, level)
except TypeError:
return old_import_hook(name, glob, loc, fromlist)

View File

@ -99,18 +99,26 @@ def deprecated_call(func, *args, **kwargs):
""" assert that calling func(*args, **kwargs)
triggers a DeprecationWarning.
"""
warningmodule = py.std.warnings
l = []
oldwarn = py.std.warnings.warn_explicit
oldwarn_explicit = getattr(warningmodule, 'warn_explicit')
def warn_explicit(*args, **kwargs):
l.append(args)
oldwarn_explicit(*args, **kwargs)
oldwarn = getattr(warningmodule, 'warn')
def warn(*args, **kwargs):
l.append(args)
oldwarn(*args, **kwargs)
py.magic.patch(py.std.warnings, 'warn_explicit', warn_explicit)
warningmodule.warn_explicit = warn_explicit
warningmodule.warn = warn
try:
ret = func(*args, **kwargs)
finally:
py.magic.revert(py.std.warnings, 'warn_explicit')
warningmodule.warn_explicit = warn_explicit
warningmodule.warn = warn
if not l:
print warningmodule
raise AssertionError("%r did not produce DeprecationWarning" %(func,))
return ret

View File

@ -187,7 +187,8 @@ class SessionTests(suptest.InlineCollection):
out = failed[0].outcome.longrepr.reprcrash.message
assert out.find("""[Exception("Ha Ha fooled you, I'm a broken repr().") raised in repr()]""") != -1 #'
out = failed[1].outcome.longrepr.reprcrash.message
assert out.find("[unknown exception raised in repr()]") != -1
assert (out.find("[unknown exception raised in repr()]") != -1 or
out.find("TypeError") != -1)
class TestNewSession(SessionTests):
def test_pdb_run(self):