From a20731b111a0347ae0062a38cc59b3793f896c08 Mon Sep 17 00:00:00 2001 From: hpk Date: Mon, 18 Aug 2008 19:33:31 +0200 Subject: [PATCH] [svn r57440] various fixes for python2.6 --HG-- branch : trunk --- py/code/testing/test_safe_repr.py | 7 ++++++- py/execnet/rsync.py | 7 +++++-- py/path/common.py | 8 ++++++-- py/test/outcome.py | 14 +++++++++++--- py/test/testing/test_session.py | 3 ++- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/py/code/testing/test_safe_repr.py b/py/code/testing/test_safe_repr.py index 31d06d804..4d67ed14b 100644 --- a/py/code/testing/test_safe_repr.py +++ b/py/code/testing/test_safe_repr.py @@ -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))) <= \ diff --git a/py/execnet/rsync.py b/py/execnet/rsync.py index fef5eba2a..d4034dd65 100644 --- a/py/execnet/rsync.py +++ b/py/execnet/rsync.py @@ -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) diff --git a/py/path/common.py b/py/path/common.py index 37ad02c1f..d0723d479 100644 --- a/py/path/common.py +++ b/py/path/common.py @@ -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) + diff --git a/py/test/outcome.py b/py/test/outcome.py index 0797e595c..f3c5d80a2 100644 --- a/py/test/outcome.py +++ b/py/test/outcome.py @@ -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 diff --git a/py/test/testing/test_session.py b/py/test/testing/test_session.py index 1e2bc1a5c..7b450ba7c 100644 --- a/py/test/testing/test_session.py +++ b/py/test/testing/test_session.py @@ -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):