示例#1
0
    def test_softlink_with_broken_entry(self):
        self.maxDiff = None

        # Given
        path = VTK_EGG_DEFERRED_SOFTLINK
        expected_files = [
            os.path.join('EGG-INFO', 'PKG-INFO'),
            os.path.join('EGG-INFO', 'inst', 'targets.dat'),
            os.path.join('EGG-INFO', 'inst', 'files_to_install.txt'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10',
                         'libvtkViews.so.5.10.1'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10',
                         'libvtkViews.so.5.10'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10',
                         'libvtkViews.so'),
            os.path.join('EGG-INFO', 'spec', 'lib-provide'),
            os.path.join('EGG-INFO', 'spec', 'depend'),
            os.path.join('EGG-INFO', 'spec', 'lib-depend'),
            os.path.join('EGG-INFO', 'spec', 'summary'),
        ]

        with mkdtemp() as d:
            existing_link = os.path.join(
                d, 'EGG-INFO/usr/lib/vtk-5.10/libvtkViews.so')
            create_broken_symlink(existing_link)

            # When
            with ZipFile(path) as zp:
                zp.extractall(d)
            files = list_files(d)

            # Then
            assertCountEqual(self, files, expected_files)
            path = os.path.join(d, "EGG-INFO/usr/lib/vtk-5.10/libvtkViews.so")
            self.assertTrue(os.path.islink(path))
示例#2
0
    def test_update_all_epd_updates(self):
        r_output = textwrap.dedent("""\
        EPD 7.3-2 is available. To update to it (with confirmation warning), run 'enpkg epd'.
        The following updates and their dependencies will be installed
        Name                 installed            available
        ============================================================
        scipy                0.13.0-1             0.13.2-1
        """)
        config = Configuration()

        installed_entries = [
            dummy_installed_package_factory("numpy", "1.7.1", 2),
            dummy_installed_package_factory("scipy", "0.13.0", 1),
            dummy_installed_package_factory("epd", "7.3", 1),
        ]
        remote_entries = [
            dummy_repository_package_factory("numpy", "1.7.1", 1),
            dummy_repository_package_factory("scipy", "0.13.2", 1),
            dummy_repository_package_factory("epd", "7.3", 2),
        ]

        with mkdtemp() as d:
            enpkg = create_prefix_with_eggs(config, d, installed_entries, remote_entries)
            with mock.patch("enstaller.cli.commands.install_req") as mocked_install_req:
                with mock_print() as m:
                    update_all(enpkg, config, FakeOptions())
                    self.assertMultiLineEqual(m.value, r_output)
                    mocked_install_req.assert_called()
示例#3
0
    def test_not_available(self):
        config = Configuration()
        config.use_webservice = False

        r_output = textwrap.dedent("""\
            Name                   Versions           Product              Note
            ================================================================================
            another_package        2.0.0-1            commercial           not subscribed to
            dummy                  0.9.8-1            commercial           {0}
                                   1.0.1-1            commercial           {0}
            """.format(""))
        another_entry = dummy_enpkg_entry_factory("another_package", "2.0.0", 1)
        another_entry.available = False

        entries = [dummy_enpkg_entry_factory("dummy", "1.0.1", 1),
                   dummy_enpkg_entry_factory("dummy", "0.9.8", 1),
                   another_entry]

        with mock.patch("enstaller.main.subscription_message") as mocked_subscription_message:
            mocked_subscription_message.return_value = ""
            with mkdtemp() as d:
                with mock_print() as m:
                    enpkg = _create_prefix_with_eggs(config, d, remote_entries=entries)
                    search(enpkg)

                    self.assertMultiLineEqual(m.value, r_output)
                    self.assertTrue(mocked_subscription_message.called)
