diff options
| author | ?ric Araujo <merwok@netwok.org> | 2011-09-18 21:12:17 +0200 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2011-09-18 21:12:17 +0200 |
| commit | 1bb0a13680fd66125da0167c8f4a7a4f9c71555d (patch) | |
| tree | dec4d99c8468dece407a5424da74eb86f6d9d12c /distutils2/tests | |
| parent | 0555ed6a05c59e22963c0c1d931f7fcfa284f04f (diff) | |
| download | disutils2-1bb0a13680fd66125da0167c8f4a7a4f9c71555d.tar.gz | |
Fix database.Distribution.list_distinfo_files (#12785).
This method was supposed to return only the file under the dist-info
directory, but it actually returned all installed files.
The tests didn?t catch this because they were flawed; I updated them.
Diffstat (limited to 'distutils2/tests')
| -rw-r--r-- | distutils2/tests/test_database.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/distutils2/tests/test_database.py b/distutils2/tests/test_database.py index 2d6a30e..e524306 100644 --- a/distutils2/tests/test_database.py +++ b/distutils2/tests/test_database.py @@ -4,10 +4,6 @@ import sys import shutil import tempfile try: - from os.path import relpath # separate import for backport concerns -except: - from distutils2._backport.path import relpath -try: from hashlib import md5 except ImportError: from distutils2._backport.hashlib import md5 @@ -40,11 +36,11 @@ def get_hexdigest(filename): return checksum.hexdigest() -def record_pieces(file): - path = relpath(file, sys.prefix) - digest = get_hexdigest(file) - size = os.path.getsize(file) - return [path, digest, size] +def record_pieces(path): + path = os.path.join(*path) + digest = get_hexdigest(path) + size = os.path.getsize(path) + return path, digest, size class FakeDistsMixin(object): @@ -58,7 +54,8 @@ class FakeDistsMixin(object): # distributions tmpdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmpdir) - self.fake_dists_path = os.path.join(tmpdir, 'fake_dists') + self.fake_dists_path = os.path.realpath( + os.path.join(tmpdir, 'fake_dists')) fake_dists_src = os.path.abspath( os.path.join(os.path.dirname(__file__), 'fake_dists')) shutil.copytree(fake_dists_src, self.fake_dists_path) @@ -151,12 +148,10 @@ class TestDistribution(CommonDistributionTests, unittest.TestCase): for path, dirs, files in os.walk(dist_location): for f in files: - record_writer.writerow(record_pieces( - os.path.join(path, f))) + record_writer.writerow(record_pieces((path, f))) for file in ('INSTALLER', 'METADATA', 'REQUESTED'): - record_writer.writerow(record_pieces( - os.path.join(distinfo_dir, file))) - record_writer.writerow([relpath(record_file, sys.prefix)]) + record_writer.writerow(record_pieces((distinfo_dir, file))) + record_writer.writerow([record_file]) finally: fp.close() @@ -186,15 +181,17 @@ class TestDistribution(CommonDistributionTests, unittest.TestCase): distinfo_name + '.dist-info') true_path = [self.fake_dists_path, distinfo_name, 'grammar', 'utils.py'] - true_path = relpath(os.path.join(*true_path), sys.prefix) + true_path = os.path.join(*true_path) false_path = [self.fake_dists_path, 'towel_stuff-0.1', 'towel_stuff', '__init__.py'] - false_path = relpath(os.path.join(*false_path), sys.prefix) + false_path = os.path.join(*false_path) # Test if the distribution uses the file in question dist = Distribution(distinfo_dir) - self.assertTrue(dist.uses(true_path)) - self.assertFalse(dist.uses(false_path)) + self.assertTrue(dist.uses(true_path), 'dist %r is supposed to use %r' % + (dist, true_path)) + self.assertFalse(dist.uses(false_path), 'dist %r is not supposed to ' + 'use %r' % (dist, true_path)) def test_get_distinfo_file(self): # Test the retrieval of dist-info file objects. @@ -233,20 +230,23 @@ class TestDistribution(CommonDistributionTests, unittest.TestCase): 'MAGICFILE') def test_list_distinfo_files(self): - # Test for the iteration of RECORD path entries. 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() + distinfo_files = [os.path.join(distinfo_dir, filename) for filename in + os.listdir(distinfo_dir)] found = dist.list_distinfo_files() - self.assertEqual(sorted(found), sorted(distinfo_record_paths)) + self.assertEqual(sorted(found), sorted(distinfo_files)) # Test for the iteration of local absolute paths - distinfo_record_paths = [os.path.join(sys.prefix, path) - for path in self.records[distinfo_dir]] - found = dist.list_distinfo_files(local=True) - self.assertEqual(sorted(found), sorted(distinfo_record_paths)) + distinfo_files = [os.path.join(sys.prefix, distinfo_dir, path) for + path in distinfo_files] + found = sorted(dist.list_distinfo_files(local=True)) + if os.sep != '/': + self.assertNotIn('/', found[0]) + self.assertIn(os.sep, found[0]) + self.assertEqual(found, sorted(distinfo_files)) def test_get_resources_path(self): distinfo_name = 'babar-0.1' |
