def test_install_with_deps_in_order(solver, repo, package): package.add_dependency("A") package.add_dependency("B") package.add_dependency("C") package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) package_b.requires.append(get_dependency("A", ">=1.0")) package_b.requires.append(get_dependency("C", ">=1.0")) package_c.requires.append(get_dependency("A", ">=1.0")) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": package_a}, {"job": "install", "package": package_c}, {"job": "install", "package": package_b}, ], )
def test_solver_returns_extras_if_requested(solver, repo, package): package.add_dependency("A") package.add_dependency("B", {"version": "*", "extras": ["foo"]}) package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_b.extras = {"foo": [get_dependency("C", "^1.0")]} package_b.add_dependency("C", {"version": "^1.0", "optional": True}) repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": package_c}, {"job": "install", "package": package_a}, {"job": "install", "package": package_b}, ], )
def test_add_constraint_dependencies(app, repo, installer): command = app.find("add") tester = CommandTester(command) cachy2 = get_package("cachy", "0.2.0") msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6") cachy2.requires = [msgpack_dep] repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(cachy2) repo.add_package(get_package("msgpack-python", "0.5.3")) tester.execute([("command", command.get_name()), ("name", ["cachy=0.2.0"])]) expected = """\ Updating dependencies Resolving dependencies... Package operations: 2 installs, 0 updates, 0 removals Writing lock file - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) """ assert tester.get_display(True) == expected assert len(installer.installs) == 2
def test_run_installs_extras_if_requested(installer, locker, repo, package): package.extras['foo'] = [get_dependency('D')] package_a = get_package('A', '1.0') package_b = get_package('B', '1.0') package_c = get_package('C', '1.0') package_d = get_package('D', '1.1') repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) package.add_dependency('A', '^1.0') package.add_dependency('B', '^1.0') package.add_dependency('C', '^1.0') package.add_dependency('D', {'version': '^1.0', 'optional': True}) installer.extras(['foo']) installer.run() expected = fixture('extras') # Extras are pinned in lock assert locker.written_data == expected # But should not be installed installer = installer.installer assert len(installer.installs) == 4 # A, B, C, D
def test_add_constraint_dependencies_old_installer(app, repo, installer, old_tester): cachy2 = get_package("cachy", "0.2.0") msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6") cachy2.requires = [msgpack_dep] repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(cachy2) repo.add_package(get_package("msgpack-python", "0.5.3")) old_tester.execute("cachy=0.2.0") expected = """\ Updating dependencies Resolving dependencies... Writing lock file Package operations: 2 installs, 0 updates, 0 removals - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) """ assert expected == old_tester.io.fetch_output() assert len(installer.installs) == 2
def test_add_constraint_dependencies(app, repo, installer): command = app.find('add') tester = CommandTester(command) cachy2 = get_package('cachy', '0.2.0') msgpack_dep = get_dependency('msgpack-python', '>=0.5 <0.6') cachy2.requires = [ msgpack_dep, ] repo.add_package(get_package('cachy', '0.1.0')) repo.add_package(cachy2) repo.add_package(get_package('msgpack-python', '0.5.3')) tester.execute([('command', command.get_name()), ('name', ['cachy=0.2.0'])]) expected = """\ Updating dependencies Resolving dependencies Package operations: 2 installs, 0 updates, 0 removals Writing lock file - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) """ assert tester.get_display() == expected assert len(installer.installs) == 2
def test_run_installs_extras_if_requested(installer, locker, repo, package): package.extras["foo"] = [get_dependency("D")] package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_d = get_package("D", "1.1") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) package.add_dependency("A", "^1.0") package.add_dependency("B", "^1.0") package.add_dependency("C", "^1.0") package.add_dependency("D", {"version": "^1.0", "optional": True}) installer.extras(["foo"]) installer.run() expected = fixture("extras") # Extras are pinned in lock assert locker.written_data == expected # But should not be installed installer = installer.installer assert len(installer.installs) == 4 # A, B, C, D
def test_run_with_optional_and_platform_restricted_dependencies( installer, locker, repo, package ): package_a = get_package("A", "1.0") package_b = get_package("B", "1.1") package_c12 = get_package("C", "1.2") package_c13 = get_package("C", "1.3") package_d = get_package("D", "1.4") package_c13.add_dependency("D", "^1.2") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c12) repo.add_package(package_c13) repo.add_package(package_d) package.extras = {"foo": [get_dependency("A", "~1.0")]} package.add_dependency("A", {"version": "~1.0", "optional": True}) package.add_dependency("B", {"version": "^1.0", "platform": "custom"}) package.add_dependency("C", {"version": "^1.0", "platform": "darwin"}) installer.run() expected = fixture("with-platform-dependencies") assert locker.written_data == expected installer = installer.installer # We should only have 2 installs: # C,D since the mocked python version is not compatible # with B's python constraint and A is optional assert len(installer.installs) == 2 assert installer.installs[0].name == "d" assert installer.installs[1].name == "c"
def test_run_with_optional_and_python_restricted_dependencies( installer, locker, repo, package): package.python_versions = "~2.7 || ^3.4" package_a = get_package("A", "1.0") package_b = get_package("B", "1.1") package_c12 = get_package("C", "1.2") package_c13 = get_package("C", "1.3") package_d = get_package("D", "1.4") package_c13.add_dependency("D", "^1.2") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c12) repo.add_package(package_c13) repo.add_package(package_d) package.extras = {"foo": [get_dependency("A", "~1.0")]} package.add_dependency("A", {"version": "~1.0", "optional": True}) package.add_dependency("B", {"version": "^1.0", "python": "~2.4"}) package.add_dependency("C", {"version": "^1.0", "python": "~2.7 || ^3.4"}) installer.run() expected = fixture("with-optional-dependencies") assert locker.written_data == expected installer = installer.installer # We should only have 2 installs: # C,D since python version is not compatible # with B's python constraint and A is optional assert len(installer.installs) == 2 assert installer.installs[0].name == "d" assert installer.installs[1].name == "c"
def test_search_for_file_wheel(provider): dependency = FileDependency( "demo", Path(__file__).parent.parent / "fixtures" / "distributions" / "demo-0.1.0-py2.py3-none-any.whl", ) package = provider.search_for_file(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.0" assert package.requires == [get_dependency("pendulum", ">=1.4.4")] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_search_for_directory_poetry_with_extras(provider): dependency = DirectoryDependency( "project-with-extras", Path(__file__).parent.parent / "fixtures" / "project_with_extras", ) dependency.extras.append("extras_a") package = provider.search_for_directory(dependency)[0] assert package.name == "project-with-extras" assert package.version.text == "1.2.3" assert package.requires == [get_dependency("pendulum", ">=1.4.4")] assert package.extras == { "extras_a": [get_dependency("pendulum", ">=1.4.4")], "extras_b": [get_dependency("cachy", ">=0.2.0")], }
def test_search_for_directory_setup_egg_info(provider): dependency = DirectoryDependency( "demo", Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo" / "demo", ) package = provider.search_for_directory(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" assert package.requires == [get_dependency("pendulum", ">=1.4.4")] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_run_installs_extras_with_deps_if_requested_locked( installer, locker, repo, package): locker.locked(True) locker.mock_lock_data(fixture('extras-with-dependencies')) package.extras['foo'] = [get_dependency('C')] package_a = get_package('A', '1.0') package_b = get_package('B', '1.0') package_c = get_package('C', '1.0') package_d = get_package('D', '1.1') repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) package.add_dependency('A', '^1.0') package.add_dependency('B', '^1.0') package.add_dependency('C', {'version': '^1.0', 'optional': True}) package_c.add_dependency('D', '^1.0') installer.extras(['foo']) installer.run() # But should not be installed installer = installer.installer assert len(installer.installs) == 4 # A, B, C, D
def test_search_for_vcs_setup_egg_info(provider): dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git") package = provider.search_for_vcs(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" required = [r for r in package.requires if not r.is_optional()] optional = [r for r in package.requires if r.is_optional()] assert required == [get_dependency("pendulum", ">=1.4.4")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_search_for_vcs_read_setup_with_extras(provider, mocker): mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = VCSDependency( "demo", "git", "https://github.com/demo/demo.git", extras=["foo"] ) package = provider.search_for_vcs(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" required = [r for r in package.requires if not r.is_optional()] optional = [r for r in package.requires if r.is_optional()] assert required == [get_dependency("pendulum", ">=1.4.4")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
def test_solver_solves_optional_and_compatible_packages(solver, repo, package): package.python_versions = "^3.4" package.extras["foo"] = [get_dependency("B")] package.add_dependency("A", {"version": "*", "python": "~3.5"}) package.add_dependency("B", {"version": "*", "optional": True}) package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_b.python_versions = "^3.6" package_c = get_package("C", "1.0") package_c.python_versions = "^3.6" package_b.add_dependency("C", "^1.0") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": package_c}, {"job": "install", "package": package_a}, {"job": "install", "package": package_b}, ], )
def test_run_with_optional_and_platform_restricted_dependencies( installer, locker, repo, package, mocker): mocker.patch("sys.platform", "darwin") package_a = get_package("A", "1.0") package_b = get_package("B", "1.1") package_c12 = get_package("C", "1.2") package_c13 = get_package("C", "1.3") package_d = get_package("D", "1.4") package_c13.add_dependency("D", "^1.2") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c12) repo.add_package(package_c13) repo.add_package(package_d) package.extras = {"foo": [get_dependency("A", "~1.0")]} package.add_dependency("A", {"version": "~1.0", "optional": True}) package.add_dependency("B", {"version": "^1.0", "platform": "custom"}) package.add_dependency("C", {"version": "^1.0", "platform": "darwin"}) installer.run() expected = fixture("with-platform-dependencies") assert locker.written_data == expected installer = installer.installer # We should only have 2 installs: # C,D since the mocked python version is not compatible # with B's python constraint and A is optional assert len(installer.installs) == 2 assert installer.installs[0].name == "d" assert installer.installs[1].name == "c"
def test_install_honours_not_equal(solver, repo, package): package.add_dependency("A") package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") new_package_b11 = get_package("B", "1.1") new_package_b12 = get_package("B", "1.2") new_package_b13 = get_package("B", "1.3") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(new_package_b11) repo.add_package(new_package_b12) repo.add_package(new_package_b13) package_a.requires.append(get_dependency("B", "<=1.3,!=1.3,!=1.2")) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": new_package_b11}, {"job": "install", "package": package_a}, ], )
def test_run_installs_extras_with_deps_if_requested_locked( installer, locker, repo, package): locker.locked(True) locker.mock_lock_data(fixture("extras-with-dependencies")) package.extras["foo"] = [get_dependency("C")] package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_d = get_package("D", "1.1") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) package.add_dependency("A", "^1.0") package.add_dependency("B", "^1.0") package.add_dependency("C", {"version": "^1.0", "optional": True}) package_c.add_dependency("D", "^1.0") installer.extras(["foo"]) installer.run() # But should not be installed installer = installer.installer assert len(installer.installs) == 4 # A, B, C, D
def test_run_installs_extras_with_deps_if_requested_locked( installer, locker, repo, package ): locker.locked(True) locker.mock_lock_data(fixture("extras-with-dependencies")) package.extras["foo"] = [get_dependency("C")] package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_d = get_package("D", "1.1") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) package.add_dependency("A", "^1.0") package.add_dependency("B", "^1.0") package.add_dependency("C", {"version": "^1.0", "optional": True}) package_c.add_dependency("D", "^1.0") installer.extras(["foo"]) installer.run() # But should not be installed installer = installer.installer assert len(installer.installs) == 4 # A, B, C, D
def test_solver_install_single(solver, repo): package_a = get_package('A', '1.0') repo.add_package(package_a) ops = solver.solve([get_dependency('A')]) check_solver_result(ops, [{'job': 'install', 'package': package_a}])
def test_add_constraint_with_extras(app, repo, installer): command = app.find("add") tester = CommandTester(command) cachy2 = get_package("cachy", "0.2.0") cachy2.extras = {"msgpack": [get_dependency("msgpack-python")]} msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) cachy2.requires = [msgpack_dep] repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(cachy2) repo.add_package(get_package("msgpack-python", "0.5.3")) tester.execute( [ ("command", command.get_name()), ("name", ["cachy=0.2.0"]), ("--extras", ["msgpack"]), ] ) expected = """\ Updating dependencies Resolving dependencies... Package operations: 2 installs, 0 updates, 0 removals Writing lock file - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) """ assert tester.get_display(True) == expected assert len(installer.installs) == 2 content = app.poetry.file.read()["tool"]["poetry"] assert "cachy" in content["dependencies"] assert content["dependencies"]["cachy"] == { "version": "0.2.0", "extras": ["msgpack"], }
def test_solver_fails_if_mismatch_root_python_versions(solver, repo, package): package.python_versions = '^3.4' package_a = get_package('A', '1.0') package_b = get_package('B', '1.0') package_b.python_versions = '^3.6' package_c = get_package('C', '1.0') package_c.python_versions = '~3.3' package_b.add_dependency('C', '~1.0') repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) request = [get_dependency('A'), get_dependency('B')] with pytest.raises(SolverProblemError): solver.solve(request)
def test_search_for_vcs_setup_egg_info_with_extras(provider): dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git") dependency.extras.append("foo") package = provider.search_for_vcs(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" assert package.requires == [ get_dependency("pendulum", ">=1.4.4"), get_dependency("cleo", optional=True), ] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_convert_dependencies(): package = Package('foo', '1.2.3') result = SdistBuilder.convert_dependencies(package, [ get_dependency('A', '^1.0'), get_dependency('B', '~1.0'), get_dependency('C', '1.2.3'), ]) main = [ 'A (>=1.0.0.0,<2.0.0.0)', 'B (>=1.0.0.0,<1.1.0.0)', 'C (==1.2.3.0)', ] extras = {} assert result == (main, extras) package = Package('foo', '1.2.3') package.extras = {'bar': [get_dependency('A')]} result = SdistBuilder.convert_dependencies(package, [ get_dependency('A', '>=1.2', optional=True), get_dependency('B', '~1.0'), get_dependency('C', '1.2.3'), ]) main = [ 'B (>=1.0.0.0,<1.1.0.0)', 'C (==1.2.3.0)', ] extras = {'bar': ['A (>=1.2.0.0)']} assert result == (main, extras)
def test_solver_sub_dependencies_with_requirements(solver, repo): package_a = get_package('A', '1.0') package_b = get_package('B', '1.0') package_c = get_package('C', '1.0') package_d = get_package('D', '1.0') package_c.add_dependency('D', {'version': '^1.0', 'python': '<4.0'}) package_a.add_dependency('C') package_b.add_dependency('D', '^1.0') repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) dependency_a = get_dependency('A') dependency_b = get_dependency('B') request = [ dependency_a, dependency_b, ] ops = solver.solve(request) check_solver_result(ops, [ { 'job': 'install', 'package': package_c }, { 'job': 'install', 'package': package_d }, { 'job': 'install', 'package': package_a }, { 'job': 'install', 'package': package_b }, ]) op = ops[1] assert op.package.requirements == {}
def test_solver_with_dependency_in_both_main_and_dev_dependencies( solver, repo, package): package.python_versions = '^3.5' package.add_dependency('A') package.add_dependency('A', { 'version': '*', 'extras': ['foo'] }, category='dev') package_a = get_package('A', '1.0') package_a.extras['foo'] = [get_dependency('C')] package_a.add_dependency('C', {'version': '^1.0', 'optional': True}) package_a.add_dependency('B', {'version': '^1.0'}) package_b = get_package('B', '1.0') package_c = get_package('C', '1.0') package_c.add_dependency('D', '^1.0') package_d = get_package('D', '1.0') repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) ops = solver.solve() check_solver_result(ops, [ { 'job': 'install', 'package': package_b }, { 'job': 'install', 'package': package_c }, { 'job': 'install', 'package': package_d }, { 'job': 'install', 'package': package_a }, ]) b = ops[0].package c = ops[1].package d = ops[2].package a = ops[3].package assert d.category == 'dev' assert c.category == 'dev' assert b.category == 'main' assert a.category == 'main'
def test_solver_install_single(solver, repo, package): package.add_dependency("A") package_a = get_package("A", "1.0") repo.add_package(package_a) ops = solver.solve([get_dependency("A")]) check_solver_result(ops, [{"job": "install", "package": package_a}])
def test_search_for_directory_setup_read_setup(provider, mocker): mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = DirectoryDependency( "demo", Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo" / "demo", ) package = provider.search_for_directory(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" assert package.requires == [get_dependency("pendulum", ">=1.4.4")] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_search_for_vcs_read_setup_with_extras(provider, mocker): mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git") dependency.extras.append("foo") package = provider.search_for_vcs(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" assert package.requires == [ get_dependency("pendulum", ">=1.4.4"), get_dependency("cleo", optional=True), ] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_add_constraint_with_extras(app, repo, installer): command = app.find('add') tester = CommandTester(command) cachy2 = get_package('cachy', '0.2.0') cachy2.extras = {'msgpack': [get_dependency('msgpack-python')]} msgpack_dep = get_dependency('msgpack-python', '>=0.5 <0.6', optional=True) cachy2.requires = [ msgpack_dep, ] repo.add_package(get_package('cachy', '0.1.0')) repo.add_package(cachy2) repo.add_package(get_package('msgpack-python', '0.5.3')) tester.execute([('command', command.get_name()), ('name', ['cachy=0.2.0']), ('--extras', ['msgpack'])]) expected = """\ Updating dependencies Resolving dependencies... Package operations: 2 installs, 0 updates, 0 removals Writing lock file - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) """ assert tester.get_display() == expected assert len(installer.installs) == 2 content = app.poetry.file.read(raw=True)['tool']['poetry'] assert 'cachy' in content['dependencies'] assert content['dependencies']['cachy'] == { 'version': '0.2.0', 'extras': ['msgpack'] }
def test_search_for_file_sdist_with_extras(provider): dependency = FileDependency( "demo", Path(__file__).parent.parent / "fixtures" / "distributions" / "demo-0.1.0.tar.gz", ) dependency.extras.append("foo") package = provider.search_for_file(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.0" assert package.requires == [ get_dependency("pendulum", ">=1.4.4"), get_dependency("cleo", optional=True), ] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_install_installed(solver, repo, installed): installed.add_package(get_package('A', '1.0')) repo.add_package(get_package('A', '1.0')) request = [ get_dependency('A'), ] ops = solver.solve(request) check_solver_result(ops, [])
def test_add_constraint_with_extras_option_old_installer( app: "PoetryTestApplication", repo: "TestRepository", installer: "NoopInstaller", old_tester: "CommandTester", ): cachy2 = get_package("cachy", "0.2.0") cachy2.extras = {"msgpack": [get_dependency("msgpack-python")]} msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True) cachy2.add_dependency(msgpack_dep) repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(cachy2) repo.add_package(get_package("msgpack-python", "0.5.3")) old_tester.execute("cachy=0.2.0 --extras msgpack") expected = """\ Updating dependencies Resolving dependencies... Writing lock file Package operations: 2 installs, 0 updates, 0 removals - Installing msgpack-python (0.5.3) - Installing cachy (0.2.0) """ assert expected == old_tester.io.fetch_output() assert len(installer.installs) == 2 content = app.poetry.file.read()["tool"]["poetry"] assert "cachy" in content["dependencies"] assert content["dependencies"]["cachy"] == { "version": "0.2.0", "extras": ["msgpack"], }
def test_search_for_directory_setup_egg_info_with_extras(provider: Provider): dependency = DirectoryDependency( "demo", Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo" / "demo", extras=["foo"], ) package = provider.search_for_directory(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" required = [r for r in package.requires if not r.is_optional()] optional = [r for r in package.requires if r.is_optional()] assert required == [get_dependency("pendulum", ">=1.4.4")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], }
def test_search_for_directory_setup_with_base(provider, directory): dependency = DirectoryDependency( "demo", Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo" / directory, base=Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo" / directory, ) package = provider.search_for_directory(dependency)[0] assert package.name == "demo" assert package.version.text == "0.1.2" assert package.requires == [get_dependency("pendulum", ">=1.4.4")] assert package.extras == { "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], } assert (package.root_dir == (Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo" / directory).as_posix())
def test_update_with_fixed(solver, repo, installed): installed.add_package(get_package('A', '1.0')) package_a = get_package('A', '1.0') new_package_a = get_package('A', '1.1') repo.add_package(package_a) repo.add_package(new_package_a) request = [ get_dependency('A'), ] ops = solver.solve(request, fixed=[get_dependency('A', '1.0')]) check_solver_result(ops, [ { 'job': 'install', 'package': package_a, 'skipped': True }, ])
def test_solver_with_dependency_in_both_main_and_dev_dependencies_with_one_more_dependent( solver, repo, package ): package.add_dependency("A") package.add_dependency("E") package.add_dependency("A", {"version": "*", "extras": ["foo"]}, category="dev") package_a = get_package("A", "1.0") package_a.extras["foo"] = [get_dependency("C")] package_a.add_dependency("C", {"version": "^1.0", "optional": True}) package_a.add_dependency("B", {"version": "^1.0"}) package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_c.add_dependency("D", "^1.0") package_d = get_package("D", "1.0") package_e = get_package("E", "1.0") package_e.add_dependency("A", "^1.0") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) repo.add_package(package_d) repo.add_package(package_e) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": package_b}, {"job": "install", "package": package_d}, {"job": "install", "package": package_a}, {"job": "install", "package": package_c}, {"job": "install", "package": package_e}, ], ) b = ops[0].package c = ops[3].package d = ops[1].package a = ops[2].package e = ops[4].package assert d.category == "dev" assert c.category == "dev" assert b.category == "main" assert a.category == "main" assert e.category == "main"
def test_run_with_dependencies_extras(installer, locker, repo, package): package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_b.extras = {"foo": [get_dependency("C", "^1.0")]} package_b.add_dependency("C", {"version": "^1.0", "optional": True}) repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) package.add_dependency("A", "^1.0") package.add_dependency("B", {"version": "^1.0", "extras": ["foo"]}) installer.run() expected = fixture("with-dependencies-extras") assert locker.written_data == expected
def test_solver_with_deps(solver, repo, package): package.add_dependency("A") package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") new_package_b = get_package("B", "1.1") repo.add_package(package_a) repo.add_package(package_b) repo.add_package(new_package_b) package_a.requires.append(get_dependency("B", "<1.1")) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": package_b}, {"job": "install", "package": package_a}, ], )
def test_solver_does_not_return_extras_if_not_requested(solver, repo, package): package.add_dependency("A") package.add_dependency("B") package_a = get_package("A", "1.0") package_b = get_package("B", "1.0") package_c = get_package("C", "1.0") package_b.extras = {"foo": [get_dependency("C", "^1.0")]} repo.add_package(package_a) repo.add_package(package_b) repo.add_package(package_c) ops = solver.solve() check_solver_result( ops, [ {"job": "install", "package": package_a}, {"job": "install", "package": package_b}, ], )
def test_run_update_with_locked_extras(installer, locker, repo, package): locker.locked(True) locker.mock_lock_data( { "package": [ { "name": "A", "version": "1.0", "category": "main", "optional": False, "platform": "*", "python-versions": "*", "checksum": [], "dependencies": {"B": "^1.0", "C": "^1.0"}, }, { "name": "B", "version": "1.0", "category": "dev", "optional": False, "platform": "*", "python-versions": "*", "checksum": [], }, { "name": "C", "version": "1.1", "category": "dev", "optional": False, "platform": "*", "python-versions": "*", "checksum": [], "requirements": {"python": "~2.7"}, }, ], "metadata": { "python-versions": "*", "platform": "*", "content-hash": "123456789", "hashes": {"A": [], "B": [], "C": []}, }, } ) package_a = get_package("A", "1.0") package_a.extras["foo"] = [get_dependency("B")] b_dependency = get_dependency("B", "^1.0", optional=True) b_dependency.in_extras.append("foo") c_dependency = get_dependency("C", "^1.0") c_dependency.python_versions = "~2.7" package_a.requires.append(b_dependency) package_a.requires.append(c_dependency) repo.add_package(package_a) repo.add_package(get_package("B", "1.0")) repo.add_package(get_package("C", "1.1")) repo.add_package(get_package("D", "1.1")) package.add_dependency("A", {"version": "^1.0", "extras": ["foo"]}) package.add_dependency("D", "^1.0") installer.update(True) installer.whitelist("D") installer.run() expected = fixture("update-with-locked-extras") assert locker.written_data == expected