From 05f29b7a3aabc89000cce21d7bfec368f9ba5a26 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 25 Jan 2012 01:35:26 +0100 Subject: [PATCH 1/2] Make test work under 32-bit systems, and when invoked through Lib/test/regrtest.py (rather than `-m test.regrtest`) --- Lib/test/test_import.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 33277d7a670..95b90b8b308 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -313,14 +313,22 @@ class ImportTests(unittest.TestCase): def test_timestamp_overflow(self): # A modification timestamp larger than 2**32 should not be a problem # when importing a module (issue #11235). - source = TESTFN + ".py" - compiled = imp.cache_from_source(source) - with open(source, 'w') as f: - pass - os.utime(source, (2 ** 33, 2 ** 33)) - __import__(TESTFN) - # The pyc file was created. - os.stat(compiled) + sys.path.insert(0, os.curdir) + try: + source = TESTFN + ".py" + compiled = imp.cache_from_source(source) + with open(source, 'w') as f: + pass + try: + os.utime(source, (2 ** 33, 2 ** 33)) + except OverflowError: + self.skipTest("cannot set modification time to large integer") + __import__(TESTFN) + # The pyc file was created. + os.stat(compiled) + finally: + del sys.path[0] + remove_files(TESTFN) class PycRewritingTests(unittest.TestCase): From dd21f68963c2b17324b6018dbbf1b32b6e88f2c2 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 25 Jan 2012 03:00:57 +0100 Subject: [PATCH 2/2] Port remaining test fixes, and fix test_importlib too. --- Lib/importlib/test/source/test_file_loader.py | 10 +++++++++- Lib/test/test_import.py | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py index 89990be9da9..912e6c3b51b 100644 --- a/Lib/importlib/test/source/test_file_loader.py +++ b/Lib/importlib/test/source/test_file_loader.py @@ -4,6 +4,7 @@ from .. import abc from .. import util from . import util as source_util +import errno import imp import marshal import os @@ -136,7 +137,14 @@ class SimpleTest(unittest.TestCase): compiled = imp.cache_from_source(source) with open(source, 'w') as f: f.write("x = 5") - os.utime(source, (2 ** 33, 2 ** 33)) + try: + os.utime(source, (2 ** 33, 2 ** 33)) + except OverflowError: + self.skipTest("cannot set modification time to large integer") + except OSError as e: + if e.errno != getattr(errno, 'EOVERFLOW', None): + raise + self.skipTest("cannot set modification time to large integer ({})".format(e)) loader = _bootstrap._SourceFileLoader('_temp', mapping['_temp']) mod = loader.load_module('_temp') # Sanity checks. diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 95b90b8b308..311063505e9 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -11,6 +11,7 @@ import stat import sys import unittest import textwrap +import errno from test.support import ( EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, @@ -323,6 +324,10 @@ class ImportTests(unittest.TestCase): os.utime(source, (2 ** 33, 2 ** 33)) except OverflowError: self.skipTest("cannot set modification time to large integer") + except OSError as e: + if e.errno != getattr(errno, 'EOVERFLOW', None): + raise + self.skipTest("cannot set modification time to large integer ({})".format(e)) __import__(TESTFN) # The pyc file was created. os.stat(compiled)