示例#4
0
    def test_remove_simple(self):
        """
        Ensure egg is removed only highest priority prefix.
        """
        with mkdtemp() as d:
            egg = DUMMY_EGG
            egg_basename = os.path.basename(egg)

            prefix0 = os.path.join(d, "prefix0")
            prefix1 = os.path.join(d, "prefix1")

            eggs = [[egg], []]

            store = _create_joined_collection((prefix0, prefix1), eggs)

            ec0 = EggCollection(prefix0, False)
            ec1 = EggCollection(prefix1, False)

            self.assertTrue(ec0.find(egg_basename) is not None)
            self.assertTrue(ec1.find(egg_basename) is None)

            store.remove(egg_basename)

            self.assertTrue(ec0.find(egg_basename) is None)
            self.assertTrue(ec1.find(egg_basename) is None)
示例#5
0
    def test_from_filename(self):
        # Given
        data = textwrap.dedent("""\
        packages:
            - MKL 10.3-1
            - numpy 1.8.1-1; depends (MKL ~= 10.3)
            - numpy 1.8.1-2; depends (MKL ~= 10.3)

        remote:
            - MKL 10.3-1
            - numpy 1.8.1-2

        request:
            - operation: install
              requirement: numpy
        """)
        r_jobs = [_Job(Requirement._from_string("numpy"), "install")]

        # When
        with mkdtemp() as d:
            path = os.path.join(d, "scenario.yaml")
            with open(path, "wt") as fp:
                fp.write(data)
            scenario = Scenario.from_yaml(path)

        # Then
        self.assertEqual(len(scenario.remote_repositories), 1)
        remote_repository = scenario.remote_repositories[0]
        self.assertEqual(len(remote_repository), 2)

        self.assertEqual(len(scenario.installed_repository), 0)

        jobs = scenario.request.jobs
        self.assertEqual(jobs, r_jobs)
示例#6
0
    def test_load_from_path(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        python_tag = PythonImplementation.from_running_python().pep425_tag

        r_indices = (
            ('https://api.enthought.com/api/v0/json/indices/enthought/free/{0}/{1}/eggs'
             .format(platform, python_tag)),
            ('https://api.enthought.com/api/v0/json/indices/enthought/commercial/{0}/{1}/eggs'
             .format(platform, python_tag)),
        )

        with mkdtemp() as prefix:
            path = os.path.join(prefix, "enstaller.yaml")
            with open(path, "wt") as fp:
                fp.write(yaml_string)

            # When
            config = Configuration.from_yaml_filename(path)

            # Then
            self.assertFalse(config.use_webservice)
            self.assertEqual(config.store_url, "https://api.enthought.com")
            self.assertEqual(
                tuple(repository_info.index_url
                      for repository_info in config.repositories),
                r_indices
            )
示例#7
0
    def test_whats_new_no_new_epd(self):
        r_output = textwrap.dedent("""\
            Name                 installed            available
            ============================================================
            scipy                0.12.0-1             0.13.0-1
            numpy                1.7.1-1              1.7.1-2
            """)
        installed_entries = [
            dummy_installed_egg_factory("numpy", "1.7.1", 1),
            dummy_installed_egg_factory("scipy", "0.12.0", 1)
        ]
        remote_entries = [
            dummy_enpkg_entry_factory("numpy", "1.7.1", 2),
            dummy_enpkg_entry_factory("scipy", "0.13.0", 1)
        ]

        with mkdtemp() as d:
            enpkg = _create_prefix_with_eggs(Configuration(), d,
                    installed_entries, remote_entries)

            with mock_print() as m:
                whats_new(enpkg)
                # FIXME: we splitlines and compared wo caring about order, as
                # the actual line order depends on dict ordering from
                # EggCollection.query_installed.
                self.assertItemsEqual(m.value.splitlines(), r_output.splitlines())
示例#8
0
    def test_no_installed(self):
        config = Configuration()
        config.update(use_webservice=False)

        with mkdtemp() as d:
            # XXX: isn't there a better way to ensure ws at the end of a line
            # are not eaten away ?
            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                another_dummy          2.0.0-1            commercial           {0}
                dummy                  0.9.8-1            commercial           {0}
                                       1.0.0-1            commercial           {0}
                """.format(""))
            entries = [
                dummy_repository_package_factory("dummy", "1.0.0", 1),
                dummy_repository_package_factory("dummy", "0.9.8", 1),
                dummy_repository_package_factory("another_dummy", "2.0.0", 1)
            ]
            enpkg = create_prefix_with_eggs(config, d, remote_entries=entries)

            with mock_print() as m:
                search(enpkg._remote_repository,
                       enpkg._top_installed_repository, config, UserInfo(True))
                self.assertMultiLineEqual(m.value, r_output)
示例#9
0
    def test_installed(self):
        config = Configuration()
        config.update(use_webservice=False)

        with mkdtemp() as d:
            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                dummy                  0.9.8-1            commercial           {0}
                                     * 1.0.1-1            commercial           {0}
                """.format(""))
            entries = [
                dummy_repository_package_factory("dummy", "1.0.1", 1),
                dummy_repository_package_factory("dummy", "0.9.8", 1)
            ]
            installed_entries = [
                dummy_installed_package_factory("dummy", "1.0.1", 1)
            ]
            enpkg = create_prefix_with_eggs(config, d, installed_entries,
                                            entries)

            with mock_print() as m:
                search(enpkg._remote_repository, enpkg._installed_repository,
                       config, UserInfo(True))
                self.assertMultiLineEqual(m.value, r_output)
