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 = Distribution(distinfo_dir) # Test for known good file matches distinfo_files = [ # Relative paths 'INSTALLER', 'METADATA', # Absolute paths os.path.join(distinfo_dir, 'RECORD'), os.path.join(distinfo_dir, 'REQUESTED'), ] for distfile in distinfo_files: with dist.get_distinfo_file(distfile) as value: self.assertIsInstance(value, io.TextIOWrapper) # Is it the correct file? self.assertEqual(value.name, 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(PackagingError, dist.get_distinfo_file, other_distinfo_file) # Test for a file that should not exist self.assertRaises(PackagingError, 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 = Distribution(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 = Distribution(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 = dist.list_distinfo_files() 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(local=True)) if os.sep != '/': self.assertNotIn('/', found[0]) self.assertIn(os.sep, found[0]) self.assertEqual(found, sorted(distinfo_files))
def test_uses(self): # Test to determine if a distribution uses a specified file. # Criteria to test against distinfo_name = 'grammar-1.0a4' distinfo_dir = os.path.join(self.fake_dists_path, distinfo_name + '.dist-info') true_path = [ self.fake_dists_path, distinfo_name, 'grammar', 'utils.py' ] true_path = os.path.join(*true_path) false_path = [ self.fake_dists_path, 'towel_stuff-0.1', 'towel_stuff', '__init__.py' ] 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), '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))