def test_get_installed(self): r_installed_eggs = sorted([ os.path.basename(DUMMY_EGG), os.path.basename(DUMMY_EGG_WITH_ENTRY_POINTS), ]) with mkdtemp() as d: egginst = EggInst(DUMMY_EGG, d) egginst.install() egginst = EggInst(DUMMY_EGG_WITH_ENTRY_POINTS, d) egginst.install() installed_eggs = list(get_installed(d)) self.assertEqual(installed_eggs, r_installed_eggs)
def test_custom_egg_with_usr_files_remove(self): egg = NOSE_1_3_0 with assert_same_fs(self, self.base_dir): egginst = EggInst(egg, self.base_dir) egginst.install() egginst.remove()
def test_custom_egg_with_usr_files(self): custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO", "nose") egg_info_base = os.path.join(self.site_packages, "nose-{0}.egg-info".format("1.3.0-1")) egg = NOSE_1_3_0 egginst = EggInst(egg, self.base_dir) egginst.install() # Check for files installed in $prefix/EGG-INFO for f in DUMMY_EGG_METADATA_FILES: path = os.path.join(custom_egg_info_base, f) self.assertTrue(os.path.exists(path)) # Check for files installed in $site-packages/$package_egg_info-INFO path = os.path.join(egg_info_base, "PKG-INFO") self.assertTrue(os.path.exists(path)) path = os.path.join(egg_info_base, "spec/depend") self.assertFalse(os.path.exists(path)) path = os.path.join(egg_info_base, "spec/summary") self.assertFalse(os.path.exists(path)) path = os.path.join(egg_info_base, "usr/share/man/man1/nosetests.1") self.assertFalse(os.path.exists(path))
def test_simple_custom_egg_remove(self): egg = DUMMY_EGG with assert_same_fs(self, self.base_dir): egginst = EggInst(egg, self.base_dir) egginst.install() egginst.remove()
def test_custom_egg_legacy_egg_info_remove(self): egg = LEGACY_EGG_INFO_EGG with assert_same_fs(self, self.base_dir): egginst = EggInst(egg, self.base_dir) egginst.install() egginst.remove()
def test_old_appinst(self): """ Test that we still work with old (<= 2.1.1) appinst, where [un]install_from_dat only takes one argument (no prefix). """ egg_path = DUMMY_EGG_WITH_APPINST appinst_path = os.path.join(self.meta_dir, "dummy_with_appinst", eggmeta.APPINST_PATH) egginst = EggInst(egg_path, self.base_dir) def mocked_old_install_from_dat(x): pass def mocked_old_uninstall_from_dat(x): pass # XXX: we use autospec to enforce function taking exactly one argument, # otherwise the proper TypeError exception is not raised when calling # it with two arguments, which is how old vs new appinst is detected. with mock.patch("appinst.install_from_dat", autospec=mocked_old_install_from_dat) as m: egginst.install() m.assert_called_with(appinst_path) with mock.patch("appinst.uninstall_from_dat", autospec=mocked_old_uninstall_from_dat) as m: egginst.remove() m.assert_called_with(appinst_path)
def test_find_lib_with_targets(self): def _compute_target_list(path, d): # FIXME: we need this hack as the internal EggInst zipfile # object is only available within an EggInst.install call. egg_inst = EggInst(path, d) egg_inst.z = zp return _compute_targets(egg_inst.iter_targets(), egg_inst.prefix) # Given with _zipfile.ZipFile(DUMMY_EGG_WITH_INST_TARGETS) as zp: egg_inst = EggInst(DUMMY_EGG_WITH_INST_TARGETS, self.prefix) egg_inst.install() targets = _compute_target_list(DUMMY_EGG_WITH_INST_TARGETS, self.prefix) path = "libfoo.dylib" r_found_lib = os.path.join(self.prefix, "lib", "foo-4.2", path) # When found_lib = _find_lib(path, targets) # Then self.assertEqual(found_lib, r_found_lib)
def _compute_target_list(path, d): # FIXME: we need this hack as the internal EggInst zipfile # object is only available within an EggInst.install call. egg_inst = EggInst(path, d) egg_inst.z = zp return _compute_targets(egg_inst.iter_targets(), egg_inst.prefix)
def test_symlink(self): """Test installing an egg with softlink in it.""" # Given if sys.platform == "win32": incdir = os.path.join(self.prefix, "EGG-INFO", "foo", "usr", "include") header = os.path.join(incdir, "foo.h") link = os.path.join(self.prefix, "EGG-INFO", "foo", "usr", "HEADERS") else: incdir = os.path.join(self.prefix, "include") header = os.path.join(incdir, "foo.h") link = os.path.join(self.prefix, "HEADERS") egg_filename = os.path.join(self.base_dir, "foo-1.0.egg") _create_egg_with_symlink(egg_filename, "foo") # When installer = EggInst(egg_filename, prefix=self.prefix) installer.install() # Then self.assertTrue(os.path.exists(header)) self.assertTrue(os.path.exists(link)) self.assertTrue(os.path.islink(link)) self.assertEqual(os.readlink(link), "include") self.assertTrue(os.path.exists(os.path.join(link, "foo.h")))
def test_softlink_with_broken_entry(self): # Given path = VTK_EGG_DEFERRED_SOFTLINK # When installer = EggInst(path, prefix=self.prefix) installer.install()
def test_custom_egg_legacy_egg_info(self): custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO", "flake8") egg_info_base = os.path.join(self.site_packages, "flake8-2.0.0-2.egg-info") legacy_egg_info_base = os.path.join(self.site_packages, "flake8.egg-info") custom_metadata = ("PKG-INFO.bak", "requires.txt", "spec/depend", "spec/summary") egg = LEGACY_EGG_INFO_EGG egginst = EggInst(egg, self.base_dir) egginst.install() # Check for files installed in $prefix/EGG-INFO for f in custom_metadata: path = os.path.join(custom_egg_info_base, f) self.assertTrue(os.path.exists(path)) # Check for files installed in $site-packages/$package_egg_info-INFO for f in LEGACY_EGG_INFO_EGG_METADATA_FILES: path = os.path.join(egg_info_base, f) self.assertTrue(os.path.exists(path)) for f in LEGACY_EGG_INFO_EGG_METADATA_FILES: path = os.path.join(legacy_egg_info_base, f) self.assertFalse(os.path.exists(path))
def test_standard_egg_remove(self): egg = STANDARD_EGG with assert_same_fs(self, self.base_dir): egginst = EggInst(egg, self.base_dir) egginst.install() egginst.remove()
def _install_egg_empty_egg_info_dir(self, egg_path): installer = EggInst(egg_path, prefix=self.prefix) installer.install() egg_info_dir = os.path.join(installer.site_packages, setuptools_egg_info_dir(egg_path)) shutil.rmtree(egg_info_dir) os.makedirs(egg_info_dir)
def _install_egg_file_egg_info_dir(self, egg_path): installer = EggInst(egg_path, prefix=self.prefix) installer.install() egg_info_dir = os.path.join(installer.site_packages, setuptools_egg_info_dir(egg_path)) shutil.rmtree(egg_info_dir) with open(egg_info_dir, "w") as fp: fp.write("")
def test_simple(self): egginst = EggInst(DUMMY_EGG, self.base_dir) egginst.install() self.assertTrue( os.path.exists(os.path.join(self.site_packages, "dummy.py"))) egginst.remove() self.assertFalse( os.path.exists(os.path.join(self.site_packages, "dummy.py")))
def test_chained_override_update(self): """ Test update to package with latest version in lower prefix but an older version in primary prefix. """ # Given l0_egg = NOSE_1_3_0 l1_egg = NOSE_1_2_1 expected_actions = [ ('remove', os.path.basename(l1_egg)), ('install', os.path.basename(l0_egg)), ] entries = [ dummy_repository_package_factory( *split_eggname(os.path.basename(l0_egg))), ] repository = repository_factory(entries) l0 = os.path.join(self.prefix, 'l0') l1 = os.path.join(self.prefix, 'l1') makedirs(l0) makedirs(l1) # Install latest version in l0 EggInst(l0_egg, l0).install() # Install older version in l1 EggInst(l1_egg, l1).install() repository = repository_factory(entries) installed_repository = Repository._from_prefixes([l1]) solver = Solver(repository, installed_repository) request = Request() request.install(Requirement("nose")) # When actions = solver.resolve(request) # Then self.assertListEqual(actions, expected_actions)
def test_simple_(self): # Given remover = EggInst(DUMMY_EGG, self.prefix) # When with testfixtures.LogCapture() as logger: remover.remove() # Then logger.check(('egginst.main', 'ERROR', "Error: Can't find meta data for: 'dummy'"))
def test_enstaller_no_placeholder_hack(self): # Given path = _create_dummy_enstaller_egg(self.base_dir) # When with mock.patch("egginst.main.object_code.apply_placeholder_hack") \ as m: installer = EggInst(path, prefix=self.prefix) installer.install() # Then self.assertFalse(m.called)
def test_simple(self): # Given path = DUMMY_EGG with mkdtemp() as tempdir: create_venv(tempdir) installer = EggInst(path, prefix=tempdir) installer.install() # When freeze_list = get_freeze_list([tempdir]) self.assertEqual(freeze_list, ["dummy 1.0.1-1"])
def test_without_appinst(self): """ Test egginst does not crash when appinst is not available and we try installing eggs using appinst """ egg_path = DUMMY_EGG_WITH_APPINST egginst = EggInst(egg_path, self.base_dir) with mock.patch("egginst.main.appinst", None): egginst.install() egginst.remove()
def iter_execute(self): extra_info = self._extract_extra_info() installer = EggInst(self._egg_path, prefix=self._top_prefix) self._progress = self._progress_factory(installer.fn, installer.installed_size) with self._progress: for step in installer.install_iterator(extra_info): yield step self._post_install()
def test_simple(self): r_link = "libfoo.so" r_source = "libfoo.so.0.0.0" with mkdtemp() as d: egginst = EggInst(DUMMY_EGG_WITH_PROXY_SOFTLINK, d) egginst.install() link = os.path.join(d, "lib", r_link) source = os.path.join(d, "lib", r_source) self.assertTrue(os.path.exists(link)) self.assertTrue(os.path.exists(source)) self.assertTrue(os.path.islink(link)) self.assertEqual(os.readlink(link), os.path.basename(source))
def test_from_prefix(self): # Given path = DUMMY_EGG with mkdtemp() as tempdir: create_venv(tempdir) installer = EggInst(path, prefix=tempdir) installer.install() # When repository = Repository._from_prefixes([tempdir]) # Then packages = repository.find_packages("dummy") self.assertEqual(len(packages), 1) self.assertEqual(packages[0].name, "dummy")
def test_appinst_failed(self): """ Test egginst does not crash when appinst is not available and we try installing eggs using appinst """ egg_path = DUMMY_EGG_WITH_APPINST egginst = EggInst(egg_path, self.base_dir) with mock.patch("egginst.main.appinst.install_from_dat", side_effect=ValueError): egginst.install() with mock.patch("egginst.main.appinst.uninstall_from_dat", side_effect=ValueError): egginst.remove()
def test_appinst(self): """ Test we install appinst bits correctly. """ egg_path = DUMMY_EGG_WITH_APPINST appinst_path = os.path.join(self.meta_dir, "dummy_with_appinst", eggmeta.APPINST_PATH) egginst = EggInst(egg_path, self.base_dir) with mock.patch("appinst.install_from_dat", autospec=True) as m: egginst.install() m.assert_called_with(appinst_path, self.base_dir) with mock.patch("appinst.uninstall_from_dat", autospec=True) as m: egginst.remove() m.assert_called_with(appinst_path, self.base_dir)
def test_remove_actions(self): # Given repository = Repository() for egg in [DUMMY_EGG]: egginst = EggInst(egg, self.prefix) egginst.install() solver = Solver(repository, Repository._from_prefixes([self.prefix])) request = Request() request.remove(Requirement("dummy")) # When actions = solver.resolve(request) # Then self.assertEqual(actions, [("remove", os.path.basename(DUMMY_EGG))])
def test_proxy_directory(self): """ Test we handle correctly entries of the form 'path some_directory'. """ with mkdtemp() as prefix: with mock.patch("sys.executable", os.path.join(prefix, "python.exe")): egginst = EggInst(DUMMY_EGG_WITH_PROXY_SCRIPTS, prefix) with ZipFile(egginst.path) as zp: egginst.z = zp egginst.arcnames = zp.namelist() create_proxies(egginst) proxied_files = [ os.path.join(prefix, "Scripts", "dummy.dll"), os.path.join(prefix, "Scripts", "dummy.lib"), ] for proxied_file in proxied_files: self.assertTrue(os.path.exists(proxied_file))
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 test_entry_points(self): """ Test we install console entry points correctly. """ py_script = os.path.join(self.site_packages, "dummy.py") if sys.platform == "win32": wrapper_script = os.path.join(self.bindir, "dummy.exe") else: wrapper_script = os.path.join(self.bindir, "dummy") egginst = EggInst(DUMMY_EGG_WITH_ENTRY_POINTS, self.base_dir) egginst.install() self.assertTrue(os.path.exists(py_script)) self.assertTrue(os.path.exists(wrapper_script)) egginst.remove() self.assertFalse(os.path.exists(py_script)) self.assertFalse(os.path.exists(wrapper_script))
def iter_execute(self): installer = EggInst(self._egg, self._top_prefix, False) remover = installer._egginst_remover if not remover.is_installed: logger.error("Error: can't find meta data for: %r", remover.cname) return name, version = egg_name_to_name_version(self._egg) package = self._top_installed_repository.find_package(name, version) self._progress = self._progress_factory(installer.fn, remover.installed_size, len(remover.files)) with self._progress: for filename in remover.remove_iterator(): yield 1 self._top_installed_repository.delete_package(package) self._installed_repository.delete_package(package)