[Python-checkins] distutils2: Refactored the test to and included version normality in the distinfo_dirname

tarek.ziade python-checkins at python.org
Mon Apr 5 23:09:19 CEST 2010


tarek.ziade pushed 26e961658823 to distutils2:

http://hg.python.org/distutils2/rev/26e961658823
changeset:   92:26e961658823
user:        pumazi
date:        Tue Mar 30 22:02:18 2010 -0400
summary:     Refactored the test to and included version normality in the distinfo_dirname function. The last test item in the test is failing, but it is unclear at this time where the problem should be addressed.
files:       src/distutils2/_backport/pkgutil.py, src/distutils2/_backport/tests/test_pkgutil.py

diff --git a/src/distutils2/_backport/pkgutil.py b/src/distutils2/_backport/pkgutil.py
--- a/src/distutils2/_backport/pkgutil.py
+++ b/src/distutils2/_backport/pkgutil.py
@@ -9,6 +9,7 @@
 import os.path
 from types import ModuleType
 from distutils2.metadata import DistributionMetadata
+from distutils2.version import suggest_normalized_version
 
 __all__ = [
     'get_importer', 'iter_importers', 'get_loader', 'find_loader',
@@ -684,7 +685,11 @@
     :rtype: string"""
     file_extension = '.dist-info'
     name = name.replace('-', '_')
-    return '-'.join([name, version]) + file_extension
+    normalized_version = suggest_normalized_version(version)
+    if normalized_version is None:
+        # Unable to achieve normality?
+        normalized_version = version
+    return '-'.join([name, normalized_version]) + file_extension
 
 def get_distributions():
     """
diff --git a/src/distutils2/_backport/tests/test_pkgutil.py b/src/distutils2/_backport/tests/test_pkgutil.py
--- a/src/distutils2/_backport/tests/test_pkgutil.py
+++ b/src/distutils2/_backport/tests/test_pkgutil.py
@@ -20,24 +20,26 @@
     def test_distinfo_dirname(self):
         """Given a name and a version, we expect the distinfo_dirname function
         to return a standard distribution information directory name."""
-        # Test for a very simple single word name and decimal version number
-        name = 'docutils'
-        version = '0.5'
-        standard_dirname = 'docutils-0.5.dist-info'
 
+        items = [ # (name, version, standard_dirname)
+            # Test for a very simple single word name and decimal version number
+            ('docutils', '0.5', 'docutils-0.5.dist-info'),
+            # Test for another except this time with a '-' in the name, which
+            #   needs to be transformed during the name lookup
+            ('python-ldap', '2.5', 'python_ldap-2.5.dist-info'),
+            # Test for both '-' in the name and a funky version number
+            # FIXME The end result, as defined in PEP 376, does not match what
+            #   would be acceptable by PEP 386.
+            ('python-ldap', '2.5 a---5', 'python_ldap-2.5.a_5.dist-info'),
+            ]
+
+        # Import the function in question
         from distutils2._backport.pkgutil import distinfo_dirname
-        dirname = distinfo_dirname(name, version)
-        self.assertEqual(dirname, standard_dirname)
 
-        # Test for another except this time with a '-' in the name, which
-        #   needs to be transformed during the name lookup
-        name = 'python-ldap'
-        version = '2.5'
-        standard_dirname = 'python_ldap-2.5.dist-info'
-
-        from distutils2._backport.pkgutil import distinfo_dirname
-        dirname = distinfo_dirname(name, version)
-        self.assertEqual(dirname, standard_dirname)
+        # Loop through the items to validate the results
+        for name, version, standard_dirname in items:
+            dirname = distinfo_dirname(name, version)
+            self.assertEqual(dirname, standard_dirname)
 
 
 def test_suite():

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


More information about the Python-checkins mailing list