def test_install_from_requirements(self): # Given remote_entries = [ dummy_repository_package_factory("numpy", "1.8.0", 1), dummy_repository_package_factory("numpy", "1.8.0", 2), dummy_repository_package_factory("nose", "1.2.1", 2), dummy_repository_package_factory("nose", "1.3.0", 1) ] requirements_file = os.path.join(self.prefix, "requirements.txt") with open(requirements_file, "w") as fp: fp.write("numpy 1.8.0-1\nnose 1.2.1-1") config = Configuration() enpkg = create_prefix_with_eggs(config, self.prefix, [], remote_entries) args = FakeOptions() args.requirements = requirements_file # When with mock.patch("enstaller.cli.commands.install_req") as mocked_install_req: install_from_requirements(enpkg, config, args) # Then mocked_install_req.assert_has_calls( [mock.call(enpkg, config, "numpy 1.8.0-1", args), mock.call(enpkg, config, "nose 1.2.1-1", args)])
def test_install_from_requirements(self): # Given remote_entries = [ dummy_repository_package_factory("numpy", "1.8.0", 1), dummy_repository_package_factory("numpy", "1.8.0", 2), dummy_repository_package_factory("nose", "1.2.1", 2), dummy_repository_package_factory("nose", "1.3.0", 1) ] requirements_file = os.path.join(self.prefix, "requirements.txt") with open(requirements_file, "w") as fp: fp.write("numpy 1.8.0-1\nnose 1.2.1-1") config = Configuration() enpkg = create_prefix_with_eggs(config, self.prefix, [], remote_entries) args = FakeOptions() args.requirements = requirements_file # When with mock.patch( "enstaller.cli.commands.install_req") as mocked_install_req: install_from_requirements(enpkg, config, args) # Then mocked_install_req.assert_has_calls([ mock.call(enpkg, config, "numpy 1.8.0-1", args), mock.call(enpkg, config, "nose 1.2.1-1", args) ])
def test_install_pypi_before_non_pypi(self): # Given config = Configuration() config.update(auth=("nono", "le petit robot")) session = Session.from_configuration(config) session.authenticate(config.auth) repository = repository_factory(session, config.indices) enpkg = Enpkg(repository, session, [self.prefix]) enpkg.execute = mock.Mock() # When with mock_print() as mocked_print: with mock_raw_input("yes"): install_req(enpkg, config, "swig 2.0.2", FakeOptions()) # Then self._assert_ask_for_pypi(mocked_print) # When with mock_print() as mocked_print: with mock_raw_input("yes"): install_req(enpkg, config, "swig 2.0.2-1", FakeOptions()) # Then self._assert_ask_for_pypi(mocked_print)
def test_install_broken_pypi_requirement(self): self.maxDiff = None # Given r_message = textwrap.dedent(""" Broken pypi package 'rednose-0.2.3-1.egg': missing dependency 'python_termstyle' Pypi packages are not officially supported. If this package is important to you, please contact Enthought support to request its inclusion in our officially supported repository. In the mean time, you may want to try installing 'rednose-0.2.3-1.egg' from sources with pip as follows: $ enpkg pip $ pip install <requested_package> """) config = Configuration() session = Session.from_configuration(config) session.authenticate(("nono", "le petit robot")) repository = repository_factory(session, config.indices) enpkg = Enpkg(repository, session, [self.prefix]) enpkg.execute = mock.Mock() # When with self.assertRaises(SystemExit): with mock_print() as mocked_print: with mock_raw_input("yes"): install_req(enpkg, config, "rednose", FakeOptions()) # Then self.assertMultiLineEqual(mocked_print.value, r_message)
def test_recursive_install_unavailable_dependency(self): config = Configuration() session = Session(DummyAuthenticator(), self.prefix) auth = ("nono", "le gros robot") session.authenticate(auth) config.update(auth=auth) r_output = textwrap.dedent(""" Cannot install 'scipy', as this package (or some of its requirements) are not available at your subscription level 'Canopy / EPD Free' (You are logged in as 'nono'). """) self.maxDiff = None numpy = dummy_repository_package_factory("numpy", "1.7.1", 1) numpy.available = False scipy = dummy_repository_package_factory("scipy", "0.12.0", 1) scipy.packages = ["numpy 1.7.1"] remote_entries = [numpy, scipy] with mock.patch("enstaller.main.Enpkg.execute"): enpkg = create_prefix_with_eggs(config, self.prefix, [], remote_entries) with mock_print() as m: with self.assertRaises(SystemExit): install_req(enpkg, config, "scipy", FakeOptions()) self.assertMultiLineEqual(m.value, r_output)
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()
def test_simple_install(self): remote_entries = [dummy_repository_package_factory("nose", "1.3.0", 1)] with mock.patch("enstaller.main.Enpkg.execute") as m: enpkg = create_prefix_with_eggs(Configuration(), self.prefix, [], remote_entries) install_req(enpkg, Configuration(), "nose", FakeOptions()) m.assert_called_with([('fetch', 'nose-1.3.0-1.egg'), ('install', 'nose-1.3.0-1.egg')])
def test_simple_no_install_needed(self): installed_entries = [ dummy_installed_package_factory("nose", "1.3.0", 1) ] remote_entries = [dummy_repository_package_factory("nose", "1.3.0", 1)] config = Configuration() with mock.patch("enstaller.main.Enpkg.execute") as m: enpkg = create_prefix_with_eggs(config, self.prefix, installed_entries, remote_entries) install_req(enpkg, config, "nose", FakeOptions()) m.assert_called_with([])
def test_simple_non_existing_requirement(self): config = Configuration() r_error_string = "No egg found for requirement 'nono_le_petit_robot'.\n" non_existing_requirement = "nono_le_petit_robot" with mock.patch("enstaller.main.Enpkg.execute") as mocked_execute: enpkg = create_prefix_with_eggs(config, self.prefix, []) with mock_print() as mocked_print: with self.assertRaises(SystemExit) as e: install_req(enpkg, config, non_existing_requirement, FakeOptions()) self.assertEqual(exception_code(e), 1) self.assertEqual(mocked_print.value, r_error_string) mocked_execute.assert_not_called()
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)
def test_install_not_available(self): # Given config = Configuration() config.update(auth=FAKE_AUTH) nose = dummy_repository_package_factory("nose", "1.3.0", 1) nose.available = False repository = Repository() repository.add_package(nose) enpkg = Enpkg(repository, mocked_session_factory(config.repository_cache), [self.prefix]) enpkg.execute = mock.Mock() # When/Then with mock.patch("enstaller.config.subscription_message") as \ subscription_message: with self.assertRaises(SystemExit) as e: install_req(enpkg, config, "nose", FakeOptions()) subscription_message.assert_called() self.assertEqual(e.exception.code, 1)
def test_install_pypi_requirement(self): self.maxDiff = None # Given r_message = textwrap.dedent("""\ The following packages/requirements are coming from the PyPi repo: rednose The PyPi repository which contains >10,000 untested ("as is") packages. Some packages are licensed under GPL or other licenses which are prohibited for some users. Dependencies may not be provided. If you need an updated version or if the installation fails due to unmet dependencies, the Knowledge Base article Installing external packages into Canopy Python (https://support.enthought.com/entries/23389761) may help you with installing it. Are you sure that you wish to proceed? (y/[n]) """) config = Configuration() session = Session.from_configuration(config) session.authenticate(("nono", "le petit robot")) repository = repository_factory(session, config.indices) enpkg = Enpkg(repository, session, [self.prefix]) enpkg.execute = mock.Mock() # When with mock_print() as mocked_print: with mock_raw_input("yes"): install_req(enpkg, config, "rednose", FakeOptions()) # Then self.assertMultiLineEqual(mocked_print.value, r_message)