示例#10
0
    def test_fetch_egg_refetch_invalid_md5(self):
        with mkdtemp() as d:
            egg = "dummy-1.0.0-1.egg"

            def _fetch_api_factory():
                fp = MockedFailingFile(100000)

                remote = DummyRepository(d, [Entry(egg, fp)])
                remote.connect()

                return fp, FetchAPI(remote, d)

            def _corrupt_file(target):
                with open(target, "wb") as fo:
                    fo.write("")

            fp, fetch_api = _fetch_api_factory()
            fetch_api.fetch_egg(egg)

            target = os.path.join(d, egg)

            self.assertEqual(md5_file(target), fp.md5)
            _corrupt_file(target)
            self.assertNotEqual(md5_file(target), fp.md5)

            fp, fetch_api = _fetch_api_factory()
            fetch_api.fetch_egg(egg, force=True)

            self.assertEqual(md5_file(target), fp.md5)
示例#11
0
    def test_load_from_path(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        r_indices = tuple((
            ('https://api.enthought.com/repo/enthought/free/{0}/index.json'.format(platform),
             'https://api.enthought.com/repo/enthought/free/{0}/index.json'.format(platform)),
            ('https://api.enthought.com/repo/enthought/commercial/{0}/index.json'.format(platform),
             'https://api.enthought.com/repo/enthought/commercial/{0}/index.json'.format(platform))
        ))

        with mkdtemp() as prefix:
            path = os.path.join(prefix, "enstaller.yaml")
            with open(path, "wt") as fp:
                fp.write(yaml_string)

            # When
            config = Configuration.from_yaml_filename(path)

            # Then
            self.assertFalse(config.use_webservice)
            self.assertEqual(config.store_url, "https://api.enthought.com")
            self.assertEqual(config.indices, r_indices)
示例#12
0
    def test_load_from_path(self):
        # Given
        yaml_string = textwrap.dedent("""\
            repositories:
              - enthought/free
              - enthought/commercial
        """)
        platform = custom_plat
        r_indices = tuple(((
            'https://api.enthought.com/repo/enthought/free/{0}/index.json'.
            format(platform),
            'https://api.enthought.com/repo/enthought/free/{0}/index.json'.
            format(platform)
        ), ('https://api.enthought.com/repo/enthought/commercial/{0}/index.json'
            .format(platform),
            'https://api.enthought.com/repo/enthought/commercial/{0}/index.json'
            .format(platform))))

        with mkdtemp() as prefix:
            path = os.path.join(prefix, "enstaller.yaml")
            with open(path, "wt") as fp:
                fp.write(yaml_string)

            # When
            config = Configuration.from_yaml_filename(path)

            # Then
            self.assertFalse(config.use_webservice)
            self.assertEqual(config.store_url, "https://api.enthought.com")
            self.assertEqual(config.indices, r_indices)
示例#13
0
    def test_softlink_with_broken_entry(self):
        self.maxDiff = None

        # Given
        path = VTK_EGG_DEFERRED_SOFTLINK
        expected_files = [
            os.path.join('EGG-INFO', 'PKG-INFO'),
            os.path.join('EGG-INFO', 'inst', 'targets.dat'),
            os.path.join('EGG-INFO', 'inst', 'files_to_install.txt'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10', 'libvtkViews.so.5.10.1'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10', 'libvtkViews.so.5.10'),
            os.path.join('EGG-INFO', 'usr', 'lib', 'vtk-5.10', 'libvtkViews.so'),
            os.path.join('EGG-INFO', 'spec', 'lib-provide'),
            os.path.join('EGG-INFO', 'spec', 'depend'),
            os.path.join('EGG-INFO', 'spec', 'lib-depend'),
            os.path.join('EGG-INFO', 'spec', 'summary'),
        ]

        with mkdtemp() as d:
            existing_link = os.path.join(d, 'EGG-INFO/usr/lib/vtk-5.10/libvtkViews.so')
            create_broken_symlink(existing_link)

            # When
            with ZipFile(path) as zp:
                zp.extractall(d)
            files = list_files(d)

            # Then
            assertCountEqual(self, files, expected_files)
            path = os.path.join(d, "EGG-INFO/usr/lib/vtk-5.10/libvtkViews.so")
            self.assertTrue(os.path.islink(path))
示例#14
0
    def test_update_all_no_epd_updates(self):
        r_output = textwrap.dedent("""\
        The following updates and their dependencies will be installed
        Name                 installed            available
        ============================================================
        scipy                0.13.0-1             0.13.2-1
        """)

        installed_entries = [
            dummy_installed_egg_factory("numpy", "1.7.1", 2),
            dummy_installed_egg_factory("scipy", "0.13.0", 1),
            dummy_installed_egg_factory("epd", "7.3", 1),
        ]
        remote_entries = [
            dummy_enpkg_entry_factory("numpy", "1.7.1", 1),
            dummy_enpkg_entry_factory("scipy", "0.13.2", 1),
            dummy_enpkg_entry_factory("epd", "7.3", 1),
        ]

        with mkdtemp() as d:
            enpkg = _create_prefix_with_eggs(Configuration(), d, installed_entries, remote_entries)
            with mock.patch("enstaller.main.install_req") as mocked_install_req:
                with mock_print() as m:
                    update_all(enpkg, FakeOptions())
                    self.assertMultiLineEqual(m.value, r_output)
                    mocked_install_req.assert_called()
示例#15
0
    def test_pattern(self):
        config = Configuration()
        config.update(use_webservice=False)
        with mkdtemp() as d:
            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                dummy                  0.9.8-1            commercial           {0}
                                     * 1.0.1-1            commercial           {0}
                """.format(""))
            entries = [dummy_repository_package_factory("dummy", "1.0.1", 1),
                       dummy_repository_package_factory("dummy", "0.9.8", 1),
                       dummy_repository_package_factory("another_package", "2.0.0", 1)]
            installed_entries = [dummy_installed_package_factory("dummy", "1.0.1", 1)]
            enpkg = create_prefix_with_eggs(config, d, installed_entries, entries)

            with mock_print() as m:
                search(enpkg._remote_repository,
                       enpkg._top_installed_repository,
                       config, UserInfo(True),
                       pat=re.compile("dummy"))
                self.assertMultiLineEqual(m.value, r_output)

            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                another_package        2.0.0-1            commercial           {0}
                dummy                  0.9.8-1            commercial           {0}
                                     * 1.0.1-1            commercial           {0}
                """.format(""))
            with mock_print() as m:
                search(enpkg._remote_repository,
                       enpkg._top_installed_repository, config,
                       UserInfo(True), pat=re.compile(".*"))
                self.assertMultiLineEqual(m.value, r_output)
