Beispiel #1
0
    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()
Beispiel #2
0
    def test_softlink_with_broken_entry(self):
        # Given
        path = VTK_EGG_DEFERRED_SOFTLINK

        # When
        installer = EggInst(path, prefix=self.prefix)
        installer.install()
Beispiel #3
0
    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))
Beispiel #4
0
        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)
Beispiel #5
0
    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)
Beispiel #6
0
    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))
Beispiel #7
0
    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()
Beispiel #8
0
    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))
Beispiel #9
0
    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")))
Beispiel #10
0
    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))
Beispiel #11
0
    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()
Beispiel #12
0
    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")))
Beispiel #13
0
    def test_softlink_with_broken_entry(self):
        # Given
        path = VTK_EGG_DEFERRED_SOFTLINK

        # When
        installer = EggInst(path, prefix=self.prefix)
        installer.install()
Beispiel #14
0
    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)
Beispiel #15
0
        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)
Beispiel #16
0
    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")))
Beispiel #17
0
    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)
Beispiel #18
0
    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)
Beispiel #20
0
    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 _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("")
Beispiel #22
0
    def test_custom_egg_with_usr_files_remove(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

        with assert_same_fs(self, self.base_dir):
            egginst = EggInst(egg, self.base_dir)
            egginst.install()
            egginst.remove()
Beispiel #23
0
    def test_find_lib_with_targets(self):
        """
        Test we handle the targets.dat hack correctly in find_lib.
        """
        with mkdtemp() as d:
            with mock.patch("egginst.object_code._targets", []):
                egg_inst = EggInst(DUMMY_EGG_WITH_INST_TARGETS, d)
                egg_inst.install()

                path = "libfoo.dylib"
                self.assertEqual(find_lib(path), op.join(d, "lib", "foo-4.2", path))
Beispiel #24
0
    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'"))
Beispiel #25
0
    def test_custom_egg_legacy_egg_info_remove(self):
        custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO", "flake9")
        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")
        egg = LEGACY_EGG_INFO_EGG

        with assert_same_fs(self, self.base_dir):
            egginst = EggInst(egg, self.base_dir)
            egginst.install()
            egginst.remove()
Beispiel #26
0
    def test_standard_egg_remove(self):
        custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO", "jinja2")
        egg_info_base = os.path.join(self.site_packages,
                                     "Jinja2-2.6-py2.7.egg-info")
        egg = STANDARD_EGG

        with assert_same_fs(self, self.base_dir):
            egginst = EggInst(egg, self.base_dir)
            egginst.install()

            egginst.remove()
Beispiel #27
0
    def test_simple_custom_egg_remove(self):
        custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO", "dummy")
        egg_info_base = os.path.join(self.site_packages,
                                     "dummy-{0}.egg-info". \
                                     format("1.0.1-1"))
        egg = DUMMY_EGG

        with assert_same_fs(self, self.base_dir):
            egginst = EggInst(egg, self.base_dir)
            egginst.install()
            egginst.remove()
Beispiel #28
0
    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()
Beispiel #29
0
    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)
Beispiel #30
0
    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"])
Beispiel #31
0
    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)
Beispiel #32
0
    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()
Beispiel #33
0
    def test_entry_points(self):
        """
        Test we install console entry points correctly.
        """
        egginst = EggInst(DUMMY_EGG_WITH_ENTRY_POINTS, self.base_dir)

        egginst.install()
        self.assertTrue(op.exists(op.join(self.site_packages, "dummy.py")))
        self.assertTrue(op.exists(op.join(self.bindir, "dummy")))

        egginst.remove()
        self.assertFalse(op.exists(op.join(self.site_packages, "dummy.py")))
        self.assertFalse(op.exists(op.join(self.bindir, "dummy")))
Beispiel #34
0
    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'")
        )
Beispiel #35
0
    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()
Beispiel #36
0
    def iter_execute(self):
        extra_info = self._extract_extra_info()

        installer = EggInst(self._package_path, runtime_info=self._runtime_info)

        progress = self._progress_factory(installer.fn,
                                          installer.installed_size)

        with progress as progress:
            self._progress = progress
            for step in installer.install_iterator(extra_info):
                yield step

        self._post_install()
Beispiel #37
0
    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()
Beispiel #38
0
    def test_post_install_script(self):
        # Given
        create_venv(self.prefix)

        egg_filename = DUMMY_EGG_WITH_POST_INSTALL
        # This file is expected to be created by the egg's post install script
        r_touch = os.path.join(self.prefix, "touch.txt")

        # When
        installer = EggInst(egg_filename, prefix=self.prefix)
        installer.install()

        # Then
        self.assertTrue(os.path.exists(r_touch))
Beispiel #39
0
    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))
Beispiel #40
0
    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")
Beispiel #41
0
    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", op.join(prefix, "python.exe")):
                egginst = EggInst(DUMMY_EGG_WITH_PROXY_SCRIPTS, prefix)
                with zipfile.ZipFile(egginst.path) as zp:
                    egginst.z = zp
                    egginst.arcnames = zp.namelist()
                    create_proxies(egginst)

                    proxied_files = [op.join(prefix, "Scripts", "dummy.dll"), op.join(prefix, "Scripts", "dummy.lib")]
                    for proxied_file in proxied_files:
                        self.assertTrue(op.exists(proxied_file))
Beispiel #42
0
    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")
Beispiel #43
0
    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_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))])
Beispiel #45
0
    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_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)
Beispiel #47
0
    def test_standard_egg(self):
        custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO",
                                            "jinja2")
        egg_info_base = os.path.join(self.site_packages,
                                     "Jinja2-2.6-py2.7.egg-info")

        egg = STANDARD_EGG

        egginst = EggInst(egg, self.base_dir)
        egginst.install()

        # Check for files installed in $prefix/EGG-INFO
        for f in STANDARD_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
        for f in STANDARD_EGG_METADATA_FILES:
            path = os.path.join(egg_info_base, f)
            self.assertTrue(os.path.exists(path))
Beispiel #48
0
    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()
Beispiel #49
0
    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()
Beispiel #50
0
    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()
Beispiel #51
0
    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)
Beispiel #52
0
    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)
Beispiel #53
0
    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()
Beispiel #54
0
    def test_simple_custom_egg(self):
        custom_egg_info_base = os.path.join(self.base_dir, "EGG-INFO", "dummy")
        egg_info_base = os.path.join(self.site_packages,
                                     "dummy-{0}.egg-info".format("1.0.1-1"))
        egg = DUMMY_EGG

        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))
Beispiel #55
0
    def test_print_installed(self):
        with mkdtemp() as d:
            r_out = textwrap.dedent("""\
                Name                 Version              Store
                ============================================================
                dummy                1.0.1-1              {0}
                """.format(disp_store_info(d)))
            ec = EggInst(DUMMY_EGG, d)
            ec.install()

            repository = Repository._from_prefixes([d])
            with mock_print() as m:
                print_installed(repository)
            self.assertMultiLineEqual(m.value, r_out)

            r_out = textwrap.dedent("""\
                Name                 Version              Store
                ============================================================
                """)

            repository = Repository._from_prefixes([d])
            with mock_print() as m:
                print_installed(repository, pat=re.compile("no_dummy"))
            self.assertEqual(m.value, r_out)
Beispiel #56
0
    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")))
Beispiel #57
0
    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()
Beispiel #58
0
    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)