def test_extract_to(self): # Given path = NOSE_1_3_0 arcname = "EGG-INFO/PKG-INFO" # When with mkdtemp() as d: with ZipFile(path) as zp: zp.extract_to(arcname, "FOO", d) extracted_data = zp.read(arcname) self.assertTrue(os.path.exists(os.path.join(d, "FOO"))) self.assertEqual(compute_md5(os.path.join(d, "FOO")), compute_md5(BytesIO(extracted_data))) self.assertFalse( os.path.exists(os.path.join(d, "EGG-INFO", "PKG-INFO")))
def test_repair_file(self): # Given egg_path = DUMMY_EGG self._install_egg_file_egg_info_dir(egg_path) # When fixer = EggInfoDirFixer(egg_path, prefix=self.prefix) old_egg_info_file_md5 = compute_md5(fixer.egg_info_dir) fixer.repair() # Then assertCountEqual(self, os.listdir(fixer.egg_info_dir), ["PKG-INFO", "egginst.json", "_info.json"]) self.assertEqual(compute_md5(os.path.join(fixer.egg_info_dir, "PKG-INFO")), old_egg_info_file_md5)
def test_simple(self): # Given source = os.path.join(self.tempdir, "source.data") self._write_content(source, b"data") # When target = os.path.join(self.tempdir, "target.data") with open(target, "wb") as _fp: fp = Checksummer(_fp, hashlib.md5()) fp.write(b"data") # Then self.assertEqual(fp.hexdigest(), compute_md5(target)) self.assertEqual(compute_md5(target), compute_md5(source)) self.assertEqual(fp.digest(), hashlib.md5(b"data").digest())
def test_extract_to(self): # Given path = NOSE_1_3_0 arcname = "EGG-INFO/PKG-INFO" # When with mkdtemp() as d: with ZipFile(path) as zp: zp.extract_to(arcname, "FOO", d) extracted_data = zp.read(arcname) self.assertTrue(os.path.exists(os.path.join(d, "FOO"))) self.assertEqual(compute_md5(os.path.join(d, "FOO")), compute_md5(BytesIO(extracted_data))) self.assertFalse(os.path.exists(os.path.join(d, "EGG-INFO", "PKG-INFO")))
def test_find_package(self): # Given path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg") # When metadata = self.repository.find_package("nose", "1.3.0-1") # Then self.assertEqual(metadata.key, "nose-1.3.0-1.egg") self.assertEqual(metadata.name, "nose") self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1")) self.assertEqual(metadata.packages, []) self.assertEqual(metadata.python, "2.7") self.assertEqual(metadata.available, True) self.assertEqual(metadata.store_location, "{0}/".format(path_to_uri(_EGGINST_COMMON_DATA))) self.assertEqual(metadata.size, os.path.getsize(path)) self.assertEqual(metadata.md5, compute_md5(path)) # Given path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-2.egg") # When metadata = self.repository.find_package("nose", "1.3.0-2") # Then self.assertEqual(metadata.key, "nose-1.3.0-2.egg") self.assertEqual(metadata.name, "nose") self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-2"))
def test_simple(self): # Given filename = "nose-1.3.0-1.egg" path = os.path.join(_EGGINST_COMMON_DATA, filename) downloader, repository = self._downloader_factory([path]) self._add_response_for_path(path) # When action = FetchAction(path, downloader, repository) action.execute() # Then target = os.path.join(downloader.cache_directory, filename) self.assertTrue(os.path.exists(target)) self.assertEqual(compute_md5(target), compute_md5(path)) self.assertFalse(action.is_canceled)
def needs_to_download(self): needs_to_download = True if isfile(self._path): if self._force: if compute_md5(self._path) == self._package_metadata.md5: logger.info("Not refetching, %r MD5 match", self._path) needs_to_download = False else: logger.info("Not forcing refetch, %r exists", self._path) needs_to_download = False return needs_to_download
def _needs_to_download(self, package_metadata, force): needs_to_download = True path = self._path(package_metadata.key) if isfile(path): if force: if compute_md5(path) == package_metadata.md5: logger.info("Not refetching, %r MD5 match", path) needs_to_download = False else: logger.info("Not forcing refetch, %r exists", path) needs_to_download = False return needs_to_download
def test_proxy(self): """ Test we handle correctly entries of the form 'path PROXY'. """ r_python_proxy_data_template = """\ #!"%(executable)s" # This proxy was created by egginst from an egg with special instructions # import sys import subprocess src = %(src)r sys.exit(subprocess.call([src] + sys.argv[1:])) """ with mkdtemp() as prefix: pythonexe = os.path.join(prefix, "python.exe") proxy_path = os.path.join( prefix, "EGG-INFO", "dummy_with_proxy", "usr", "swig.exe" ) if PY2: proxy_path = proxy_path.decode("utf8") r_python_proxy_data = r_python_proxy_data_template % \ {'executable': pythonexe, 'src': proxy_path} runtime_info = self._runtime_info_factory(prefix) egginst = EggInst(DUMMY_EGG_WITH_PROXY, runtime_info=runtime_info) with ZipFile(egginst.path) as zp: egginst.z = zp egginst.arcnames = zp.namelist() create_proxies(egginst, pythonexe) python_proxy = os.path.join(prefix, "Scripts", "swig-script.py") coff_proxy = os.path.join(prefix, "Scripts", "swig.exe") self.assertTrue(os.path.exists(python_proxy)) self.assertTrue(os.path.exists(coff_proxy)) self.assertTrue(compute_md5(coff_proxy), hashlib.md5(exe_data.cli).hexdigest()) with open(python_proxy, "rt") as fp: python_proxy_data = fp.read() self.assertMultiLineEqual(python_proxy_data, r_python_proxy_data)
def test_proxy(self): """ Test we handle correctly entries of the form 'path PROXY'. """ r_python_proxy_data_template = """\ #!"%(executable)s" # This proxy was created by egginst from an egg with special instructions # import sys import subprocess src = %(src)r sys.exit(subprocess.call([src] + sys.argv[1:])) """ with mkdtemp() as prefix: with mock.patch("sys.executable", os.path.join(prefix, "python.exe")): proxy_path = os.path.join(prefix, "EGG-INFO", "dummy_with_proxy", "usr", "swig.exe") if PY2: proxy_path = proxy_path.decode("utf8") r_python_proxy_data = r_python_proxy_data_template % \ {'executable': os.path.join(prefix, "python.exe"), 'src': proxy_path} egginst = EggInst(DUMMY_EGG_WITH_PROXY, prefix) with ZipFile(egginst.path) as zp: egginst.z = zp egginst.arcnames = zp.namelist() create_proxies(egginst) python_proxy = os.path.join(prefix, "Scripts", "swig-script.py") coff_proxy = os.path.join(prefix, "Scripts", "swig.exe") self.assertTrue(os.path.exists(python_proxy)) self.assertTrue(os.path.exists(coff_proxy)) self.assertTrue(compute_md5(coff_proxy), hashlib.md5(exe_data.cli).hexdigest()) with open(python_proxy, "rt") as fp: python_proxy_data = fp.read() self.assertMultiLineEqual(python_proxy_data, r_python_proxy_data)
def info_file(path): return dict(size=getsize(path), mtime=getmtime(path), md5=compute_md5(path))
def test_simple_windows(self): python_executable = "C:\\Python27\\python.exe" pythonw_executable = "C:\\Python27\\pythonw.exe" r_cli_entry_point = """\ #!"{executable}" # This script was created by egginst when installing: # # dummy.egg # if __name__ == '__main__': import sys from dummy import main_cli sys.exit(main_cli()) """.format(executable=python_executable) r_gui_entry_point = """\ #!"{executable}" # This script was created by egginst when installing: # # dummy.egg # if __name__ == '__main__': import sys from dummy import main_gui sys.exit(main_gui()) """.format(executable=pythonw_executable) entry_points = """\ [console_scripts] dummy = dummy:main_cli [gui_scripts] dummy-gui = dummy:main_gui """ s = StringIO(entry_points) config = configparser.ConfigParser() config.readfp(s) with mock.patch("sys.executable", python_executable): with mkdtemp() as d: egginst = EggInst("dummy.egg", d) create(egginst, config) cli_entry_point_path = os.path.join(egginst.bin_dir, "dummy-script.py") gui_entry_point_path = os.path.join(egginst.bin_dir, "dummy-gui-script.pyw") entry_points = [ os.path.join(egginst.bin_dir, "dummy.exe"), os.path.join(egginst.bin_dir, "dummy-gui.exe"), cli_entry_point_path, gui_entry_point_path, ] for entry_point in entry_points: self.assertTrue(os.path.exists(entry_point)) with open(cli_entry_point_path, "rt") as fp: cli_entry_point = fp.read() self.assertMultiLineEqual(cli_entry_point, r_cli_entry_point) with open(gui_entry_point_path, "rt") as fp: gui_entry_point = fp.read() self.assertMultiLineEqual(gui_entry_point, r_gui_entry_point) self.assertEqual(compute_md5(os.path.join(egginst.bin_dir, "dummy.exe")), hashlib.md5(exe_data.cli).hexdigest()) self.assertEqual(compute_md5(os.path.join(egginst.bin_dir, "dummy-gui.exe")), hashlib.md5(exe_data.gui).hexdigest())
def test_simple_windows(self): python_executable = "C:\\Python27\\python.exe" pythonw_executable = "C:\\Python27\\pythonw.exe" r_cli_entry_point = """\ #!"{executable}" # This script was created by egginst when installing: # # dummy.egg # if __name__ == '__main__': import sys from dummy import main_cli sys.exit(main_cli()) """.format(executable=python_executable) r_gui_entry_point = """\ #!"{executable}" # This script was created by egginst when installing: # # dummy.egg # if __name__ == '__main__': import sys from dummy import main_gui sys.exit(main_gui()) """.format(executable=pythonw_executable) entry_points = """\ [console_scripts] dummy = dummy:main_cli [gui_scripts] dummy-gui = dummy:main_gui """ s = StringIO(entry_points) config = configparser.ConfigParser() config.readfp(s) with mkdtemp() as d: egginst = EggInst("dummy.egg", d) create_entry_points(egginst, config, python_executable) cli_entry_point_path = os.path.join(egginst.scriptsdir, "dummy-script.py") gui_entry_point_path = os.path.join(egginst.scriptsdir, "dummy-gui-script.pyw") entry_points = [ os.path.join(egginst.scriptsdir, "dummy.exe"), os.path.join(egginst.scriptsdir, "dummy-gui.exe"), cli_entry_point_path, gui_entry_point_path, ] for entry_point in entry_points: self.assertTrue(os.path.exists(entry_point)) with open(cli_entry_point_path, "rt") as fp: cli_entry_point = fp.read() self.assertMultiLineEqual(cli_entry_point, r_cli_entry_point) with open(gui_entry_point_path, "rt") as fp: gui_entry_point = fp.read() self.assertMultiLineEqual(gui_entry_point, r_gui_entry_point) self.assertEqual(compute_md5(os.path.join(egginst.scriptsdir, "dummy.exe")), hashlib.md5(exe_data.cli).hexdigest()) self.assertEqual(compute_md5(os.path.join(egginst.scriptsdir, "dummy-gui.exe")), hashlib.md5(exe_data.gui).hexdigest())