def generate_dist(dist_dir=None, script_name='setup.py'): if dist_dir: current_wd = os.getcwd() os.chdir(dist_dir) try: with tempfile.TemporaryDirectory(prefix='ap_dist') as tmp_dir,\ StringIO() as pkg_info: with patch('sys.stdout', new_callable=StringIO) as mock_stdout: dist = run_setup(script_name, ['sdist', '-d', tmp_dir, 'bdist_wheel', '-d', tmp_dir]) local_locator = DirectoryLocator(tmp_dir) filenames = [Path(urlparse(uri).path) for uri in local_locator.get_project(dist.metadata.name)['digests'].keys()] dist.metadata.write_pkg_file(pkg_info) pkg_info.seek(0) metadata = Metadata(fileobj=pkg_info) yield metadata, filenames finally: if dist_dir: os.chdir(current_wd)
def test_aggregation(self): d = os.path.join(HERE, 'fake_archives') loc1 = DirectoryLocator(d) loc2 = SimpleScrapingLocator('https://pypi.python.org/simple/', timeout=5.0) locator = AggregatingLocator(loc1, loc2) exp1 = os.path.join(HERE, 'fake_archives', 'subdir', 'subsubdir', 'Flask-0.9.tar.gz') exp2 = 'https://pypi.python.org/packages/source/F/Flask/Flask-0.9.tar.gz' result = locator.get_project('flask') self.assertEqual(len(result), 1) self.assertIn('0.9', result) dist = result['0.9'] self.assertEqual(dist.name, 'Flask') self.assertEqual(dist.version, '0.9') scheme, _, path, _, _, _ = urlparse(dist.source_url) self.assertEqual(scheme, 'file') self.assertEqual(os.path.normcase(url2pathname(path)), os.path.normcase(exp1)) locator.merge = True locator._cache.clear() result = locator.get_project('flask') self.assertGreater(len(result), 1) self.assertIn('0.9', result) dist = result['0.9'] self.assertEqual(dist.name, 'Flask') self.assertEqual(dist.version, '0.9') self.assertEqual(dist.source_url, exp2) return # The following code is slow because it has # to get all the dist names by scraping :-( n1 = loc1.get_distribution_names() n2 = loc2.get_distribution_names() self.assertEqual(locator.get_distribution_names(), n1 | n2)
def test_aggregation(self): d = os.path.join(HERE, "fake_archives") loc1 = DirectoryLocator(d) loc2 = SimpleScrapingLocator("https://pypi.python.org/simple/", timeout=5.0) locator = AggregatingLocator(loc1, loc2) exp1 = os.path.join(HERE, "fake_archives", "subdir", "subsubdir", "Flask-0.9.tar.gz") exp2 = "/Flask-0.9.tar.gz" result = locator.get_project("flask") self.assertEqual(len(result), 3) self.assertIn("0.9", result) dist = result["0.9"] self.assertEqual(dist.name, "Flask") self.assertEqual(dist.version, "0.9") scheme, _, path, _, _, _ = urlparse(dist.source_url) self.assertEqual(scheme, "file") self.assertEqual(os.path.normcase(url2pathname(path)), os.path.normcase(exp1)) locator.merge = True locator._cache.clear() result = locator.get_project("flask") self.assertGreater(len(result), 3) self.assertIn("0.9", result) dist = result["0.9"] self.assertEqual(dist.name, "Flask") self.assertEqual(dist.version, "0.9") self.assertTrue(dist.source_url.endswith(exp2)) return # The following code is slow because it has # to get all the dist names by scraping :-( n1 = loc1.get_distribution_names() n2 = loc2.get_distribution_names() self.assertEqual(locator.get_distribution_names(), n1 | n2)
def test_aggregation(self): d = os.path.join(HERE, 'fake_archives') loc1 = DirectoryLocator(d) loc2 = SimpleScrapingLocator('https://pypi.python.org/simple/', timeout=5.0) locator = AggregatingLocator(loc1, loc2) exp1 = os.path.join(HERE, 'fake_archives', 'subdir', 'subsubdir', 'Flask-0.9.tar.gz') exp2 = '/Flask-0.9.tar.gz' result = locator.get_project('flask') self.assertEqual(len(result), 3) self.assertIn('0.9', result) dist = result['0.9'] self.assertEqual(dist.name, 'Flask') self.assertEqual(dist.version, '0.9') scheme, _, path, _, _, _ = urlparse(dist.source_url) self.assertEqual(scheme, 'file') self.assertEqual(os.path.normcase(url2pathname(path)), os.path.normcase(exp1)) locator.merge = True locator._cache.clear() result = locator.get_project('flask') self.assertGreater(len(result), 3) self.assertIn('0.9', result) dist = result['0.9'] self.assertEqual(dist.name, 'Flask') self.assertEqual(dist.version, '0.9') self.assertTrue(dist.source_url.endswith(exp2)) return # The following code is slow because it has # to get all the dist names by scraping :-( n1 = loc1.get_distribution_names() n2 = loc2.get_distribution_names() self.assertEqual(locator.get_distribution_names(), n1 | n2)
def test_dir_nonrecursive(self): d = os.path.join(HERE, "fake_archives") locator = DirectoryLocator(d, recursive=False) expected = os.path.join(HERE, "fake_archives", "subdir", "subsubdir", "Flask-0.9.tar.gz") def get_path(url): t = urlparse(url) return url2pathname(t.path) for name in ("flask", "Flask"): result = locator.get_project(name) self.assertEqual(result, {"urls": {}, "digests": {}}) names = locator.get_distribution_names() expected = set(["coverage"]) self.assertEqual(names, expected)
def test_dir_nonrecursive(self): d = os.path.join(HERE, 'fake_archives') locator = DirectoryLocator(d, recursive=False) expected = os.path.join(HERE, 'fake_archives', 'subdir', 'subsubdir', 'Flask-0.9.tar.gz') def get_path(url): t = urlparse(url) return url2pathname(t.path) for name in ('flask', 'Flask'): result = locator.get_project(name) self.assertEqual(result, {}) names = locator.get_distribution_names() expected = set(['coverage']) self.assertEqual(names, expected)
def test_dir_nonrecursive(self): d = os.path.join(HERE, 'fake_archives') locator = DirectoryLocator(d, recursive=False) expected = os.path.join(HERE, 'fake_archives', 'subdir', 'subsubdir', 'Flask-0.9.tar.gz') def get_path(url): t = urlparse(url) return url2pathname(t.path) for name in ('flask', 'Flask'): result = locator.get_project(name) self.assertEqual(result, {'urls': {}, 'digests': {}}) names = locator.get_distribution_names() expected = set(['coverage']) self.assertEqual(names, expected)
def test_dir(self): d = os.path.join(HERE, "fake_archives") locator = DirectoryLocator(d) expected = os.path.join(HERE, "fake_archives", "subdir", "subsubdir", "Flask-0.9.tar.gz") def get_path(url): t = urlparse(url) return url2pathname(t.path) for name in ("flask", "Flask"): result = locator.get_project(name) self.assertIn("0.9", result) dist = result["0.9"] self.assertEqual(dist.name, "Flask") self.assertEqual(dist.version, "0.9") self.assertEqual(os.path.normcase(get_path(dist.source_url)), os.path.normcase(expected)) names = locator.get_distribution_names() expected = set(["Flask", "python-gnupg", "coverage", "Django"]) if sys.version_info[:2] == (2, 7): expected.add("config") self.assertEqual(names, expected)
def test_dir(self): d = os.path.join(HERE, 'fake_archives') locator = DirectoryLocator(d) expected = os.path.join(HERE, 'fake_archives', 'subdir', 'subsubdir', 'Flask-0.9.tar.gz') def get_path(url): t = urlparse(url) return url2pathname(t.path) for name in ('flask', 'Flask'): result = locator.get_project(name) self.assertIn('0.9', result) dist = result['0.9'] self.assertEqual(dist.name, 'Flask') self.assertEqual(dist.version, '0.9') self.assertEqual(os.path.normcase(get_path(dist.source_url)), os.path.normcase(expected)) names = locator.get_distribution_names() expected = set(['Flask', 'python-gnupg', 'coverage', 'Django']) if sys.version_info[:2] == (2, 7): expected.add('config') self.assertEqual(names, expected)