Anonymous avatar Anonymous committed d94e869

Fixed more of the record file generation testing. Added the test and functionality for the Distribution.get_distinfo_files method.

Comments (0)

Files changed (2)

src/distutils2/_backport/pkgutil.py

         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)
         :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):
         """
 
         :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
 
         :type local: boolean
         :returns: iterator of paths
         """
-        pass
+        for path, md5, size in self._get_records(local):
+            yield path
 
 
 def _normalize_dist_name(name):

src/distutils2/_backport/tests/test_pkgutil.py

             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:
         # 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."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.