[Python-checkins] cpython (merge 3.2 -> 3.2): merge heads

senthil.kumaran python-checkins at python.org
Tue Mar 13 08:17:37 CET 2012


http://hg.python.org/cpython/rev/0b3e5503a6ee
changeset:   75580:0b3e5503a6ee
branch:      3.2
parent:      75578:744a8256489f
parent:      75571:0f1619e539fb
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Tue Mar 13 00:16:58 2012 -0700
summary:
  merge heads

files:
  Lib/unittest/loader.py |  13 +++++++++----
  Misc/NEWS              |   2 ++
  2 files changed, 11 insertions(+), 4 deletions(-)


diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -34,6 +34,11 @@
     TestClass = type(classname, (case.TestCase,), attrs)
     return suiteClass((TestClass(methodname),))
 
+def _jython_aware_splitext(path):
+    if path.lower().endswith('$py.class'):
+        return path[:-9]
+    return os.path.splitext(path)[0]
+
 
 class TestLoader(object):
     """
@@ -221,7 +226,7 @@
             return os.path.dirname(full_path)
 
     def _get_name_from_path(self, path):
-        path = os.path.splitext(os.path.normpath(path))[0]
+        path = _jython_aware_splitext(os.path.normpath(path))
 
         _relpath = os.path.relpath(path, self._top_level_dir)
         assert not os.path.isabs(_relpath), "Path must be within the project"
@@ -258,11 +263,11 @@
                     yield _make_failed_import_test(name, self.suiteClass)
                 else:
                     mod_file = os.path.abspath(getattr(module, '__file__', full_path))
-                    realpath = os.path.splitext(mod_file)[0]
-                    fullpath_noext = os.path.splitext(full_path)[0]
+                    realpath = _jython_aware_splitext(mod_file)
+                    fullpath_noext = _jython_aware_splitext(full_path)
                     if realpath.lower() != fullpath_noext.lower():
                         module_dir = os.path.dirname(realpath)
-                        mod_name = os.path.splitext(os.path.basename(full_path))[0]
+                        mod_name = _jython_aware_splitext(os.path.basename(full_path))
                         expected_dir = os.path.dirname(full_path)
                         msg = ("%r module incorrectly imported from %r. Expected %r. "
                                "Is this module globally installed?")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,8 @@
 Library
 -------
 
+- Issue #10543: Fix unittest test discovery with Jython bytecode files.
+
 - Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under
   Windows when the child process has already exited.
 

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


More information about the Python-checkins mailing list