示例#16
0
    def test_query_simple_with_local(self):
        """
        Ensure enpkg.query finds both local and remote eggs.
        """
        local_egg = DUMMY_EGG

        entries = [
            dummy_enpkg_entry_factory("dummy", "1.6.1", 1),
            dummy_enpkg_entry_factory("dummy", "1.8k", 2),
        ]

        repo = MetadataOnlyStore(entries)
        repo.connect()

        local_entry = EnpkgS3IndexEntry.from_egg(DUMMY_EGG)

        with mkdtemp() as d:
            enpkg = Enpkg(repo, prefixes=[d], hook=None,
                          evt_mgr=None, verbose=False, config=Configuration())
            enpkg = Enpkg(repo, prefixes=[d], hook=None,
                          evt_mgr=None, verbose=False, config=Configuration())
            enpkg.ec.install(os.path.basename(local_egg),
                             os.path.dirname(local_egg))

            r = dict(enpkg.query(name="dummy"))
            self.assertEqual(set(r.keys()),
                             set(entry.s3index_key for entry in entries + [local_entry]))
示例#17
0
    def test_not_available(self):
        responses.add(responses.GET,
                      "https://acme.com/accounts/user/info/",
                      body=json.dumps(R_JSON_AUTH_FREE_RESP))
        config = Configuration()
        config.update(store_url="https://acme.com")

        r_output = textwrap.dedent("""\
            Name                   Versions           Product              Note
            ================================================================================
            another_package        2.0.0-1            commercial           not subscribed to
            dummy                  0.9.8-1            commercial           {0}
                                   1.0.1-1            commercial           {0}
            Note: some of those packages are not available at your current
            subscription level ('Canopy / EPD Free').
            """.format(""))
        another_entry = dummy_repository_package_factory("another_package", "2.0.0", 1)
        another_entry.available = False

        entries = [dummy_repository_package_factory("dummy", "1.0.1", 1),
                   dummy_repository_package_factory("dummy", "0.9.8", 1),
                   another_entry]

        with Session.from_configuration(config) as session:
            with mkdtemp() as d:
                with mock_print() as m:
                    enpkg = create_prefix_with_eggs(config, d, remote_entries=entries)
                    search(enpkg._remote_repository,
                           enpkg._installed_repository, config, session)

                self.assertMultiLineEqual(m.value, r_output)
