def test_list_distinfo_files(self): distinfo_name = 'towel_stuff-0.1' distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + '.dist-info') dist = InstalledDistribution(distinfo_dir) # Test for the iteration of the raw path distinfo_files = [ os.path.join(distinfo_dir, filename) for filename in os.listdir(distinfo_dir) ] found = list(dist.list_distinfo_files()) base = self.fake_dists_path for i, p in enumerate(found): if not os.path.isabs(p): found[i] = os.path.join(base, p) self.assertEqual(sorted(found), sorted(distinfo_files)) # Test for the iteration of local absolute paths distinfo_files = [ os.path.join(sys.prefix, distinfo_dir, path) for path in distinfo_files ] found = sorted(dist.list_distinfo_files()) if os.sep != '/': self.assertNotIn('/', found[0]) self.assertIn(os.sep, found[0]) self.assertEqual(found, sorted(distinfo_files))
def test_get_distinfo_file(self): # Test the retrieval of dist-info file objects. distinfo_name = 'choxie-2.0.0.9' other_distinfo_name = 'grammar-1.0a4' distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + '.dist-info') dist = InstalledDistribution(distinfo_dir) # Test for known good file matches distinfo_files = [ # Relative paths 'INSTALLER', METADATA_FILENAME, # Absolute paths os.path.join(distinfo_dir, 'RECORD'), os.path.join(distinfo_dir, 'REQUESTED'), ] for distfile in distinfo_files: value = dist.get_distinfo_file(distfile) self.assertTrue(os.path.isfile(value)) self.assertEqual(value, os.path.join(distinfo_dir, distfile)) # Test an absolute path that is part of another distributions dist-info other_distinfo_file = os.path.join(self.fake_dists_path, other_distinfo_name + '.dist-info', 'REQUESTED') self.assertRaises(DistlibException, dist.get_distinfo_file, other_distinfo_file) # Test for a file that should not exist self.assertRaises(DistlibException, dist.get_distinfo_file, 'MAGICFILE')
def test_get_distinfo_file(self): # Test the retrieval of dist-info file objects. distinfo_name = 'choxie-2.0.0.9' other_distinfo_name = 'grammar-1.0a4' distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + '.dist-info') dist = InstalledDistribution(distinfo_dir) # Test for known good file matches distinfo_files = [ # Relative paths 'INSTALLER', METADATA_FILENAME, # Absolute paths os.path.join(distinfo_dir, 'RECORD'), os.path.join(distinfo_dir, 'REQUESTED'), ] for distfile in distinfo_files: value = dist.get_distinfo_file(distfile) self.assertTrue(os.path.isfile(value)) self.assertEqual(value, os.path.join(distinfo_dir, distfile)) # Test an absolute path that is part of another distributions dist-info other_distinfo_file = os.path.join( self.fake_dists_path, other_distinfo_name + '.dist-info', 'REQUESTED') self.assertRaises(DistlibException, dist.get_distinfo_file, other_distinfo_file) # Test for a file that should not exist self.assertRaises(DistlibException, dist.get_distinfo_file, 'MAGICFILE')
def test_get_resources_path(self): distinfo_name = "babar-0.1" distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + ".dist-info") dist = InstalledDistribution(distinfo_dir) resource_path = dist.get_resource_path("babar.png") self.assertEqual(resource_path, "babar.png") self.assertRaises(KeyError, dist.get_resource_path, "notexist")
def test_get_resources_path(self): distinfo_name = 'babar-0.1' distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + '.dist-info') dist = InstalledDistribution(distinfo_dir) resource_path = dist.get_resource_path('babar.png') self.assertEqual(resource_path, 'babar.png') self.assertRaises(KeyError, dist.get_resource_path, 'notexist')
def test_list_distinfo_files(self): distinfo_name = "towel_stuff-0.1" distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + ".dist-info") dist = InstalledDistribution(distinfo_dir) # Test for the iteration of the raw path distinfo_files = [os.path.join(distinfo_dir, filename) for filename in os.listdir(distinfo_dir)] found = list(dist.list_distinfo_files()) base = self.fake_dists_path for i, p in enumerate(found): if not os.path.isabs(p): found[i] = os.path.join(base, p) self.assertEqual(sorted(found), sorted(distinfo_files)) # Test for the iteration of local absolute paths distinfo_files = [os.path.join(sys.prefix, distinfo_dir, path) for path in distinfo_files] found = sorted(dist.list_distinfo_files()) if os.sep != "/": self.assertNotIn("/", found[0]) self.assertIn(os.sep, found[0]) self.assertEqual(found, sorted(distinfo_files))