[Python-checkins] distutils2: Fixed more of the record file generation testing. Added the test and

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


tarek.ziade pushed d94e8697e7cc to distutils2:

http://hg.python.org/distutils2/rev/d94e8697e7cc
changeset:   107:d94e8697e7cc
user:        pumazi
date:        Thu Apr 01 22:18:25 2010 -0400
summary:     Fixed more of the record file generation testing. Added the test and functionality for the Distribution.get_distinfo_files method.
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
@@ -616,6 +616,16 @@
         self.metadata = DistributionMetadata(path=metadata_path)
         self.name = self.metadata['name']
 
+    def _get_records(self, local=False):
+        RECORD = os.path.join(self.path, 'RECORD')
+        record_reader = csv_reader(open(RECORD, 'rb'), delimiter=',')
+        for row in record_reader:
+            path, md5, size = row[:] + [ None for i in xrange(len(row), 3) ]
+            if local:
+                path = path.replace('/', os.sep)
+                path = os.path.join(sys.prefix, path)
+            yield path, md5, size
+
     def get_installed_files(self, local=False):
         """
         Iterates over the RECORD entries and returns a tuple (path, md5, size)
@@ -631,13 +641,8 @@
         :type local: boolean
         :returns: iterator of (path, md5, size)
         """
-        RECORD = os.path.join(self.path, 'RECORD')
-        record_reader = csv_reader(open(RECORD, 'rb'), delimiter=',')
-        for row in record_reader:
-            path, md5, size = row[:] + [ None for i in xrange(len(row), 3) ]
-            if local:
-                path = path.replace('/', os.sep)
-            yield path, md5, size
+        return self._get_records(local)
+
 
     def uses(self, path):
         """
@@ -646,8 +651,9 @@
 
         :rtype: boolean
         """
-        for p, md5, size in self.get_installed_files(local=True):
-            if path == p:
+        for p, md5, size in self._get_records():
+            local_absolute = os.path.join(sys.prefix, p)
+            if path == p or path == local_absolute:
                 return True
         return False
 
@@ -700,7 +706,8 @@
         :type local: boolean
         :returns: iterator of paths
         """
-        pass
+        for path, md5, size in self._get_records(local):
+            yield path
 
 
 def _normalize_dist_name(name):
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
@@ -50,8 +50,8 @@
             for file in ['INSTALLER', 'METADATA', 'REQUESTED']:
                 record_writer.writerow(record_pieces(
                     os.path.join(distinfo_dir, file)))
-            record_writer.writerow([record_file])
-            del record_writer # causes the RECORD to close
+            record_writer.writerow([os.path.relpath(record_file, sys.prefix)])
+            del record_writer # causes the RECORD file to close
             record_reader = csv.reader(open(record_file, 'rb'))
             record_data = []
             for row in record_reader:
@@ -147,6 +147,24 @@
         # Test for a file that does not exist and should not exist
         self.assertRaises(DistutilsError, dist.get_distinfo_file, 'ENTRYPOINTS')
 
+    def test_get_distinfo_files(self):
+        """Test for the iteration of RECORD path entries."""
+        from distutils2._backport.pkgutil import Distribution
+        distinfo_name = 'towel_stuff-0.1'
+        distinfo_dir = os.path.join(self.fake_dists_path,
+            distinfo_name + '.dist-info')
+        dist = Distribution(distinfo_dir)
+        # Test for the iteration of the raw path
+        distinfo_record_paths = self.records[distinfo_dir].keys()
+        found = [ path for path in dist.get_distinfo_files() ]
+        self.assertEqual(sorted(found), sorted(distinfo_record_paths))
+        # Test for the iteration of local absolute paths
+        distinfo_record_paths = [ os.path.join(sys.prefix, path)
+            for path in self.records[distinfo_dir].keys()
+            ]
+        found = [ path for path in dist.get_distinfo_files(local=True) ]
+        self.assertEqual(sorted(found), sorted(distinfo_record_paths))
+
 
 class TestPkgUtilFunctions(unittest2.TestCase):
     """Tests for the new functionality added in PEP 376."""

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


More information about the Python-checkins mailing list