示例#18
0
    def test_update_all_epd_updates(self):
        r_output = textwrap.dedent("""\
        EPD 7.3-2 is available. To update to it (with confirmation warning), run 'enpkg epd'.
        The following updates and their dependencies will be installed
        Name                 installed            available
        ============================================================
        scipy                0.13.0-1             0.13.2-1
        """)
        config = Configuration()

        installed_entries = [
            dummy_installed_package_factory("numpy", "1.7.1", 2),
            dummy_installed_package_factory("scipy", "0.13.0", 1),
            dummy_installed_package_factory("epd", "7.3", 1),
        ]
        remote_entries = [
            dummy_repository_package_factory("numpy", "1.7.1", 1),
            dummy_repository_package_factory("scipy", "0.13.2", 1),
            dummy_repository_package_factory("epd", "7.3", 2),
        ]

        with mkdtemp() as d:
            enpkg = create_prefix_with_eggs(config, d, installed_entries,
                                            remote_entries)
            with mock.patch("enstaller.cli.commands.install_req"
                            ) as mocked_install_req:
                with mock_print() as m:
                    update_all(enpkg, config, FakeOptions())
                    self.assertMultiLineEqual(m.value, r_output)
                    mocked_install_req.assert_called()
示例#19
0
    def test_info_option(self):
        self.maxDiff = None
        r_output = textwrap.dedent("""\
        Package: enstaller

        Version: 4.6.2-1
            Product: commercial
            Available: True
            Python version: {1}
            Store location:{0}
            Last modified: 0.0
            Type: egg
            MD5:{0}
            Size: 1024
            Requirements: None
        Version: 4.6.3-1
            Product: commercial
            Available: True
            Python version: {1}
            Store location:{0}
            Last modified: 0.0
            Type: egg
            MD5:{0}
            Size: 1024
            Requirements: None
        """.format(" ", PY_VER))
        with mkdtemp() as d:
            entries = [dummy_enpkg_entry_factory("enstaller", "4.6.2", 1),
                       dummy_enpkg_entry_factory("enstaller", "4.6.3", 1)]
            enpkg = _create_prefix_with_eggs(Configuration(), d, remote_entries=entries)

            with mock_print() as m:
                info_option(enpkg, "enstaller")
                self.assertMultiLineEqual(m.value, r_output)
