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_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_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_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_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)