[Python-checkins] cpython: Skip long repr tests when the cached pyc file's path length would exceed the

antoine.pitrou python-checkins at python.org
Tue Apr 24 13:57:01 CEST 2012


http://hg.python.org/cpython/rev/9381e368b1ae
changeset:   76516:9381e368b1ae
parent:      76512:de0b6e0d8cb9
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Tue Apr 24 13:55:35 2012 +0200
summary:
  Skip long repr tests when the cached pyc file's path length would exceed the maximum Win32 path length.
This should fix a failure on one of the XP buildbots.

files:
  Lib/test/test_reprlib.py |  28 +++++++++++++++++++++++++---
  1 files changed, 25 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py
--- a/Lib/test/test_reprlib.py
+++ b/Lib/test/test_reprlib.py
@@ -3,6 +3,7 @@
   Nick Mathewson
 """
 
+import imp
 import sys
 import os
 import shutil
@@ -199,10 +200,11 @@
         fp.write(text)
 
 class LongReprTest(unittest.TestCase):
+    longname = 'areallylongpackageandmodulenametotestreprtruncation'
+
     def setUp(self):
-        longname = 'areallylongpackageandmodulenametotestreprtruncation'
-        self.pkgname = os.path.join(longname)
-        self.subpkgname = os.path.join(longname, longname)
+        self.pkgname = os.path.join(self.longname)
+        self.subpkgname = os.path.join(self.longname, self.longname)
         # Make the package and subpackage
         shutil.rmtree(self.pkgname, ignore_errors=True)
         os.mkdir(self.pkgname)
@@ -232,7 +234,23 @@
                 os.remove(p)
         del sys.path[0]
 
+    def _check_path_limitations(self, module_name):
+        # base directory
+        source_path_len = len(self.here)
+        # a path separator + `longname` (twice)
+        source_path_len += 2 * (len(self.longname) + 1)
+        # a path separator + `module_name` + ".py"
+        source_path_len += len(module_name) + 1 + len(".py")
+        cached_path_len = source_path_len + len(imp.cache_from_source("x.py")) - len("x.py")
+        if os.name == 'nt' and cached_path_len >= 259:
+            # Under Windows, the max path len is 260 including C's terminating
+            # NUL character.
+            # (see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#maxpath)
+            self.skipTest("test paths too long (%d characters) for Windows' 260 character limit"
+                          % cached_path_len)
+
     def test_module(self):
+        self._check_path_limitations(self.pkgname)
         eq = self.assertEqual
         create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py'))
         importlib.invalidate_caches()
@@ -242,6 +260,7 @@
         eq(repr(sys), "<module 'sys' (built-in)>")
 
     def test_type(self):
+        self._check_path_limitations('foo')
         eq = self.assertEqual
         write_file(os.path.join(self.subpkgname, 'foo.py'), '''\
 class foo(object):
@@ -258,6 +277,7 @@
         pass
 
     def test_class(self):
+        self._check_path_limitations('bar')
         write_file(os.path.join(self.subpkgname, 'bar.py'), '''\
 class bar:
     pass
@@ -268,6 +288,7 @@
         self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__)
 
     def test_instance(self):
+        self._check_path_limitations('baz')
         write_file(os.path.join(self.subpkgname, 'baz.py'), '''\
 class baz:
     pass
@@ -279,6 +300,7 @@
             "<%s.baz object at 0x" % baz.__name__))
 
     def test_method(self):
+        self._check_path_limitations('qux')
         eq = self.assertEqual
         write_file(os.path.join(self.subpkgname, 'qux.py'), '''\
 class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list