示例#20
0
    def test_simple_dir(self):
        with mkdtemp() as d:
            urls = [d]
            store = create_joined_store(Configuration(), urls)
            self.assertEqual(len(store.repos), 1)

            store = store.repos[0]
            self.assertTrue(isinstance(store, LocalIndexedStore))
            self.assertEqual(store.root, d)
示例#21
0
    def test_print_install_time(self):
        with mkdtemp() as d:
            installed_entries = [dummy_installed_egg_factory("dummy", "1.0.1", 1)]
            enpkg = _create_prefix_with_eggs(Configuration(), d, installed_entries)

            self.assertRegexpMatches(install_time_string(enpkg, "dummy"),
                                     "dummy-1.0.1-1.egg was installed on:")

            self.assertEqual(install_time_string(enpkg, "ddummy"), "")
示例#22
0
    def test_from_empty_prefix(self):
        # Given
        with mkdtemp() as tempdir:

            # When
            repository = Repository._from_prefixes([tempdir])

            # Then
            self.assertEqual(len(list(repository.iter_packages())), 0)
示例#23
0
    def test_deprecated_get_auth(self):
        with mkdtemp() as d:
            f = os.path.join(d, "enstaller4rc")
            config = Configuration()
            config.set_auth(FAKE_USER, FAKE_PASSWORD)
            config.write(f)

            with mock.patch("enstaller.config.get_path", lambda: f):
                self.assertEqual(get_auth(), (FAKE_USER, FAKE_PASSWORD))
示例#24
0
    def test_from_empty_prefix(self):
        # Given
        with mkdtemp() as tempdir:

            # When
            repository = Repository._from_prefixes([tempdir])

            # Then
            self.assertEqual(len(list(repository.iter_packages())), 0)
示例#25
0
    def test_extract(self):
        # Given
        path = NOSE_1_3_0
        arcname = "EGG-INFO/PKG-INFO"

        # When
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extract(arcname, d)
            self.assertTrue(os.path.exists(os.path.join(d, arcname)))
示例#26
0
    def test_remove(self):
        with mkdtemp() as d:
            makedirs(d)

            enpkg = unconnected_enpkg_factory([d])

            with mock.patch("enstaller.enpkg.RemoveAction.execute") as mocked_remove:
                actions = [("remove", DUMMY_EGG)]
                enpkg.execute(actions)
                self.assertTrue(mocked_remove.called)
示例#27
0
    def test_extract(self):
        # Given
        path = NOSE_1_3_0
        arcname = "EGG-INFO/PKG-INFO"

        # When
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extract(arcname, d)
            self.assertTrue(os.path.exists(os.path.join(d, arcname)))
示例#28
0
    def test_update_check_no_available(self):
        installed_entries = [
                dummy_installed_egg_factory("dummy", "1.0.1", 1)
        ]
        with mkdtemp() as d:
            enpkg = _create_prefix_with_eggs(Configuration(), d, installed_entries)

            updates, EPD_update =  updates_check(enpkg)

            self.assertEqual(EPD_update, [])
            self.assertEqual(updates, [])
示例#29
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"])
示例#30
0
    def test_fetch_egg_simple(self):
        with mkdtemp() as d:
            egg = "dummy-1.0.0-1.egg"
            fp = MockedFailingFile(100000)

            remote = DummyRepository(d, [Entry(egg, fp)])
            remote.connect()

            fetch_api = FetchAPI(remote, d)
            fetch_api.fetch_egg(egg)

            target = os.path.join(d, egg)
            self.assertTrue(os.path.exists(target))
示例#31
0
    def test_softlink(self):
        # Given
        path = ZIP_WITH_SOFTLINK

        # When/Then
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extractall(d)
            paths = list_files(d)

            assertCountEqual(self, paths, [os.path.join("lib", "foo.so.1.3"),
                                           os.path.join("lib", "foo.so")])
            self.assertTrue(os.path.islink(os.path.join(d, "lib", "foo.so")))
示例#32
0
    def test_find_simple(self):
        with mkdtemp() as d:
            egg = DUMMY_EGG
            egg_basename = os.path.basename(egg)
            prefix0 = os.path.join(d, "prefix0")
            prefix1 = os.path.join(d, "prefix1")

            eggs = [[egg], [egg]]
            store = _create_joined_collection((prefix0, prefix1), eggs)

            info = store.find(egg_basename)
            self.assertInstalledInfoEqual(info, _dummy_installed_info(prefix0))
            self.assertNotEqual(info, _dummy_installed_info(prefix1))
示例#33
0
    def test_find_simple(self):
        with mkdtemp() as d:
            prefix = os.path.join(d, "env")

            _install_eggs_set([DUMMY_EGG], prefix)

            ec = EggCollection(prefix, False)

            info = ec.find(os.path.basename(DUMMY_EGG))
            self.assertInstalledInfoEqual(info, _dummy_installed_info(prefix))

            info = ec.find("dummy-1.eggg")
            self.assertTrue(info is None)
示例#34
0
    def test_fetch_simple(self):
        with mkdtemp() as d:
            filename = "dummy"
            fp = MockedFailingFile(100000)

            remote = DummyRepository(d, [Entry(filename, fp)])
            remote.connect()

            fetch_api = FetchAPI(remote, d)
            fetch_api.fetch(filename)

            target = os.path.join(d, filename)
            self.assertTrue(os.path.exists(target))
            self.assertEqual(md5_file(target), fp.md5)
示例#35
0
    def test_remove_non_existing(self):
        entries = [
            dummy_enpkg_entry_factory("numpy", "1.6.1", 1),
           dummy_enpkg_entry_factory("numpy", "1.8.0", 2),
        ]

        repo = MetadataOnlyStore(entries)
        repo.connect()

        with mkdtemp() as d:
            enpkg = Enpkg(repo, prefixes=[d], hook=None,
                          evt_mgr=None, verbose=False, config=Configuration())
            with self.assertRaises(EnpkgError):
                enpkg.remove_actions("numpy")
示例#36
0
    def test_install_remove_simple(self):
        with mkdtemp() as d:
            egg = DUMMY_EGG
            egg_basename = os.path.basename(egg)
            prefix = os.path.join(d, "prefix")

            ec = EggCollection(prefix, False)
            self.assertTrue(ec.find(egg_basename) is None)

            ec.install(os.path.basename(egg), os.path.dirname(egg))
            self.assertTrue(ec.find(egg_basename) is not None)

            ec.remove(os.path.basename(egg))
            self.assertTrue(ec.find(egg_basename) is None)
示例#37
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")
示例#38
0
    def test_print_install_time(self):
        with mkdtemp():
            installed_entries = [dummy_installed_package_factory("dummy",
                                                                 "1.0.1", 1)]
            installed_repository = Repository()
            for package in installed_entries:
                installed_repository.add_package(package)

            self.assertRegexpMatches(install_time_string(installed_repository,
                                                         "dummy"),
                                     "dummy-1.0.1-1.egg was installed on:")

            self.assertEqual(install_time_string(installed_repository,
                                                 "ddummy"),
                             "")
示例#39
0
    def test_print_install_time(self):
        with mkdtemp():
            installed_entries = [
                dummy_installed_package_factory("dummy", "1.0.1", 1)
            ]
            installed_repository = Repository()
            for package in installed_entries:
                installed_repository.add_package(package)

            self.assertRegexpMatches(
                install_time_string(installed_repository, "dummy"),
                "dummy-1.0.1-1.egg was installed on:")

            self.assertEqual(
                install_time_string(installed_repository, "ddummy"), "")
示例#40
0
    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")))
示例#41
0
    def test_softlink(self):
        # Given
        path = ZIP_WITH_SOFTLINK

        # When/Then
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extractall(d)
            paths = list_files(d)

            assertCountEqual(self, paths, [
                os.path.join("lib", "foo.so.1.3"),
                os.path.join("lib", "foo.so")
            ])
            self.assertTrue(os.path.islink(os.path.join(d, "lib", "foo.so")))
示例#42
0
    def test_simple(self):
        # Given
        with mkdtemp() as prefix:
            if sys.platform == "win32":
                # python.exe is in scripts because we use virtualenv
                r_executable = os.path.join(prefix, "Scripts", "python.exe")
            else:
                r_executable = os.path.join(prefix, "bin", "python")

            create_venv(prefix)

            # When
            executable = get_executable(prefix)

        # Then
        self.assertEqual(executable, r_executable)
示例#43
0
    def test_update_all_no_updates(self):
        r_output = "No new version of any installed package is available\n"
        config = Configuration()

        installed_entries = [
            dummy_installed_package_factory("numpy", "1.7.1", 2),
            dummy_installed_package_factory("scipy", "0.13.0", 1)
        ]
        remote_entries = [
            dummy_repository_package_factory("numpy", "1.7.1", 1),
            dummy_repository_package_factory("scipy", "0.12.0", 1)
        ]

        with mkdtemp() as d:
            enpkg = create_prefix_with_eggs(config, d, installed_entries,
                                            remote_entries)
            with mock_print() as m:
                update_all(enpkg, config, FakeOptions())
                self.assertMultiLineEqual(m.value, r_output)
示例#44
0
    def test_simple(self):
        # Given
        path = NOSE_1_3_0
        r_paths = [
            os.path.join("EGG-INFO", "entry_points.txt"),
            os.path.join("EGG-INFO", "PKG-INFO"),
            os.path.join("EGG-INFO", "spec", "depend"),
            os.path.join("EGG-INFO", "spec", "summary"),
            os.path.join("EGG-INFO", "usr", "share", "man", "man1",
                         "nosetests.1"),
        ]

        # When
        with mkdtemp() as d:
            with ZipFile(path) as zp:
                zp.extractall(d)
            paths = list_files(d)

        # Then
        assertCountEqual(self, paths, r_paths)
示例#45
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)
示例#46
0
    def test_not_available(self):
        responses.add(responses.GET,
                      "https://acme.com/accounts/user/info/",
                      body=json.dumps(R_JSON_AUTH_FREE_RESP))
        config = Configuration()
        config.update(store_url="https://acme.com")

        r_output = textwrap.dedent("""\
            Name                   Versions           Product              Note
            ================================================================================
            another_package        2.0.0-1            commercial           not subscribed to
            dummy                  0.9.8-1            commercial           {0}
                                   1.0.1-1            commercial           {0}
            Note: some of those packages are not available at your current
            subscription level ('Canopy / EPD Free').
            """.format(""))
        another_entry = dummy_repository_package_factory(
            "another_package", "2.0.0", 1)
        another_entry.available = False

        entries = [
            dummy_repository_package_factory("dummy", "1.0.1", 1),
            dummy_repository_package_factory("dummy", "0.9.8", 1),
            another_entry
        ]

        with Session.from_configuration(config) as session:
            with mkdtemp() as d:
                with mock_print() as m:
                    enpkg = create_prefix_with_eggs(config,
                                                    d,
                                                    remote_entries=entries)
                    search(enpkg._remote_repository,
                           enpkg._installed_repository, config, session)

                self.assertMultiLineEqual(m.value, r_output)
示例#47
0
 def test_writable_repository_cache(self):
     config = Configuration()
     with mkdtemp() as d:
         config.update(repository_cache=d)
         self.assertEqual(config.repository_cache, d)