How to use get_package method in Airtest

Best Python code snippet using Airtest

test_solver.py

Source:test_solver.py Github

copy

Full Screen

...97def test_solver_install_single(98 solver: Solver, repo: Repository, package: ProjectPackage99):100 package.add_dependency(Factory.create_dependency("A", "*"))101 package_a = get_package("A", "1.0")102 repo.add_package(package_a)103 transaction = solver.solve([get_dependency("A")])104 check_solver_result(transaction, [{"job": "install", "package": package_a}])105def test_solver_remove_if_no_longer_locked(106 solver: Solver, locked: Repository, installed: InstalledRepository107):108 package_a = get_package("A", "1.0")109 installed.add_package(package_a)110 locked.add_package(package_a)111 transaction = solver.solve()112 check_solver_result(transaction, [{"job": "remove", "package": package_a}])113def test_remove_non_installed(solver: Solver, repo: Repository, locked: Repository):114 package_a = get_package("A", "1.0")115 locked.add_package(package_a)116 repo.add_package(package_a)117 request = []118 transaction = solver.solve(request)119 check_solver_result(transaction, [])120def test_install_non_existing_package_fail(121 solver: Solver, repo: Repository, package: ProjectPackage122):123 package.add_dependency(Factory.create_dependency("B", "1"))124 package_a = get_package("A", "1.0")125 repo.add_package(package_a)126 with pytest.raises(SolverProblemError):127 solver.solve()128def test_solver_with_deps(solver: Solver, repo: Repository, package: ProjectPackage):129 package.add_dependency(Factory.create_dependency("A", "*"))130 package_a = get_package("A", "1.0")131 package_b = get_package("B", "1.0")132 new_package_b = get_package("B", "1.1")133 repo.add_package(package_a)134 repo.add_package(package_b)135 repo.add_package(new_package_b)136 package_a.add_dependency(get_dependency("B", "<1.1"))137 transaction = solver.solve()138 check_solver_result(139 transaction,140 [141 {"job": "install", "package": package_b},142 {"job": "install", "package": package_a},143 ],144 )145def test_install_honours_not_equal(146 solver: Solver, repo: Repository, package: ProjectPackage147):148 package.add_dependency(Factory.create_dependency("A", "*"))149 package_a = get_package("A", "1.0")150 package_b = get_package("B", "1.0")151 new_package_b11 = get_package("B", "1.1")152 new_package_b12 = get_package("B", "1.2")153 new_package_b13 = get_package("B", "1.3")154 repo.add_package(package_a)155 repo.add_package(package_b)156 repo.add_package(new_package_b11)157 repo.add_package(new_package_b12)158 repo.add_package(new_package_b13)159 package_a.add_dependency(get_dependency("B", "<=1.3,!=1.3,!=1.2"))160 transaction = solver.solve()161 check_solver_result(162 transaction,163 [164 {"job": "install", "package": new_package_b11},165 {"job": "install", "package": package_a},166 ],167 )168def test_install_with_deps_in_order(169 solver: Solver, repo: Repository, package: ProjectPackage170):171 package.add_dependency(Factory.create_dependency("A", "*"))172 package.add_dependency(Factory.create_dependency("B", "*"))173 package.add_dependency(Factory.create_dependency("C", "*"))174 package_a = get_package("A", "1.0")175 package_b = get_package("B", "1.0")176 package_c = get_package("C", "1.0")177 repo.add_package(package_a)178 repo.add_package(package_b)179 repo.add_package(package_c)180 package_b.add_dependency(get_dependency("A", ">=1.0"))181 package_b.add_dependency(get_dependency("C", ">=1.0"))182 package_c.add_dependency(get_dependency("A", ">=1.0"))183 transaction = solver.solve()184 check_solver_result(185 transaction,186 [187 {"job": "install", "package": package_a},188 {"job": "install", "package": package_c},189 {"job": "install", "package": package_b},190 ],191 )192def test_install_installed(193 solver: Solver,194 repo: Repository,195 installed: InstalledRepository,196 package: ProjectPackage,197):198 package.add_dependency(Factory.create_dependency("A", "*"))199 package_a = get_package("A", "1.0")200 installed.add_package(package_a)201 repo.add_package(package_a)202 transaction = solver.solve()203 check_solver_result(204 transaction, [{"job": "install", "package": package_a, "skipped": True}]205 )206def test_update_installed(207 solver: Solver,208 repo: Repository,209 installed: InstalledRepository,210 package: ProjectPackage,211):212 package.add_dependency(Factory.create_dependency("A", "*"))213 installed.add_package(get_package("A", "1.0"))214 package_a = get_package("A", "1.0")215 new_package_a = get_package("A", "1.1")216 repo.add_package(package_a)217 repo.add_package(new_package_a)218 transaction = solver.solve()219 check_solver_result(220 transaction, [{"job": "update", "from": package_a, "to": new_package_a}]221 )222def test_update_with_use_latest(223 solver: Solver,224 repo: Repository,225 installed: InstalledRepository,226 package: ProjectPackage,227 locked: Repository,228):229 package.add_dependency(Factory.create_dependency("A", "*"))230 package.add_dependency(Factory.create_dependency("B", "*"))231 installed.add_package(get_package("A", "1.0"))232 package_a = get_package("A", "1.0")233 new_package_a = get_package("A", "1.1")234 package_b = get_package("B", "1.0")235 new_package_b = get_package("B", "1.1")236 repo.add_package(package_a)237 repo.add_package(new_package_a)238 repo.add_package(package_b)239 repo.add_package(new_package_b)240 locked.add_package(package_a)241 locked.add_package(package_b)242 transaction = solver.solve(use_latest=[package_b.name])243 check_solver_result(244 transaction,245 [246 {"job": "install", "package": package_a, "skipped": True},247 {"job": "install", "package": new_package_b},248 ],249 )250def test_solver_sets_groups(solver: Solver, repo: Repository, package: ProjectPackage):251 package.add_dependency(Factory.create_dependency("A", "*"))252 package.add_dependency(Factory.create_dependency("B", "*", groups=["dev"]))253 package_a = get_package("A", "1.0")254 package_b = get_package("B", "1.0")255 package_c = get_package("C", "1.0")256 package_b.add_dependency(Factory.create_dependency("C", "~1.0"))257 repo.add_package(package_a)258 repo.add_package(package_b)259 repo.add_package(package_c)260 transaction = solver.solve()261 ops = check_solver_result(262 transaction,263 [264 {"job": "install", "package": package_c},265 {"job": "install", "package": package_a},266 {"job": "install", "package": package_b},267 ],268 )269 assert ops[0].package.category == "dev"270 assert ops[2].package.category == "dev"271 assert ops[1].package.category == "main"272def test_solver_respects_root_package_python_versions(273 solver: Solver, repo: Repository, package: ProjectPackage274):275 solver.provider.set_package_python_versions("~3.4")276 package.add_dependency(Factory.create_dependency("A", "*"))277 package.add_dependency(Factory.create_dependency("B", "*"))278 package_a = get_package("A", "1.0")279 package_b = get_package("B", "1.0")280 package_b.python_versions = "^3.3"281 package_c = get_package("C", "1.0")282 package_c.python_versions = "^3.4"283 package_c11 = get_package("C", "1.1")284 package_c11.python_versions = "^3.6"285 package_b.add_dependency(Factory.create_dependency("C", "^1.0"))286 repo.add_package(package_a)287 repo.add_package(package_b)288 repo.add_package(package_c)289 repo.add_package(package_c11)290 transaction = solver.solve()291 check_solver_result(292 transaction,293 [294 {"job": "install", "package": package_c},295 {"job": "install", "package": package_a},296 {"job": "install", "package": package_b},297 ],298 )299def test_solver_fails_if_mismatch_root_python_versions(300 solver: Solver, repo: Repository, package: ProjectPackage301):302 solver.provider.set_package_python_versions("^3.4")303 package.add_dependency(Factory.create_dependency("A", "*"))304 package.add_dependency(Factory.create_dependency("B", "*"))305 package_a = get_package("A", "1.0")306 package_b = get_package("B", "1.0")307 package_b.python_versions = "^3.6"308 package_c = get_package("C", "1.0")309 package_c.python_versions = "~3.3"310 package_b.add_dependency(Factory.create_dependency("C", "~1.0"))311 repo.add_package(package_a)312 repo.add_package(package_b)313 repo.add_package(package_c)314 with pytest.raises(SolverProblemError):315 solver.solve()316def test_solver_solves_optional_and_compatible_packages(317 solver: Solver, repo: Repository, package: ProjectPackage318):319 solver.provider.set_package_python_versions("~3.4")320 package.extras["foo"] = [get_dependency("B")]321 package.add_dependency(322 Factory.create_dependency("A", {"version": "*", "python": "^3.4"})323 )324 package.add_dependency(325 Factory.create_dependency("B", {"version": "*", "optional": True})326 )327 package_a = get_package("A", "1.0")328 package_b = get_package("B", "1.0")329 package_b.python_versions = "^3.3"330 package_c = get_package("C", "1.0")331 package_c.python_versions = "^3.4"332 package_b.add_dependency(Factory.create_dependency("C", "^1.0"))333 repo.add_package(package_a)334 repo.add_package(package_b)335 repo.add_package(package_c)336 transaction = solver.solve()337 check_solver_result(338 transaction,339 [340 {"job": "install", "package": package_c},341 {"job": "install", "package": package_a},342 {"job": "install", "package": package_b},343 ],344 )345def test_solver_does_not_return_extras_if_not_requested(346 solver: Solver, repo: Repository, package: ProjectPackage347):348 package.add_dependency(Factory.create_dependency("A", "*"))349 package.add_dependency(Factory.create_dependency("B", "*"))350 package_a = get_package("A", "1.0")351 package_b = get_package("B", "1.0")352 package_c = get_package("C", "1.0")353 package_b.extras = {"foo": [get_dependency("C", "^1.0")]}354 repo.add_package(package_a)355 repo.add_package(package_b)356 repo.add_package(package_c)357 transaction = solver.solve()358 check_solver_result(359 transaction,360 [361 {"job": "install", "package": package_a},362 {"job": "install", "package": package_b},363 ],364 )365def test_solver_returns_extras_if_requested(366 solver: Solver, repo: Repository, package: ProjectPackage367):368 package.add_dependency(Factory.create_dependency("A", "*"))369 package.add_dependency(370 Factory.create_dependency("B", {"version": "*", "extras": ["foo"]})371 )372 package_a = get_package("A", "1.0")373 package_b = get_package("B", "1.0")374 package_c = get_package("C", "1.0")375 dep = get_dependency("C", "^1.0", optional=True)376 dep.marker = parse_marker("extra == 'foo'")377 package_b.extras = {"foo": [dep]}378 package_b.add_dependency(dep)379 repo.add_package(package_a)380 repo.add_package(package_b)381 repo.add_package(package_c)382 transaction = solver.solve()383 ops = check_solver_result(384 transaction,385 [386 {"job": "install", "package": package_c},387 {"job": "install", "package": package_a},388 {"job": "install", "package": package_b},389 ],390 )391 assert ops[-1].package.marker.is_any()392 assert ops[0].package.marker.is_any()393@pytest.mark.parametrize("enabled_extra", ["one", "two", None])394def test_solver_returns_extras_only_requested(395 solver: Solver,396 repo: Repository,397 package: ProjectPackage,398 enabled_extra: bool | None,399):400 extras = [enabled_extra] if enabled_extra is not None else []401 package.add_dependency(Factory.create_dependency("A", "*"))402 package.add_dependency(403 Factory.create_dependency("B", {"version": "*", "extras": extras})404 )405 package_a = get_package("A", "1.0")406 package_b = get_package("B", "1.0")407 package_c10 = get_package("C", "1.0")408 package_c20 = get_package("C", "2.0")409 dep10 = get_dependency("C", "1.0", optional=True)410 dep10._in_extras.append("one")411 dep10.marker = parse_marker("extra == 'one'")412 dep20 = get_dependency("C", "2.0", optional=True)413 dep20._in_extras.append("two")414 dep20.marker = parse_marker("extra == 'two'")415 package_b.extras = {"one": [dep10], "two": [dep20]}416 package_b.add_dependency(dep10)417 package_b.add_dependency(dep20)418 repo.add_package(package_a)419 repo.add_package(package_b)420 repo.add_package(package_c10)421 repo.add_package(package_c20)422 transaction = solver.solve()423 expected = [424 {"job": "install", "package": package_a},425 {"job": "install", "package": package_b},426 ]427 if enabled_extra is not None:428 expected.insert(429 0,430 {431 "job": "install",432 "package": package_c10 if enabled_extra == "one" else package_c20,433 },434 )435 ops = check_solver_result(436 transaction,437 expected,438 )439 assert ops[-1].package.marker.is_any()440 assert ops[0].package.marker.is_any()441@pytest.mark.parametrize("enabled_extra", ["one", "two", None])442def test_solver_returns_extras_when_multiple_extras_use_same_dependency(443 solver: Solver,444 repo: Repository,445 package: ProjectPackage,446 enabled_extra: bool | None,447):448 package.add_dependency(Factory.create_dependency("A", "*"))449 package_a = get_package("A", "1.0")450 package_b = get_package("B", "1.0")451 package_c = get_package("C", "1.0")452 dep = get_dependency("C", "*", optional=True)453 dep._in_extras.append("one")454 dep._in_extras.append("two")455 package_b.extras = {"one": [dep], "two": [dep]}456 package_b.add_dependency(dep)457 extras = [enabled_extra] if enabled_extra is not None else []458 package_a.add_dependency(459 Factory.create_dependency("B", {"version": "*", "extras": extras})460 )461 repo.add_package(package_a)462 repo.add_package(package_b)463 repo.add_package(package_c)464 transaction = solver.solve()465 expected = [466 {"job": "install", "package": package_b},467 {"job": "install", "package": package_a},468 ]469 if enabled_extra is not None:470 expected.insert(0, {"job": "install", "package": package_c})471 ops = check_solver_result(472 transaction,473 expected,474 )475 assert ops[-1].package.marker.is_any()476 assert ops[0].package.marker.is_any()477@pytest.mark.parametrize("enabled_extra", ["one", "two", None])478def test_solver_returns_extras_only_requested_nested(479 solver: Solver,480 repo: Repository,481 package: ProjectPackage,482 enabled_extra: bool | None,483):484 package.add_dependency(Factory.create_dependency("A", "*"))485 package_a = get_package("A", "1.0")486 package_b = get_package("B", "1.0")487 package_c10 = get_package("C", "1.0")488 package_c20 = get_package("C", "2.0")489 dep10 = get_dependency("C", "1.0", optional=True)490 dep10._in_extras.append("one")491 dep10.marker = parse_marker("extra == 'one'")492 dep20 = get_dependency("C", "2.0", optional=True)493 dep20._in_extras.append("two")494 dep20.marker = parse_marker("extra == 'two'")495 package_b.extras = {"one": [dep10], "two": [dep20]}496 package_b.add_dependency(dep10)497 package_b.add_dependency(dep20)498 extras = [enabled_extra] if enabled_extra is not None else []499 package_a.add_dependency(500 Factory.create_dependency("B", {"version": "*", "extras": extras})501 )502 repo.add_package(package_a)503 repo.add_package(package_b)504 repo.add_package(package_c10)505 repo.add_package(package_c20)506 transaction = solver.solve()507 expected = [508 {"job": "install", "package": package_b},509 {"job": "install", "package": package_a},510 ]511 if enabled_extra is not None:512 expected.insert(513 0,514 {515 "job": "install",516 "package": package_c10 if enabled_extra == "one" else package_c20,517 },518 )519 ops = check_solver_result(transaction, expected)520 assert ops[-1].package.marker.is_any()521 assert ops[0].package.marker.is_any()522def test_solver_returns_prereleases_if_requested(523 solver: Solver, repo: Repository, package: ProjectPackage524):525 package.add_dependency(Factory.create_dependency("A", "*"))526 package.add_dependency(Factory.create_dependency("B", "*"))527 package.add_dependency(528 Factory.create_dependency("C", {"version": "*", "allow-prereleases": True})529 )530 package_a = get_package("A", "1.0")531 package_b = get_package("B", "1.0")532 package_c = get_package("C", "1.0")533 package_c_dev = get_package("C", "1.1-beta.1")534 repo.add_package(package_a)535 repo.add_package(package_b)536 repo.add_package(package_c)537 repo.add_package(package_c_dev)538 transaction = solver.solve()539 check_solver_result(540 transaction,541 [542 {"job": "install", "package": package_a},543 {"job": "install", "package": package_b},544 {"job": "install", "package": package_c_dev},545 ],546 )547def test_solver_does_not_return_prereleases_if_not_requested(548 solver: Solver, repo: Repository, package: ProjectPackage549):550 package.add_dependency(Factory.create_dependency("A", "*"))551 package.add_dependency(Factory.create_dependency("B", "*"))552 package.add_dependency(Factory.create_dependency("C", "*"))553 package_a = get_package("A", "1.0")554 package_b = get_package("B", "1.0")555 package_c = get_package("C", "1.0")556 package_c_dev = get_package("C", "1.1-beta.1")557 repo.add_package(package_a)558 repo.add_package(package_b)559 repo.add_package(package_c)560 repo.add_package(package_c_dev)561 transaction = solver.solve()562 check_solver_result(563 transaction,564 [565 {"job": "install", "package": package_a},566 {"job": "install", "package": package_b},567 {"job": "install", "package": package_c},568 ],569 )570def test_solver_sub_dependencies_with_requirements(571 solver: Solver, repo: Repository, package: ProjectPackage572):573 package.add_dependency(Factory.create_dependency("A", "*"))574 package.add_dependency(Factory.create_dependency("B", "*"))575 package_a = get_package("A", "1.0")576 package_b = get_package("B", "1.0")577 package_c = get_package("C", "1.0")578 package_d = get_package("D", "1.0")579 package_c.add_dependency(580 Factory.create_dependency("D", {"version": "^1.0", "python": "<4.0"})581 )582 package_a.add_dependency(Factory.create_dependency("C", "*"))583 package_b.add_dependency(Factory.create_dependency("D", "^1.0"))584 repo.add_package(package_a)585 repo.add_package(package_b)586 repo.add_package(package_c)587 repo.add_package(package_d)588 transaction = solver.solve()589 ops = check_solver_result(590 transaction,591 [592 {"job": "install", "package": package_d},593 {"job": "install", "package": package_c},594 {"job": "install", "package": package_a},595 {"job": "install", "package": package_b},596 ],597 )598 op = ops[1]599 assert op.package.marker.is_any()600def test_solver_sub_dependencies_with_requirements_complex(601 solver: Solver, repo: Repository, package: ProjectPackage602):603 package.add_dependency(604 Factory.create_dependency("A", {"version": "^1.0", "python": "<5.0"})605 )606 package.add_dependency(607 Factory.create_dependency("B", {"version": "^1.0", "python": "<5.0"})608 )609 package.add_dependency(610 Factory.create_dependency("C", {"version": "^1.0", "python": "<4.0"})611 )612 package_a = get_package("A", "1.0")613 package_b = get_package("B", "1.0")614 package_c = get_package("C", "1.0")615 package_d = get_package("D", "1.0")616 package_e = get_package("E", "1.0")617 package_f = get_package("F", "1.0")618 package_a.add_dependency(619 Factory.create_dependency("B", {"version": "^1.0", "python": "<4.0"})620 )621 package_a.add_dependency(622 Factory.create_dependency("D", {"version": "^1.0", "python": "<4.0"})623 )624 package_b.add_dependency(625 Factory.create_dependency("E", {"version": "^1.0", "platform": "win32"})626 )627 package_b.add_dependency(628 Factory.create_dependency("F", {"version": "^1.0", "python": "<5.0"})629 )630 package_c.add_dependency(631 Factory.create_dependency("F", {"version": "^1.0", "python": "<4.0"})632 )633 package_d.add_dependency(Factory.create_dependency("F", "*"))634 repo.add_package(package_a)635 repo.add_package(package_b)636 repo.add_package(package_c)637 repo.add_package(package_d)638 repo.add_package(package_e)639 repo.add_package(package_f)640 transaction = solver.solve()641 check_solver_result(642 transaction,643 [644 {"job": "install", "package": package_e},645 {"job": "install", "package": package_f},646 {"job": "install", "package": package_b},647 {"job": "install", "package": package_d},648 {"job": "install", "package": package_a},649 {"job": "install", "package": package_c},650 ],651 )652def test_solver_sub_dependencies_with_not_supported_python_version(653 solver: Solver, repo: Repository, package: Package654):655 solver.provider.set_package_python_versions("^3.5")656 package.add_dependency(Factory.create_dependency("A", "*"))657 package_a = get_package("A", "1.0")658 package_b = get_package("B", "1.0")659 package_b.python_versions = "<2.0"660 package_a.add_dependency(661 Factory.create_dependency("B", {"version": "^1.0", "python": "<2.0"})662 )663 repo.add_package(package_a)664 repo.add_package(package_b)665 transaction = solver.solve()666 check_solver_result(transaction, [{"job": "install", "package": package_a}])667def test_solver_sub_dependencies_with_not_supported_python_version_transitive(668 solver: Solver, repo: Repository, package: Package669):670 solver.provider.set_package_python_versions("^3.4")671 package.add_dependency(672 Factory.create_dependency("httpx", {"version": "^0.17.1", "python": "^3.6"})673 )674 httpx = get_package("httpx", "0.17.1")675 httpx.python_versions = ">=3.6"676 httpcore = get_package("httpcore", "0.12.3")677 httpcore.python_versions = ">=3.6"678 sniffio_1_1_0 = get_package("sniffio", "1.1.0")679 sniffio_1_1_0.python_versions = ">=3.5"680 sniffio = get_package("sniffio", "1.2.0")681 sniffio.python_versions = ">=3.5"682 httpx.add_dependency(683 Factory.create_dependency("httpcore", {"version": ">=0.12.1,<0.13"})684 )685 httpx.add_dependency(Factory.create_dependency("sniffio", {"version": "*"}))686 httpcore.add_dependency(Factory.create_dependency("sniffio", {"version": "==1.*"}))687 repo.add_package(httpx)688 repo.add_package(httpcore)689 repo.add_package(sniffio)690 repo.add_package(sniffio_1_1_0)691 transaction = solver.solve()692 check_solver_result(693 transaction,694 [695 {"job": "install", "package": sniffio, "skipped": False},696 {"job": "install", "package": httpcore, "skipped": False},697 {"job": "install", "package": httpx, "skipped": False},698 ],699 )700def test_solver_with_dependency_in_both_default_and_dev_dependencies(701 solver: Solver, repo: Repository, package: Package702):703 solver.provider.set_package_python_versions("^3.5")704 package.add_dependency(Factory.create_dependency("A", "*"))705 package.add_dependency(706 Factory.create_dependency(707 "A", {"version": "*", "extras": ["foo"]}, groups=["dev"]708 )709 )710 package_a = get_package("A", "1.0")711 package_a.extras["foo"] = [get_dependency("C")]712 package_a.add_dependency(713 Factory.create_dependency("C", {"version": "^1.0", "optional": True})714 )715 package_a.add_dependency(Factory.create_dependency("B", {"version": "^1.0"}))716 package_b = get_package("B", "1.0")717 package_c = get_package("C", "1.0")718 package_c.add_dependency(Factory.create_dependency("D", "^1.0"))719 package_d = get_package("D", "1.0")720 repo.add_package(package_a)721 repo.add_package(package_b)722 repo.add_package(package_c)723 repo.add_package(package_d)724 transaction = solver.solve()725 ops = check_solver_result(726 transaction,727 [728 {"job": "install", "package": package_d},729 {"job": "install", "package": package_b},730 {"job": "install", "package": package_c},731 {"job": "install", "package": package_a},732 ],733 )734 d = ops[0].package735 b = ops[1].package736 c = ops[2].package737 a = ops[3].package738 assert d.category == "dev"739 assert b.category == "main"740 assert c.category == "dev"741 assert a.category == "main"742def test_solver_with_dependency_in_both_main_and_dev_dependencies_with_one_more_dependent( # noqa: E501743 solver: Solver, repo: Repository, package: Package744):745 package.add_dependency(Factory.create_dependency("A", "*"))746 package.add_dependency(Factory.create_dependency("E", "*"))747 package.add_dependency(748 Factory.create_dependency(749 "A", {"version": "*", "extras": ["foo"]}, groups=["dev"]750 )751 )752 package_a = get_package("A", "1.0")753 package_a.extras["foo"] = [get_dependency("C")]754 package_a.add_dependency(755 Factory.create_dependency("C", {"version": "^1.0", "optional": True})756 )757 package_a.add_dependency(Factory.create_dependency("B", {"version": "^1.0"}))758 package_b = get_package("B", "1.0")759 package_c = get_package("C", "1.0")760 package_c.add_dependency(Factory.create_dependency("D", "^1.0"))761 package_d = get_package("D", "1.0")762 package_e = get_package("E", "1.0")763 package_e.add_dependency(Factory.create_dependency("A", "^1.0"))764 repo.add_package(package_a)765 repo.add_package(package_b)766 repo.add_package(package_c)767 repo.add_package(package_d)768 repo.add_package(package_e)769 transaction = solver.solve()770 ops = check_solver_result(771 transaction,772 [773 {"job": "install", "package": package_b},774 {"job": "install", "package": package_d},775 {"job": "install", "package": package_a},776 {"job": "install", "package": package_c},777 {"job": "install", "package": package_e},778 ],779 )780 b = ops[0].package781 d = ops[1].package782 a = ops[2].package783 c = ops[3].package784 e = ops[4].package785 assert b.category == "main"786 assert d.category == "dev"787 assert a.category == "main"788 assert c.category == "dev"789 assert e.category == "main"790def test_solver_with_dependency_and_prerelease_sub_dependencies(791 solver: Solver, repo: Repository, package: ProjectPackage792):793 package.add_dependency(Factory.create_dependency("A", "*"))794 package_a = get_package("A", "1.0")795 package_a.add_dependency(Factory.create_dependency("B", ">=1.0.0.dev2"))796 repo.add_package(package_a)797 repo.add_package(get_package("B", "0.9.0"))798 repo.add_package(get_package("B", "1.0.0.dev1"))799 repo.add_package(get_package("B", "1.0.0.dev2"))800 repo.add_package(get_package("B", "1.0.0.dev3"))801 package_b = get_package("B", "1.0.0.dev4")802 repo.add_package(package_b)803 transaction = solver.solve()804 check_solver_result(805 transaction,806 [807 {"job": "install", "package": package_b},808 {"job": "install", "package": package_a},809 ],810 )811def test_solver_circular_dependency(812 solver: Solver, repo: Repository, package: ProjectPackage813):814 package.add_dependency(Factory.create_dependency("A", "*"))815 package_a = get_package("A", "1.0")816 package_a.add_dependency(Factory.create_dependency("B", "^1.0"))817 package_b = get_package("B", "1.0")818 package_b.add_dependency(Factory.create_dependency("A", "^1.0"))819 package_b.add_dependency(Factory.create_dependency("C", "^1.0"))820 package_c = get_package("C", "1.0")821 repo.add_package(package_a)822 repo.add_package(package_b)823 repo.add_package(package_c)824 transaction = solver.solve()825 ops = check_solver_result(826 transaction,827 [828 {"job": "install", "package": package_c},829 {"job": "install", "package": package_b},830 {"job": "install", "package": package_a},831 ],832 )833 assert ops[0].package.category == "main"834def test_solver_circular_dependency_chain(835 solver: Solver, repo: Repository, package: ProjectPackage836):837 package.add_dependency(Factory.create_dependency("A", "*"))838 package_a = get_package("A", "1.0")839 package_a.add_dependency(Factory.create_dependency("B", "^1.0"))840 package_b = get_package("B", "1.0")841 package_b.add_dependency(Factory.create_dependency("C", "^1.0"))842 package_c = get_package("C", "1.0")843 package_c.add_dependency(Factory.create_dependency("D", "^1.0"))844 package_d = get_package("D", "1.0")845 package_d.add_dependency(Factory.create_dependency("B", "^1.0"))846 repo.add_package(package_a)847 repo.add_package(package_b)848 repo.add_package(package_c)849 repo.add_package(package_d)850 transaction = solver.solve()851 ops = check_solver_result(852 transaction,853 [854 {"job": "install", "package": package_d},855 {"job": "install", "package": package_c},856 {"job": "install", "package": package_b},857 {"job": "install", "package": package_a},858 ],859 )860 assert ops[0].package.category == "main"861def test_solver_dense_dependencies(862 solver: Solver, repo: Repository, package: ProjectPackage863):864 # The root package depends on packages A0...An-1,865 # And package Ai depends on packages A0...Ai-1866 # This graph is a transitive tournament867 packages = []868 n = 22869 for i in range(n):870 package_ai = get_package("a" + str(i), "1.0")871 repo.add_package(package_ai)872 packages.append(package_ai)873 package.add_dependency(Factory.create_dependency("a" + str(i), "^1.0"))874 for j in range(i):875 package_ai.add_dependency(Factory.create_dependency("a" + str(j), "^1.0"))876 transaction = solver.solve()877 check_solver_result(878 transaction, [{"job": "install", "package": packages[i]} for i in range(n)]879 )880def test_solver_duplicate_dependencies_same_constraint(881 solver: Solver, repo: Repository, package: ProjectPackage882):883 package.add_dependency(Factory.create_dependency("A", "*"))884 package_a = get_package("A", "1.0")885 package_a.add_dependency(886 Factory.create_dependency("B", {"version": "^1.0", "python": "2.7"})887 )888 package_a.add_dependency(889 Factory.create_dependency("B", {"version": "^1.0", "python": ">=3.4"})890 )891 package_b = get_package("B", "1.0")892 repo.add_package(package_a)893 repo.add_package(package_b)894 transaction = solver.solve()895 check_solver_result(896 transaction,897 [898 {"job": "install", "package": package_b},899 {"job": "install", "package": package_a},900 ],901 )902def test_solver_duplicate_dependencies_different_constraints(903 solver: Solver, repo: Repository, package: ProjectPackage904):905 package.add_dependency(Factory.create_dependency("A", "*"))906 package_a = get_package("A", "1.0")907 package_a.add_dependency(908 Factory.create_dependency("B", {"version": "^1.0", "python": "<3.4"})909 )910 package_a.add_dependency(911 Factory.create_dependency("B", {"version": "^2.0", "python": ">=3.4"})912 )913 package_b10 = get_package("B", "1.0")914 package_b20 = get_package("B", "2.0")915 repo.add_package(package_a)916 repo.add_package(package_b10)917 repo.add_package(package_b20)918 transaction = solver.solve()919 check_solver_result(920 transaction,921 [922 {"job": "install", "package": package_b10},923 {"job": "install", "package": package_b20},924 {"job": "install", "package": package_a},925 ],926 )927def test_solver_duplicate_dependencies_different_constraints_same_requirements(928 solver: Solver, repo: Repository, package: Package929):930 package.add_dependency(Factory.create_dependency("A", "*"))931 package_a = get_package("A", "1.0")932 package_a.add_dependency(Factory.create_dependency("B", {"version": "^1.0"}))933 package_a.add_dependency(Factory.create_dependency("B", {"version": "^2.0"}))934 package_b10 = get_package("B", "1.0")935 package_b20 = get_package("B", "2.0")936 repo.add_package(package_a)937 repo.add_package(package_b10)938 repo.add_package(package_b20)939 with pytest.raises(SolverProblemError) as e:940 solver.solve()941 expected = """\942Because a (1.0) depends on both B (^1.0) and B (^2.0), a is forbidden.943So, because no versions of a match !=1.0944 and root depends on A (*), version solving failed."""945 assert str(e.value) == expected946def test_solver_duplicate_dependencies_different_constraints_merge_no_markers(947 solver: Solver, repo: Repository, package: Package948):949 package.add_dependency(Factory.create_dependency("A", "*"))950 package.add_dependency(Factory.create_dependency("B", "1.0"))951 package_a10 = get_package("A", "1.0")952 package_a10.add_dependency(Factory.create_dependency("C", {"version": "^1.0"}))953 package_a20 = get_package("A", "2.0")954 package_a20.add_dependency(955 Factory.create_dependency("C", {"version": "^2.0"}) # incompatible with B956 )957 package_a20.add_dependency(958 Factory.create_dependency("C", {"version": "!=2.1", "python": "3.10"})959 )960 package_b = get_package("B", "1.0")961 package_b.add_dependency(Factory.create_dependency("C", {"version": "<2.0"}))962 package_c10 = get_package("C", "1.0")963 package_c20 = get_package("C", "2.0")964 package_c21 = get_package("C", "2.1")965 repo.add_package(package_a10)966 repo.add_package(package_a20)967 repo.add_package(package_b)968 repo.add_package(package_c10)969 repo.add_package(package_c20)970 repo.add_package(package_c21)971 transaction = solver.solve()972 check_solver_result(973 transaction,974 [975 {"job": "install", "package": package_c10},976 {"job": "install", "package": package_a10}, # only a10, not a20977 {"job": "install", "package": package_b},978 ],979 )980def test_solver_duplicate_dependencies_sub_dependencies(981 solver: Solver, repo: Repository, package: ProjectPackage982):983 package.add_dependency(Factory.create_dependency("A", "*"))984 package_a = get_package("A", "1.0")985 package_a.add_dependency(986 Factory.create_dependency("B", {"version": "^1.0", "python": "<3.4"})987 )988 package_a.add_dependency(989 Factory.create_dependency("B", {"version": "^2.0", "python": ">=3.4"})990 )991 package_b10 = get_package("B", "1.0")992 package_b20 = get_package("B", "2.0")993 package_b10.add_dependency(Factory.create_dependency("C", "1.2"))994 package_b20.add_dependency(Factory.create_dependency("C", "1.5"))995 package_c12 = get_package("C", "1.2")996 package_c15 = get_package("C", "1.5")997 repo.add_package(package_a)998 repo.add_package(package_b10)999 repo.add_package(package_b20)1000 repo.add_package(package_c12)1001 repo.add_package(package_c15)1002 transaction = solver.solve()1003 check_solver_result(1004 transaction,1005 [1006 {"job": "install", "package": package_c12},1007 {"job": "install", "package": package_c15},1008 {"job": "install", "package": package_b10},1009 {"job": "install", "package": package_b20},1010 {"job": "install", "package": package_a},1011 ],1012 )1013def test_solver_fails_if_dependency_name_does_not_match_package(1014 solver: Solver, repo: Repository, package: ProjectPackage1015):1016 package.add_dependency(1017 Factory.create_dependency(1018 "my-demo", {"git": "https://github.com/demo/demo.git"}1019 )1020 )1021 with pytest.raises(RuntimeError):1022 solver.solve()1023def test_solver_does_not_get_stuck_in_recursion_on_circular_dependency(1024 solver: Solver, repo: Repository, package: Package1025):1026 package_a = get_package("A", "1.0")1027 package_a.add_dependency(Factory.create_dependency("B", "^1.0"))1028 package_b = get_package("B", "1.0")1029 package_b.add_dependency(Factory.create_dependency("C", "^1.0"))1030 package_c = get_package("C", "1.0")1031 package_c.add_dependency(Factory.create_dependency("B", "^1.0"))1032 repo.add_package(package_a)1033 repo.add_package(package_b)1034 repo.add_package(package_c)1035 package.add_dependency(Factory.create_dependency("A", "^1.0"))1036 transaction = solver.solve()1037 check_solver_result(1038 transaction,1039 [1040 {"job": "install", "package": package_c},1041 {"job": "install", "package": package_b},1042 {"job": "install", "package": package_a},1043 ],1044 )1045def test_solver_can_resolve_git_dependencies(1046 solver: Solver, repo: Repository, package: ProjectPackage1047):1048 pendulum = get_package("pendulum", "2.0.3")1049 cleo = get_package("cleo", "1.0.0")1050 repo.add_package(pendulum)1051 repo.add_package(cleo)1052 package.add_dependency(1053 Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.git"})1054 )1055 transaction = solver.solve()1056 demo = Package(1057 "demo",1058 "0.1.2",1059 source_type="git",1060 source_url="https://github.com/demo/demo.git",1061 source_reference=DEFAULT_SOURCE_REF,1062 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1063 )1064 ops = check_solver_result(1065 transaction,1066 [{"job": "install", "package": pendulum}, {"job": "install", "package": demo}],1067 )1068 op = ops[1]1069 assert op.package.source_type == "git"1070 assert op.package.source_reference == DEFAULT_SOURCE_REF1071 assert op.package.source_resolved_reference.startswith("9cf87a2")1072def test_solver_can_resolve_git_dependencies_with_extras(1073 solver: Solver, repo: Repository, package: ProjectPackage1074):1075 pendulum = get_package("pendulum", "2.0.3")1076 cleo = get_package("cleo", "1.0.0")1077 repo.add_package(pendulum)1078 repo.add_package(cleo)1079 package.add_dependency(1080 Factory.create_dependency(1081 "demo", {"git": "https://github.com/demo/demo.git", "extras": ["foo"]}1082 )1083 )1084 transaction = solver.solve()1085 demo = Package(1086 "demo",1087 "0.1.2",1088 source_type="git",1089 source_url="https://github.com/demo/demo.git",1090 source_reference=DEFAULT_SOURCE_REF,1091 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1092 )1093 check_solver_result(1094 transaction,1095 [1096 {"job": "install", "package": cleo},1097 {"job": "install", "package": pendulum},1098 {"job": "install", "package": demo},1099 ],1100 )1101@pytest.mark.parametrize(1102 "ref",1103 [{"branch": "a-branch"}, {"tag": "a-tag"}, {"rev": "9cf8"}],1104 ids=["branch", "tag", "rev"],1105)1106def test_solver_can_resolve_git_dependencies_with_ref(1107 solver: Solver, repo: Repository, package: Package, ref: dict[str, str]1108):1109 pendulum = get_package("pendulum", "2.0.3")1110 cleo = get_package("cleo", "1.0.0")1111 repo.add_package(pendulum)1112 repo.add_package(cleo)1113 demo = Package(1114 "demo",1115 "0.1.2",1116 source_type="git",1117 source_url="https://github.com/demo/demo.git",1118 source_reference=ref[list(ref.keys())[0]],1119 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1120 )1121 git_config = {demo.source_type: demo.source_url}1122 git_config.update(ref)1123 package.add_dependency(Factory.create_dependency("demo", git_config))1124 transaction = solver.solve()1125 ops = check_solver_result(1126 transaction,1127 [{"job": "install", "package": pendulum}, {"job": "install", "package": demo}],1128 )1129 op = ops[1]1130 assert op.package.source_type == "git"1131 assert op.package.source_reference == ref[list(ref.keys())[0]]1132 assert op.package.source_resolved_reference.startswith("9cf87a2")1133def test_solver_does_not_trigger_conflict_for_python_constraint_if_python_requirement_is_compatible( # noqa: E5011134 solver: Solver, repo: Repository, package: Package1135):1136 solver.provider.set_package_python_versions("~2.7 || ^3.4")1137 package.add_dependency(1138 Factory.create_dependency("A", {"version": "^1.0", "python": "^3.6"})1139 )1140 package_a = get_package("A", "1.0.0")1141 package_a.python_versions = ">=3.6"1142 repo.add_package(package_a)1143 transaction = solver.solve()1144 check_solver_result(transaction, [{"job": "install", "package": package_a}])1145def test_solver_does_not_trigger_conflict_for_python_constraint_if_python_requirement_is_compatible_multiple( # noqa: E5011146 solver: Solver, repo: Repository, package: Package1147):1148 solver.provider.set_package_python_versions("~2.7 || ^3.4")1149 package.add_dependency(1150 Factory.create_dependency("A", {"version": "^1.0", "python": "^3.6"})1151 )1152 package.add_dependency(1153 Factory.create_dependency("B", {"version": "^1.0", "python": "^3.5.3"})1154 )1155 package_a = get_package("A", "1.0.0")1156 package_a.python_versions = ">=3.6"1157 package_a.add_dependency(Factory.create_dependency("B", "^1.0"))1158 package_b = get_package("B", "1.0.0")1159 package_b.python_versions = ">=3.5.3"1160 repo.add_package(package_a)1161 repo.add_package(package_b)1162 transaction = solver.solve()1163 check_solver_result(1164 transaction,1165 [1166 {"job": "install", "package": package_b},1167 {"job": "install", "package": package_a},1168 ],1169 )1170def test_solver_triggers_conflict_for_dependency_python_not_fully_compatible_with_package_python( # noqa: E5011171 solver: Solver, repo: Repository, package: Package1172):1173 solver.provider.set_package_python_versions("~2.7 || ^3.4")1174 package.add_dependency(1175 Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"})1176 )1177 package_a = get_package("A", "1.0.0")1178 package_a.python_versions = ">=3.6"1179 repo.add_package(package_a)1180 with pytest.raises(SolverProblemError):1181 solver.solve()1182def test_solver_finds_compatible_package_for_dependency_python_not_fully_compatible_with_package_python( # noqa: E5011183 solver: Solver, repo: Repository, package: Package1184):1185 solver.provider.set_package_python_versions("~2.7 || ^3.4")1186 package.add_dependency(1187 Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"})1188 )1189 package_a101 = get_package("A", "1.0.1")1190 package_a101.python_versions = ">=3.6"1191 package_a100 = get_package("A", "1.0.0")1192 package_a100.python_versions = ">=3.5"1193 repo.add_package(package_a100)1194 repo.add_package(package_a101)1195 transaction = solver.solve()1196 check_solver_result(transaction, [{"job": "install", "package": package_a100}])1197def test_solver_does_not_trigger_new_resolution_on_duplicate_dependencies_if_only_extras( # noqa: E5011198 solver: Solver, repo: Repository, package: Package1199):1200 dep1 = Dependency.create_from_pep_508('B (>=1.0); extra == "foo"')1201 dep1.activate()1202 dep2 = Dependency.create_from_pep_508('B (>=2.0); extra == "bar"')1203 dep2.activate()1204 package.add_dependency(1205 Factory.create_dependency("A", {"version": "^1.0", "extras": ["foo", "bar"]})1206 )1207 package_a = get_package("A", "1.0.0")1208 package_a.extras = {"foo": [dep1], "bar": [dep2]}1209 package_a.add_dependency(dep1)1210 package_a.add_dependency(dep2)1211 package_b2 = get_package("B", "2.0.0")1212 package_b1 = get_package("B", "1.0.0")1213 repo.add_package(package_a)1214 repo.add_package(package_b1)1215 repo.add_package(package_b2)1216 transaction = solver.solve()1217 ops = check_solver_result(1218 transaction,1219 [1220 {"job": "install", "package": package_b2},1221 {"job": "install", "package": package_a},1222 ],1223 )1224 assert str(ops[0].package.marker) == ""1225 assert str(ops[1].package.marker) == ""1226def test_solver_does_not_raise_conflict_for_locked_conditional_dependencies(1227 solver: Solver, repo: Repository, package: Package1228):1229 solver.provider.set_package_python_versions("~2.7 || ^3.4")1230 package.add_dependency(1231 Factory.create_dependency("A", {"version": "^1.0", "python": "^3.6"})1232 )1233 package.add_dependency(Factory.create_dependency("B", "^1.0"))1234 package_a = get_package("A", "1.0.0")1235 package_a.python_versions = ">=3.6"1236 package_a.marker = parse_marker(1237 'python_version >= "3.6" and python_version < "4.0"'1238 )1239 package_b = get_package("B", "1.0.0")1240 repo.add_package(package_a)1241 repo.add_package(package_b)1242 solver._locked = Repository([package_a])1243 transaction = solver.solve(use_latest=[package_b.name])1244 check_solver_result(1245 transaction,1246 [1247 {"job": "install", "package": package_a},1248 {"job": "install", "package": package_b},1249 ],1250 )1251def test_solver_returns_extras_if_requested_in_dependencies_and_not_in_root_package(1252 solver: Solver, repo: Repository, package: Package1253):1254 package.add_dependency(Factory.create_dependency("A", "*"))1255 package.add_dependency(Factory.create_dependency("B", "*"))1256 package.add_dependency(Factory.create_dependency("C", "*"))1257 package_a = get_package("A", "1.0")1258 package_b = get_package("B", "1.0")1259 package_c = get_package("C", "1.0")1260 package_d = get_package("D", "1.0")1261 package_b.add_dependency(1262 Factory.create_dependency("C", {"version": "^1.0", "extras": ["foo"]})1263 )1264 package_c.add_dependency(1265 Factory.create_dependency("D", {"version": "^1.0", "optional": True})1266 )1267 package_c.extras = {"foo": [Factory.create_dependency("D", "^1.0")]}1268 repo.add_package(package_a)1269 repo.add_package(package_b)1270 repo.add_package(package_c)1271 repo.add_package(package_d)1272 transaction = solver.solve()1273 check_solver_result(1274 transaction,1275 [1276 {"job": "install", "package": package_d},1277 {"job": "install", "package": package_c},1278 {"job": "install", "package": package_a},1279 {"job": "install", "package": package_b},1280 ],1281 )1282def test_solver_should_not_resolve_prerelease_version_if_not_requested(1283 solver: Solver, repo: Repository, package: Package1284):1285 package.add_dependency(Factory.create_dependency("A", "~1.8.0"))1286 package.add_dependency(Factory.create_dependency("B", "^0.5.0"))1287 package_a185 = get_package("A", "1.8.5")1288 package_a19b1 = get_package("A", "1.9b1")1289 package_b = get_package("B", "0.5.0")1290 package_b.add_dependency(Factory.create_dependency("A", ">=1.9b1"))1291 repo.add_package(package_a185)1292 repo.add_package(package_a19b1)1293 repo.add_package(package_b)1294 with pytest.raises(SolverProblemError):1295 solver.solve()1296def test_solver_ignores_dependencies_with_incompatible_python_full_version_marker(1297 solver: Solver, repo: Repository, package: Package1298):1299 solver.provider.set_package_python_versions("^3.6")1300 package.add_dependency(Factory.create_dependency("A", "^1.0"))1301 package.add_dependency(Factory.create_dependency("B", "^2.0"))1302 package_a = get_package("A", "1.0.0")1303 package_a.add_dependency(1304 Dependency.create_from_pep_508(1305 'B (<2.0); platform_python_implementation == "PyPy" and python_full_version'1306 ' < "2.7.9"'1307 )1308 )1309 package_b200 = get_package("B", "2.0.0")1310 package_b100 = get_package("B", "1.0.0")1311 repo.add_package(package_a)1312 repo.add_package(package_b100)1313 repo.add_package(package_b200)1314 transaction = solver.solve()1315 check_solver_result(1316 transaction,1317 [1318 {"job": "install", "package": package_a},1319 {"job": "install", "package": package_b200},1320 ],1321 )1322def test_solver_git_dependencies_update(1323 solver: Solver, repo: Repository, package: Package, installed: InstalledRepository1324):1325 pendulum = get_package("pendulum", "2.0.3")1326 cleo = get_package("cleo", "1.0.0")1327 repo.add_package(pendulum)1328 repo.add_package(cleo)1329 demo_installed = Package(1330 "demo",1331 "0.1.2",1332 source_type="git",1333 source_url="https://github.com/demo/demo.git",1334 source_reference=DEFAULT_SOURCE_REF,1335 source_resolved_reference="123456",1336 )1337 demo = Package(1338 "demo",1339 "0.1.2",1340 source_type="git",1341 source_url="https://github.com/demo/demo.git",1342 source_reference=DEFAULT_SOURCE_REF,1343 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1344 )1345 installed.add_package(demo_installed)1346 package.add_dependency(1347 Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.git"})1348 )1349 transaction = solver.solve()1350 ops = check_solver_result(1351 transaction,1352 [1353 {"job": "install", "package": pendulum},1354 {"job": "update", "from": demo_installed, "to": demo},1355 ],1356 )1357 op = ops[1]1358 assert op.job_type == "update"1359 assert op.package.source_type == "git"1360 assert op.package.source_reference == DEFAULT_SOURCE_REF1361 assert op.package.source_resolved_reference.startswith("9cf87a2")1362 assert op.initial_package.source_resolved_reference == "123456"1363def test_solver_git_dependencies_update_skipped(1364 solver: Solver, repo: Repository, package: Package, installed: InstalledRepository1365):1366 pendulum = get_package("pendulum", "2.0.3")1367 cleo = get_package("cleo", "1.0.0")1368 repo.add_package(pendulum)1369 repo.add_package(cleo)1370 demo = Package(1371 "demo",1372 "0.1.2",1373 source_type="git",1374 source_url="https://github.com/demo/demo.git",1375 source_reference="master",1376 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1377 )1378 installed.add_package(demo)1379 package.add_dependency(1380 Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.git"})1381 )1382 transaction = solver.solve()1383 check_solver_result(1384 transaction,1385 [1386 {"job": "install", "package": pendulum},1387 {"job": "install", "package": demo, "skipped": True},1388 ],1389 )1390def test_solver_git_dependencies_short_hash_update_skipped(1391 solver: Solver, repo: Repository, package: Package, installed: InstalledRepository1392):1393 pendulum = get_package("pendulum", "2.0.3")1394 cleo = get_package("cleo", "1.0.0")1395 repo.add_package(pendulum)1396 repo.add_package(cleo)1397 demo = Package(1398 "demo",1399 "0.1.2",1400 source_type="git",1401 source_url="https://github.com/demo/demo.git",1402 source_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1403 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1404 )1405 installed.add_package(demo)1406 package.add_dependency(1407 Factory.create_dependency(1408 "demo", {"git": "https://github.com/demo/demo.git", "rev": "9cf87a2"}1409 )1410 )1411 transaction = solver.solve()1412 check_solver_result(1413 transaction,1414 [1415 {"job": "install", "package": pendulum},1416 {1417 "job": "install",1418 "package": Package(1419 "demo",1420 "0.1.2",1421 source_type="git",1422 source_url="https://github.com/demo/demo.git",1423 source_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",1424 source_resolved_reference=(1425 "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24"1426 ),1427 ),1428 "skipped": True,1429 },1430 ],1431 )1432def test_solver_can_resolve_directory_dependencies(1433 solver: Solver, repo: Repository, package: ProjectPackage1434):1435 pendulum = get_package("pendulum", "2.0.3")1436 repo.add_package(pendulum)1437 path = (1438 Path(__file__).parent.parent1439 / "fixtures"1440 / "git"1441 / "github.com"1442 / "demo"1443 / "demo"1444 ).as_posix()1445 package.add_dependency(Factory.create_dependency("demo", {"path": path}))1446 transaction = solver.solve()1447 demo = Package("demo", "0.1.2", source_type="directory", source_url=path)1448 ops = check_solver_result(1449 transaction,1450 [{"job": "install", "package": pendulum}, {"job": "install", "package": demo}],1451 )1452 op = ops[1]1453 assert op.package.name == "demo"1454 assert op.package.version.text == "0.1.2"1455 assert op.package.source_type == "directory"1456 assert op.package.source_url == path1457def test_solver_can_resolve_directory_dependencies_nested_editable(1458 repo: Repository,1459 pool: Pool,1460 installed: InstalledRepository,1461 locked: Repository,1462 io: NullIO,1463):1464 base = Path(__file__).parent.parent / "fixtures" / "project_with_nested_local"1465 poetry = Factory().create_poetry(cwd=base)1466 package = poetry.package1467 solver = Solver(1468 package, pool, installed, locked, io, provider=Provider(package, pool, io)1469 )1470 transaction = solver.solve()1471 ops = check_solver_result(1472 transaction,1473 [1474 {1475 "job": "install",1476 "package": Package(1477 "quix",1478 "1.2.3",1479 source_type="directory",1480 source_url=(base / "quix").as_posix(),1481 ),1482 "skipped": False,1483 },1484 {1485 "job": "install",1486 "package": Package(1487 "bar",1488 "1.2.3",1489 source_type="directory",1490 source_url=(base / "bar").as_posix(),1491 ),1492 "skipped": False,1493 },1494 {1495 "job": "install",1496 "package": Package(1497 "foo",1498 "1.2.3",1499 source_type="directory",1500 source_url=(base / "foo").as_posix(),1501 ),1502 "skipped": False,1503 },1504 ],1505 )1506 for op in ops:1507 assert op.package.source_type == "directory"1508 assert op.package.develop is True1509def test_solver_can_resolve_directory_dependencies_with_extras(1510 solver: Solver, repo: Repository, package: ProjectPackage1511):1512 pendulum = get_package("pendulum", "2.0.3")1513 cleo = get_package("cleo", "1.0.0")1514 repo.add_package(pendulum)1515 repo.add_package(cleo)1516 path = (1517 Path(__file__).parent.parent1518 / "fixtures"1519 / "git"1520 / "github.com"1521 / "demo"1522 / "demo"1523 ).as_posix()1524 package.add_dependency(1525 Factory.create_dependency("demo", {"path": path, "extras": ["foo"]})1526 )1527 transaction = solver.solve()1528 demo = Package("demo", "0.1.2", source_type="directory", source_url=path)1529 ops = check_solver_result(1530 transaction,1531 [1532 {"job": "install", "package": cleo},1533 {"job": "install", "package": pendulum},1534 {"job": "install", "package": demo},1535 ],1536 )1537 op = ops[2]1538 assert op.package.name == "demo"1539 assert op.package.version.text == "0.1.2"1540 assert op.package.source_type == "directory"1541 assert op.package.source_url == path1542def test_solver_can_resolve_sdist_dependencies(1543 solver: Solver, repo: Repository, package: ProjectPackage1544):1545 pendulum = get_package("pendulum", "2.0.3")1546 repo.add_package(pendulum)1547 path = (1548 Path(__file__).parent.parent1549 / "fixtures"1550 / "distributions"1551 / "demo-0.1.0.tar.gz"1552 ).as_posix()1553 package.add_dependency(Factory.create_dependency("demo", {"path": path}))1554 transaction = solver.solve()1555 demo = Package("demo", "0.1.0", source_type="file", source_url=path)1556 ops = check_solver_result(1557 transaction,1558 [{"job": "install", "package": pendulum}, {"job": "install", "package": demo}],1559 )1560 op = ops[1]1561 assert op.package.name == "demo"1562 assert op.package.version.text == "0.1.0"1563 assert op.package.source_type == "file"1564 assert op.package.source_url == path1565def test_solver_can_resolve_sdist_dependencies_with_extras(1566 solver: Solver, repo: Repository, package: ProjectPackage1567):1568 pendulum = get_package("pendulum", "2.0.3")1569 cleo = get_package("cleo", "1.0.0")1570 repo.add_package(pendulum)1571 repo.add_package(cleo)1572 path = (1573 Path(__file__).parent.parent1574 / "fixtures"1575 / "distributions"1576 / "demo-0.1.0.tar.gz"1577 ).as_posix()1578 package.add_dependency(1579 Factory.create_dependency("demo", {"path": path, "extras": ["foo"]})1580 )1581 transaction = solver.solve()1582 demo = Package("demo", "0.1.0", source_type="file", source_url=path)1583 ops = check_solver_result(1584 transaction,1585 [1586 {"job": "install", "package": cleo},1587 {"job": "install", "package": pendulum},1588 {"job": "install", "package": demo},1589 ],1590 )1591 op = ops[2]1592 assert op.package.name == "demo"1593 assert op.package.version.text == "0.1.0"1594 assert op.package.source_type == "file"1595 assert op.package.source_url == path1596def test_solver_can_resolve_wheel_dependencies(1597 solver: Solver, repo: Repository, package: ProjectPackage1598):1599 pendulum = get_package("pendulum", "2.0.3")1600 repo.add_package(pendulum)1601 path = (1602 Path(__file__).parent.parent1603 / "fixtures"1604 / "distributions"1605 / "demo-0.1.0-py2.py3-none-any.whl"1606 ).as_posix()1607 package.add_dependency(Factory.create_dependency("demo", {"path": path}))1608 transaction = solver.solve()1609 demo = Package("demo", "0.1.0", source_type="file", source_url=path)1610 ops = check_solver_result(1611 transaction,1612 [{"job": "install", "package": pendulum}, {"job": "install", "package": demo}],1613 )1614 op = ops[1]1615 assert op.package.name == "demo"1616 assert op.package.version.text == "0.1.0"1617 assert op.package.source_type == "file"1618 assert op.package.source_url == path1619def test_solver_can_resolve_wheel_dependencies_with_extras(1620 solver: Solver, repo: Repository, package: ProjectPackage1621):1622 pendulum = get_package("pendulum", "2.0.3")1623 cleo = get_package("cleo", "1.0.0")1624 repo.add_package(pendulum)1625 repo.add_package(cleo)1626 path = (1627 Path(__file__).parent.parent1628 / "fixtures"1629 / "distributions"1630 / "demo-0.1.0-py2.py3-none-any.whl"1631 ).as_posix()1632 package.add_dependency(1633 Factory.create_dependency("demo", {"path": path, "extras": ["foo"]})1634 )1635 transaction = solver.solve()1636 demo = Package("demo", "0.1.0", source_type="file", source_url=path)1637 ops = check_solver_result(1638 transaction,1639 [1640 {"job": "install", "package": cleo},1641 {"job": "install", "package": pendulum},1642 {"job": "install", "package": demo},1643 ],1644 )1645 op = ops[2]1646 assert op.package.name == "demo"1647 assert op.package.version.text == "0.1.0"1648 assert op.package.source_type == "file"1649 assert op.package.source_url == path1650def test_solver_can_solve_with_legacy_repository_using_proper_dists(1651 package: ProjectPackage,1652 installed: InstalledRepository,1653 locked: Repository,1654 io: NullIO,1655):1656 repo = MockLegacyRepository()1657 pool = Pool([repo])1658 solver = Solver(package, pool, installed, locked, io)1659 package.add_dependency(Factory.create_dependency("isort", "4.3.4"))1660 transaction = solver.solve()1661 ops = check_solver_result(1662 transaction,1663 [1664 {1665 "job": "install",1666 "package": Package(1667 "futures",1668 "3.2.0",1669 source_type="legacy",1670 source_url=repo.url,1671 source_reference=repo.name,1672 ),1673 },1674 {1675 "job": "install",1676 "package": Package(1677 "isort",1678 "4.3.4",1679 source_type="legacy",1680 source_url=repo.url,1681 source_reference=repo.name,1682 ),1683 },1684 ],1685 )1686 futures = ops[0].package1687 assert futures.python_versions == ">=2.6, <3"1688def test_solver_can_solve_with_legacy_repository_using_proper_python_compatible_dists(1689 package: ProjectPackage,1690 installed: InstalledRepository,1691 locked: Repository,1692 io: NullIO,1693):1694 package.python_versions = "^3.7"1695 repo = MockLegacyRepository()1696 pool = Pool([repo])1697 solver = Solver(package, pool, installed, locked, io)1698 package.add_dependency(Factory.create_dependency("isort", "4.3.4"))1699 transaction = solver.solve()1700 check_solver_result(1701 transaction,1702 [1703 {1704 "job": "install",1705 "package": Package(1706 "isort",1707 "4.3.4",1708 source_type="legacy",1709 source_url=repo.url,1710 source_reference=repo.name,1711 ),1712 }1713 ],1714 )1715def test_solver_skips_invalid_versions(1716 package: ProjectPackage,1717 installed: InstalledRepository,1718 locked: Repository,1719 io: NullIO,1720):1721 package.python_versions = "^3.7"1722 repo = MockPyPIRepository()1723 pool = Pool([repo])1724 solver = Solver(package, pool, installed, locked, io)1725 package.add_dependency(Factory.create_dependency("trackpy", "^0.4"))1726 transaction = solver.solve()1727 check_solver_result(1728 transaction, [{"job": "install", "package": get_package("trackpy", "0.4.1")}]1729 )1730def test_multiple_constraints_on_root(1731 package: ProjectPackage, solver: Solver, repo: Repository1732):1733 package.add_dependency(1734 Factory.create_dependency("foo", {"version": "^1.0", "python": "^2.7"})1735 )1736 package.add_dependency(1737 Factory.create_dependency("foo", {"version": "^2.0", "python": "^3.7"})1738 )1739 foo15 = get_package("foo", "1.5.0")1740 foo25 = get_package("foo", "2.5.0")1741 repo.add_package(foo15)1742 repo.add_package(foo25)1743 transaction = solver.solve()1744 check_solver_result(1745 transaction,1746 [{"job": "install", "package": foo15}, {"job": "install", "package": foo25}],1747 )1748def test_solver_chooses_most_recent_version_amongst_repositories(1749 package: ProjectPackage,1750 installed: InstalledRepository,1751 locked: Repository,1752 io: NullIO,1753):1754 package.python_versions = "^3.7"1755 package.add_dependency(Factory.create_dependency("tomlkit", {"version": "^0.5"}))1756 repo = MockLegacyRepository()1757 pool = Pool([repo, MockPyPIRepository()])1758 solver = Solver(package, pool, installed, locked, io)1759 transaction = solver.solve()1760 ops = check_solver_result(1761 transaction, [{"job": "install", "package": get_package("tomlkit", "0.5.3")}]1762 )1763 assert ops[0].package.source_type is None1764 assert ops[0].package.source_url is None1765def test_solver_chooses_from_correct_repository_if_forced(1766 package: ProjectPackage,1767 installed: InstalledRepository,1768 locked: Repository,1769 io: NullIO,1770):1771 package.python_versions = "^3.7"1772 package.add_dependency(1773 Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "legacy"})1774 )1775 repo = MockLegacyRepository()1776 pool = Pool([repo, MockPyPIRepository()])1777 solver = Solver(package, pool, installed, locked, io)1778 transaction = solver.solve()1779 ops = check_solver_result(1780 transaction,1781 [1782 {1783 "job": "install",1784 "package": Package(1785 "tomlkit",1786 "0.5.2",1787 source_type="legacy",1788 source_url=repo.url,1789 source_reference=repo.name,1790 ),1791 }1792 ],1793 )1794 assert ops[0].package.source_url == "http://legacy.foo.bar"1795def test_solver_chooses_from_correct_repository_if_forced_and_transitive_dependency(1796 package: ProjectPackage,1797 installed: InstalledRepository,1798 locked: Repository,1799 io: NullIO,1800):1801 package.python_versions = "^3.7"1802 package.add_dependency(Factory.create_dependency("foo", "^1.0"))1803 package.add_dependency(1804 Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "legacy"})1805 )1806 repo = Repository()1807 foo = get_package("foo", "1.0.0")1808 foo.add_dependency(Factory.create_dependency("tomlkit", "^0.5.0"))1809 repo.add_package(foo)1810 pool = Pool([MockLegacyRepository(), repo, MockPyPIRepository()])1811 solver = Solver(package, pool, installed, locked, io)1812 transaction = solver.solve()1813 ops = check_solver_result(1814 transaction,1815 [1816 {1817 "job": "install",1818 "package": Package(1819 "tomlkit",1820 "0.5.2",1821 source_type="legacy",1822 source_url="http://legacy.foo.bar",1823 source_reference="legacy",1824 ),1825 },1826 {"job": "install", "package": foo},1827 ],1828 )1829 assert ops[0].package.source_url == "http://legacy.foo.bar"1830 assert ops[1].package.source_type is None1831 assert ops[1].package.source_url is None1832def test_solver_does_not_choose_from_secondary_repository_by_default(1833 package: ProjectPackage,1834 installed: InstalledRepository,1835 locked: Repository,1836 io: NullIO,1837):1838 package.python_versions = "^3.7"1839 package.add_dependency(Factory.create_dependency("clikit", {"version": "^0.2.0"}))1840 pool = Pool()1841 pool.add_repository(MockPyPIRepository(), secondary=True)1842 pool.add_repository(MockLegacyRepository())1843 solver = Solver(package, pool, installed, locked, io)1844 transaction = solver.solve()1845 ops = check_solver_result(1846 transaction,1847 [1848 {1849 "job": "install",1850 "package": Package(1851 "pastel",1852 "0.1.0",1853 source_type="legacy",1854 source_url="http://legacy.foo.bar",1855 source_reference="legacy",1856 ),1857 },1858 {"job": "install", "package": get_package("pylev", "1.3.0")},1859 {1860 "job": "install",1861 "package": Package(1862 "clikit",1863 "0.2.4",1864 source_type="legacy",1865 source_url="http://legacy.foo.bar",1866 source_reference="legacy",1867 ),1868 },1869 ],1870 )1871 assert ops[0].package.source_url == "http://legacy.foo.bar"1872 assert ops[1].package.source_type is None1873 assert ops[1].package.source_url is None1874 assert ops[2].package.source_url == "http://legacy.foo.bar"1875def test_solver_chooses_from_secondary_if_explicit(1876 package: ProjectPackage,1877 installed: InstalledRepository,1878 locked: Repository,1879 io: NullIO,1880):1881 package.python_versions = "^3.7"1882 package.add_dependency(1883 Factory.create_dependency("clikit", {"version": "^0.2.0", "source": "PyPI"})1884 )1885 pool = Pool()1886 pool.add_repository(MockPyPIRepository(), secondary=True)1887 pool.add_repository(MockLegacyRepository())1888 solver = Solver(package, pool, installed, locked, io)1889 transaction = solver.solve()1890 ops = check_solver_result(1891 transaction,1892 [1893 {1894 "job": "install",1895 "package": Package(1896 "pastel",1897 "0.1.0",1898 source_type="legacy",1899 source_url="http://legacy.foo.bar",1900 source_reference="legacy",1901 ),1902 },1903 {"job": "install", "package": get_package("pylev", "1.3.0")},1904 {"job": "install", "package": get_package("clikit", "0.2.4")},1905 ],1906 )1907 assert ops[0].package.source_url == "http://legacy.foo.bar"1908 assert ops[1].package.source_type is None1909 assert ops[1].package.source_url is None1910 assert ops[2].package.source_type is None1911 assert ops[2].package.source_url is None1912def test_solver_discards_packages_with_empty_markers(1913 package: ProjectPackage,1914 installed: InstalledRepository,1915 locked: Repository,1916 io: NullIO,1917 pool: Pool,1918 repo: Repository,1919):1920 package.python_versions = "~2.7 || ^3.4"1921 package.add_dependency(1922 Factory.create_dependency(1923 "a", {"version": "^0.1.0", "markers": "python_version >= '3.4'"}1924 )1925 )1926 package_a = get_package("a", "0.1.0")1927 package_a.add_dependency(1928 Factory.create_dependency(1929 "b", {"version": "^0.1.0", "markers": "python_version < '3.2'"}1930 )1931 )1932 package_a.add_dependency(Factory.create_dependency("c", "^0.2.0"))1933 package_b = get_package("b", "0.1.0")1934 package_c = get_package("c", "0.2.0")1935 repo.add_package(package_a)1936 repo.add_package(package_b)1937 repo.add_package(package_c)1938 solver = Solver(package, pool, installed, locked, io)1939 transaction = solver.solve()1940 check_solver_result(1941 transaction,1942 [1943 {"job": "install", "package": package_c},1944 {"job": "install", "package": package_a},1945 ],1946 )1947def test_solver_does_not_raise_conflict_for_conditional_dev_dependencies(1948 solver: Solver, repo: Repository, package: Package1949):1950 solver.provider.set_package_python_versions("~2.7 || ^3.5")1951 package.add_dependency(1952 Factory.create_dependency(1953 "A", {"version": "^1.0", "python": "~2.7"}, groups=["dev"]1954 )1955 )1956 package.add_dependency(1957 Factory.create_dependency(1958 "A", {"version": "^2.0", "python": "^3.5"}, groups=["dev"]1959 )1960 )1961 package_a100 = get_package("A", "1.0.0")1962 package_a200 = get_package("A", "2.0.0")1963 repo.add_package(package_a100)1964 repo.add_package(package_a200)1965 transaction = solver.solve()1966 check_solver_result(1967 transaction,1968 [1969 {"job": "install", "package": package_a100},1970 {"job": "install", "package": package_a200},1971 ],1972 )1973def test_solver_does_not_loop_indefinitely_on_duplicate_constraints_with_extras(1974 solver: Solver, repo: Repository, package: Package1975):1976 solver.provider.set_package_python_versions("~2.7 || ^3.5")1977 package.add_dependency(1978 Factory.create_dependency(1979 "requests", {"version": "^2.22.0", "extras": ["security"]}1980 )1981 )1982 requests = get_package("requests", "2.22.0")1983 requests.add_dependency(Factory.create_dependency("idna", ">=2.5,<2.9"))1984 requests.add_dependency(1985 Factory.create_dependency(1986 "idna", {"version": ">=2.0.0", "markers": "extra == 'security'"}1987 )1988 )1989 requests.extras["security"] = [get_dependency("idna", ">=2.0.0")]1990 idna = get_package("idna", "2.8")1991 repo.add_package(requests)1992 repo.add_package(idna)1993 transaction = solver.solve()1994 check_solver_result(1995 transaction,1996 [{"job": "install", "package": idna}, {"job": "install", "package": requests}],1997 )1998def test_solver_does_not_fail_with_locked_git_and_non_git_dependencies(1999 repo: Repository,2000 package: Package,2001 locked: Repository,2002 pool: Pool,2003 installed: InstalledRepository,2004 io: NullIO,2005):2006 package.add_dependency(2007 Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.git"})2008 )2009 package.add_dependency(Factory.create_dependency("a", "^1.2.3"))2010 git_package = Package(2011 "demo",2012 "0.1.2",2013 source_type="git",2014 source_url="https://github.com/demo/demo.git",2015 source_reference=DEFAULT_SOURCE_REF,2016 source_resolved_reference="9cf87a285a2d3fbb0b9fa621997b3acc3631ed24",2017 )2018 installed.add_package(git_package)2019 locked.add_package(get_package("a", "1.2.3"))2020 locked.add_package(git_package)2021 repo.add_package(get_package("a", "1.2.3"))2022 repo.add_package(Package("pendulum", "2.1.2"))2023 solver = Solver(package, pool, installed, locked, io)2024 transaction = solver.solve()2025 check_solver_result(2026 transaction,2027 [2028 {"job": "install", "package": get_package("a", "1.2.3")},2029 {"job": "install", "package": git_package, "skipped": True},2030 ],2031 )2032def test_ignore_python_constraint_no_overlap_dependencies(2033 solver: Solver, repo: Repository, package: ProjectPackage2034):2035 pytest = get_package("demo", "1.0.0")2036 pytest.add_dependency(2037 Factory.create_dependency(2038 "configparser", {"version": "^1.2.3", "python": "<3.2"}2039 )2040 )2041 package.add_dependency(2042 Factory.create_dependency("demo", {"version": "^1.0.0", "python": "^3.6"})2043 )2044 repo.add_package(pytest)2045 repo.add_package(get_package("configparser", "1.2.3"))2046 transaction = solver.solve()2047 check_solver_result(2048 transaction,2049 [{"job": "install", "package": pytest}],2050 )2051def test_solver_should_not_go_into_an_infinite_loop_on_duplicate_dependencies(2052 solver: Solver, repo: Repository, package: Package2053):2054 solver.provider.set_package_python_versions("~2.7 || ^3.5")2055 package.add_dependency(Factory.create_dependency("A", "^1.0"))2056 package_a = get_package("A", "1.0.0")2057 package_a.add_dependency(Factory.create_dependency("B", "*"))2058 package_a.add_dependency(2059 Factory.create_dependency(2060 "B", {"version": "^1.0", "markers": "implementation_name == 'pypy'"}2061 )2062 )2063 package_b20 = get_package("B", "2.0.0")2064 package_b10 = get_package("B", "1.0.0")2065 repo.add_package(package_a)2066 repo.add_package(package_b10)2067 repo.add_package(package_b20)2068 transaction = solver.solve()2069 check_solver_result(2070 transaction,2071 [2072 {"job": "install", "package": package_b10},2073 {"job": "install", "package": package_b20},2074 {"job": "install", "package": package_a},2075 ],2076 )2077def test_solver_synchronize_single(2078 package: ProjectPackage,2079 pool: Pool,2080 installed: InstalledRepository,2081 locked: Repository,2082 io: NullIO,2083):2084 solver = Solver(package, pool, installed, locked, io)2085 package_a = get_package("a", "1.0")2086 installed.add_package(package_a)2087 transaction = solver.solve()2088 check_solver_result(2089 transaction, [{"job": "remove", "package": package_a}], synchronize=True2090 )2091@pytest.mark.skip(reason="Poetry no longer has critical package requirements")2092def test_solver_with_synchronization_keeps_critical_package(2093 package: ProjectPackage,2094 pool: Pool,2095 installed: InstalledRepository,2096 locked: Repository,2097 io: NullIO,2098):2099 solver = Solver(package, pool, installed, locked, io)2100 package_pip = get_package("setuptools", "1.0")2101 installed.add_package(package_pip)2102 transaction = solver.solve()2103 check_solver_result(transaction, [])2104def test_solver_cannot_choose_another_version_for_directory_dependencies(2105 solver: Solver, repo: Repository, package: Package2106):2107 pendulum = get_package("pendulum", "2.0.3")2108 demo = get_package("demo", "0.1.0")2109 foo = get_package("foo", "1.2.3")2110 foo.add_dependency(Factory.create_dependency("demo", "<0.1.2"))2111 repo.add_package(foo)2112 repo.add_package(demo)2113 repo.add_package(pendulum)2114 path = (2115 Path(__file__).parent.parent2116 / "fixtures"2117 / "git"2118 / "github.com"2119 / "demo"2120 / "demo"2121 ).as_posix()2122 package.add_dependency(Factory.create_dependency("demo", {"path": path}))2123 package.add_dependency(Factory.create_dependency("foo", "^1.2.3"))2124 # This is not solvable since the demo version is pinned2125 # via the directory dependency2126 with pytest.raises(SolverProblemError):2127 solver.solve()2128def test_solver_cannot_choose_another_version_for_file_dependencies(2129 solver: Solver, repo: Repository, package: Package2130):2131 pendulum = get_package("pendulum", "2.0.3")2132 demo = get_package("demo", "0.0.8")2133 foo = get_package("foo", "1.2.3")2134 foo.add_dependency(Factory.create_dependency("demo", "<0.1.0"))2135 repo.add_package(foo)2136 repo.add_package(demo)2137 repo.add_package(pendulum)2138 path = (2139 Path(__file__).parent.parent2140 / "fixtures"2141 / "distributions"2142 / "demo-0.1.0-py2.py3-none-any.whl"2143 ).as_posix()2144 package.add_dependency(Factory.create_dependency("demo", {"path": path}))2145 package.add_dependency(Factory.create_dependency("foo", "^1.2.3"))2146 # This is not solvable since the demo version is pinned2147 # via the file dependency2148 with pytest.raises(SolverProblemError):2149 solver.solve()2150def test_solver_cannot_choose_another_version_for_git_dependencies(2151 solver: Solver, repo: Repository, package: Package2152):2153 pendulum = get_package("pendulum", "2.0.3")2154 demo = get_package("demo", "0.0.8")2155 foo = get_package("foo", "1.2.3")2156 foo.add_dependency(Factory.create_dependency("demo", "<0.1.0"))2157 repo.add_package(foo)2158 repo.add_package(demo)2159 repo.add_package(pendulum)2160 package.add_dependency(2161 Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.git"})2162 )2163 package.add_dependency(Factory.create_dependency("foo", "^1.2.3"))2164 # This is not solvable since the demo version is pinned2165 # via the file dependency2166 with pytest.raises(SolverProblemError):2167 solver.solve()2168def test_solver_cannot_choose_another_version_for_url_dependencies(2169 solver: Solver,2170 repo: Repository,2171 package: Package,2172 http: type[httpretty.httpretty],2173):2174 path = (2175 Path(__file__).parent.parent2176 / "fixtures"2177 / "distributions"2178 / "demo-0.1.0-py2.py3-none-any.whl"2179 )2180 http.register_uri(2181 "GET",2182 "https://foo.bar/demo-0.1.0-py2.py3-none-any.whl",2183 body=path.read_bytes(),2184 streaming=True,2185 )2186 pendulum = get_package("pendulum", "2.0.3")2187 demo = get_package("demo", "0.0.8")2188 foo = get_package("foo", "1.2.3")2189 foo.add_dependency(Factory.create_dependency("demo", "<0.1.0"))2190 repo.add_package(foo)2191 repo.add_package(demo)2192 repo.add_package(pendulum)2193 package.add_dependency(2194 Factory.create_dependency(2195 "demo",2196 {"url": "https://foo.bar/distributions/demo-0.1.0-py2.py3-none-any.whl"},2197 )2198 )2199 package.add_dependency(Factory.create_dependency("foo", "^1.2.3"))2200 # This is not solvable since the demo version is pinned2201 # via the git dependency2202 with pytest.raises(SolverProblemError):2203 solver.solve()2204def test_solver_should_not_update_same_version_packages_if_installed_has_no_source_type(2205 solver: Solver, repo: Repository, package: Package, installed: InstalledRepository2206):2207 package.add_dependency(Factory.create_dependency("foo", "1.0.0"))2208 foo = Package(2209 "foo",2210 "1.0.0",2211 source_type="legacy",2212 source_url="https://foo.bar",2213 source_reference="custom",2214 )2215 repo.add_package(foo)2216 installed.add_package(get_package("foo", "1.0.0"))2217 transaction = solver.solve()2218 check_solver_result(2219 transaction, [{"job": "install", "package": foo, "skipped": True}]2220 )2221def test_solver_should_use_the_python_constraint_from_the_environment_if_available(2222 solver: Solver, repo: Repository, package: Package, installed: InstalledRepository2223):2224 solver.provider.set_package_python_versions("~2.7 || ^3.5")2225 package.add_dependency(Factory.create_dependency("A", "^1.0"))2226 a = get_package("A", "1.0.0")2227 a.add_dependency(2228 Factory.create_dependency(2229 "B", {"version": "^1.0.0", "markers": 'python_version < "3.2"'}2230 )2231 )2232 b = get_package("B", "1.0.0")2233 b.python_versions = ">=2.6, <3"2234 repo.add_package(a)2235 repo.add_package(b)2236 with solver.use_environment(MockEnv((2, 7, 18))):2237 transaction = solver.solve()2238 check_solver_result(2239 transaction,2240 [{"job": "install", "package": b}, {"job": "install", "package": a}],2241 )2242def test_solver_should_resolve_all_versions_for_multiple_duplicate_dependencies(2243 solver: Solver, repo: Repository, package: Package2244):2245 package.python_versions = "~2.7 || ^3.5"2246 package.add_dependency(2247 Factory.create_dependency(2248 "A", {"version": "^1.0", "markers": "python_version < '3.5'"}2249 )2250 )2251 package.add_dependency(2252 Factory.create_dependency(2253 "A", {"version": "^2.0", "markers": "python_version >= '3.5'"}2254 )2255 )2256 package.add_dependency(2257 Factory.create_dependency(2258 "B", {"version": "^3.0", "markers": "python_version < '3.5'"}2259 )2260 )2261 package.add_dependency(2262 Factory.create_dependency(2263 "B", {"version": "^4.0", "markers": "python_version >= '3.5'"}2264 )2265 )2266 package_a10 = get_package("A", "1.0.0")2267 package_a20 = get_package("A", "2.0.0")2268 package_b30 = get_package("B", "3.0.0")2269 package_b40 = get_package("B", "4.0.0")2270 repo.add_package(package_a10)2271 repo.add_package(package_a20)2272 repo.add_package(package_b30)2273 repo.add_package(package_b40)2274 transaction = solver.solve()2275 check_solver_result(2276 transaction,2277 [2278 {"job": "install", "package": package_a10},2279 {"job": "install", "package": package_a20},2280 {"job": "install", "package": package_b30},2281 {"job": "install", "package": package_b40},2282 ],2283 )2284def test_solver_should_not_raise_errors_for_irrelevant_python_constraints(2285 solver: Solver, repo: Repository, package: Package2286):2287 package.python_versions = "^3.6"2288 solver.provider.set_package_python_versions("^3.6")2289 package.add_dependency(2290 Factory.create_dependency("dataclasses", {"version": "^0.7", "python": "<3.7"})2291 )2292 dataclasses = get_package("dataclasses", "0.7")2293 dataclasses.python_versions = ">=3.6, <3.7"2294 repo.add_package(dataclasses)2295 transaction = solver.solve()2296 check_solver_result(transaction, [{"job": "install", "package": dataclasses}])2297def test_solver_can_resolve_transitive_extras(2298 solver: Solver, repo: Repository, package: ProjectPackage2299):2300 package.add_dependency(Factory.create_dependency("requests", "^2.24.0"))2301 package.add_dependency(Factory.create_dependency("PyOTA", "^2.1.0"))2302 requests = get_package("requests", "2.24.0")2303 requests.add_dependency(Factory.create_dependency("certifi", ">=2017.4.17"))2304 dep = get_dependency("PyOpenSSL", ">=0.14")2305 requests.add_dependency(2306 Factory.create_dependency("PyOpenSSL", {"version": ">=0.14", "optional": True})2307 )2308 requests.extras["security"] = [dep]2309 pyota = get_package("PyOTA", "2.1.0")2310 pyota.add_dependency(2311 Factory.create_dependency(2312 "requests", {"version": ">=2.24.0", "extras": ["security"]}2313 )2314 )2315 repo.add_package(requests)2316 repo.add_package(pyota)2317 repo.add_package(get_package("certifi", "2017.4.17"))2318 repo.add_package(get_package("pyopenssl", "0.14"))2319 transaction = solver.solve()2320 check_solver_result(2321 transaction,2322 [2323 {"job": "install", "package": get_package("certifi", "2017.4.17")},2324 {"job": "install", "package": get_package("pyopenssl", "0.14")},2325 {"job": "install", "package": requests},2326 {"job": "install", "package": pyota},2327 ],2328 )2329def test_solver_can_resolve_for_packages_with_missing_extras(2330 solver: Solver, repo: Repository, package: ProjectPackage2331):2332 package.add_dependency(2333 Factory.create_dependency(2334 "django-anymail", {"version": "^6.0", "extras": ["postmark"]}2335 )2336 )2337 django_anymail = get_package("django-anymail", "6.1.0")2338 django_anymail.add_dependency(Factory.create_dependency("django", ">=2.0"))2339 django_anymail.add_dependency(Factory.create_dependency("requests", ">=2.4.3"))2340 django_anymail.add_dependency(2341 Factory.create_dependency("boto3", {"version": "*", "optional": True})2342 )2343 django_anymail.extras["amazon_ses"] = [Factory.create_dependency("boto3", "*")]2344 django = get_package("django", "2.2.0")2345 boto3 = get_package("boto3", "1.0.0")2346 requests = get_package("requests", "2.24.0")2347 repo.add_package(django_anymail)2348 repo.add_package(django)2349 repo.add_package(boto3)2350 repo.add_package(requests)2351 transaction = solver.solve()2352 check_solver_result(2353 transaction,2354 [2355 {"job": "install", "package": django},2356 {"job": "install", "package": requests},2357 {"job": "install", "package": django_anymail},2358 ],2359 )2360def test_solver_can_resolve_python_restricted_package_dependencies(2361 solver: Solver, repo: Repository, package: Package, locked: Repository2362):2363 package.add_dependency(2364 Factory.create_dependency("futures", {"version": "^3.3.0", "python": "~2.7"})2365 )2366 package.add_dependency(2367 Factory.create_dependency("pre-commit", {"version": "^2.6", "python": "^3.6.1"})2368 )2369 futures = Package("futures", "3.3.0")2370 futures.python_versions = ">=2.6, <3"2371 pre_commit = Package("pre-commit", "2.7.1")2372 pre_commit.python_versions = ">=3.6.1"2373 locked.add_package(futures)2374 locked.add_package(pre_commit)2375 repo.add_package(futures)2376 repo.add_package(pre_commit)2377 transaction = solver.solve(use_latest=["pre-commit"])2378 check_solver_result(2379 transaction,2380 [2381 {"job": "install", "package": futures},2382 {"job": "install", "package": pre_commit},2383 ],2384 )2385def test_solver_should_not_raise_errors_for_irrelevant_transitive_python_constraints(2386 solver: Solver, repo: Repository, package: Package2387):2388 package.python_versions = "~2.7 || ^3.5"2389 solver.provider.set_package_python_versions("~2.7 || ^3.5")2390 package.add_dependency(Factory.create_dependency("virtualenv", "^20.4.3"))2391 package.add_dependency(2392 Factory.create_dependency("pre-commit", {"version": "^2.6", "python": "^3.6.1"})2393 )2394 virtualenv = get_package("virtualenv", "20.4.3")2395 virtualenv.python_versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"2396 virtualenv.add_dependency(2397 Factory.create_dependency(2398 "importlib-resources", {"version": "*", "markers": 'python_version < "3.7"'}2399 )2400 )2401 pre_commit = Package("pre-commit", "2.7.1")2402 pre_commit.python_versions = ">=3.6.1"2403 pre_commit.add_dependency(2404 Factory.create_dependency(2405 "importlib-resources", {"version": "*", "markers": 'python_version < "3.7"'}2406 )2407 )2408 importlib_resources = get_package("importlib-resources", "5.1.2")2409 importlib_resources.python_versions = ">=3.6"2410 importlib_resources_3_2_1 = get_package("importlib-resources", "3.2.1")2411 importlib_resources_3_2_1.python_versions = (2412 "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"2413 )2414 repo.add_package(virtualenv)2415 repo.add_package(pre_commit)2416 repo.add_package(importlib_resources)2417 repo.add_package(importlib_resources_3_2_1)2418 transaction = solver.solve()2419 check_solver_result(2420 transaction,2421 [2422 {"job": "install", "package": importlib_resources_3_2_1},2423 {"job": "install", "package": pre_commit},2424 {"job": "install", "package": virtualenv},...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...40if x == "1":41 42 43 #Loading packages to Truck 144 Truck1.add(HashMap.get_package("4"), clockTruck1)45 Truck1.add(HashMap.get_package("6"), clockTruck1)46 Truck1.add(HashMap.get_package("12"), clockTruck1)47 Truck1.add(HashMap.get_package("21"), clockTruck1)48 Truck1.add(HashMap.get_package("22"), clockTruck1)49 Truck1.add(HashMap.get_package("31"), clockTruck1)50 Truck1.add(HashMap.get_package("40"), clockTruck1)51 Truck1.add(HashMap.get_package("32"), clockTruck1)52 Truck1.add(HashMap.get_package("24"), clockTruck1)53 Truck1.add(HashMap.get_package("25"), clockTruck1)54 Truck1.add(HashMap.get_package("34"), clockTruck1)55 Truck1.add(HashMap.get_package("26"), clockTruck1)56 Truck1.add(HashMap.get_package("17"), clockTruck1)57 58 print("------------------------------------------")59 60 #Loading packages to truck 2 61 Truck2.add(HashMap.get_package("13"), clockTruck2)62 Truck2.add(HashMap.get_package("39"), clockTruck2)63 Truck2.add(HashMap.get_package("3"), clockTruck2)64 Truck2.add(HashMap.get_package("5"), clockTruck2)65 Truck2.add(HashMap.get_package("37"), clockTruck2)66 Truck2.add(HashMap.get_package("38"), clockTruck2)67 Truck2.add(HashMap.get_package("14"), clockTruck2)68 Truck2.add(HashMap.get_package("15"), clockTruck2)69 Truck2.add(HashMap.get_package("16"), clockTruck2)70 Truck2.add(HashMap.get_package("19"), clockTruck2)71 Truck2.add(HashMap.get_package("20"), clockTruck2)72 Truck2.add(HashMap.get_package("10"), clockTruck2)73 Truck2.add(HashMap.get_package("29"), clockTruck2)74 Truck2.add(HashMap.get_package("30"), clockTruck2)75 Truck2.add(HashMap.get_package("33"), clockTruck2)76 Truck2.add(HashMap.get_package("1"), clockTruck2)77 78 print("----------------------------------------------")79 80 print("--------------Beginning Truck Simulation--------------")81 ## here we call the method start_trip which returns the total round trip miles from the hub and sum the return value to totalMiles82 totalMiles += S.start_trip(Truck2, HashMap, Adjacency, depaT2, clockTruck2)83 ##Here we call a method in Simulation to get the saved departure time on the class and assign it to the proper variable84 depaT2 = S.get_depa()85 ##Here we call a method in Simulation to get the saved hour and assign it to the proper variable86 clockTruck2 = S.get_time()87 88 89 #Loading Packages to Truck 290 Truck2.add(HashMap.get_package("2"), clockTruck2)91 Truck2.add(HashMap.get_package("7"), clockTruck2)92 Truck2.add(HashMap.get_package("36"), clockTruck2)93 Truck2.add(HashMap.get_package("8"), clockTruck2)94 Truck2.add(HashMap.get_package("35"), clockTruck2)95 Truck2.add(HashMap.get_package("27"), clockTruck2)96 Truck2.add(HashMap.get_package("18"), clockTruck2)97 Truck2.add(HashMap.get_package("23"), clockTruck2)98 Truck2.add(HashMap.get_package("11"), clockTruck2)99 Truck2.add(HashMap.get_package("9"), clockTruck2)100 Truck2.add(HashMap.get_package("28"), clockTruck2)101 102 totalMiles += S.start_trip(Truck1, HashMap, Adjacency, depaT1, clockTruck1)103 depaT21 = S.get_depa()104 clockTruck1 = S.get_time()105 106 totalMiles += S.start_trip(Truck2, HashMap, Adjacency, depaT2, clockTruck2)107 depaT2 = S.get_depa()108 clockTruck2 = S.get_time()109 110 print("------------------------------------------------") 111 print("------------------------------------------------")112 print(" ------Total Miles For All Trucks------ ")113 print(" ", totalMiles) 114 115 print()116 117 118 119 print("-------------------------------Ending of the Truck simulator-------------------------------")120 121 print()122 print()123 print("--------------------------------------------------------------Results Menu--------------------------------------------------------------")124 print("Would you like to track packages at certain time? if yes type the desired hour of format HH:MM, if not type 'n'")125 126 x = input()127 if x != 'n':128 129 clockTracker = HashMap.transform_hour_to_string(x)130 print("Packages status at: ", HashMap.transform_hour(clockTracker))131 HashMap.get_all_packages(clockTracker, Truck1, Truck2, Truck3)132 input("Press Enter to continue...")133 if clockTracker == -1:134 quit()135 136 print("current hour", HashMap.transform_hour(clockTracker))137 print(" 1.Look Packages by ID")138 print(" 2.Look Packages by address")139 print(" 3.Look Packages by deadline")140 print(" 4.Look Packages by city")141 print(" 5.Look Packages by zip code")142 print(" 6.Look Packages by weight")143 print(" 7.Look Packages by status")144 print(" 8.Retrieve total mileage")145 print(" 9.Exit application")146 while x != "9":147 print("What would you like to do?")148 149 x = input()150 151 if x == "1":152 print("Type the desire ID ")153 z = input()154 res = HashMap.get_package(z)155 if res is not None:156 status = HashMap.convert_status(res, clockTracker)157 print("---------------------------------------------------------------------")158 print("Package ID: ", res.get_packageID())159 print("Package Address: ", res.get_delivery_address())160 print("Delivery Deadline: ", res.get_delivery_deadline())161 print("City: ", res.get_delivery_city())162 print("Zip: ", res.get_delivery_zip())163 print("Weight: ", res.get_package_weight())164 print("Status: ", status)165 if status == "delivered":166 print("Delivery Time: ", HashMap.transform_hour(res.get_delivery_time()))167 print("---------------------------------------------------------------------")168 ...

Full Screen

Full Screen

password_hash_gpgme.py

Source:password_hash_gpgme.py Github

copy

Full Screen

...42 # Check that we got all the expected supplemental credentials43 # And they are in the expected order.44 size = len(sc.sub.packages)45 self.assertEquals(5, size)46 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")47 self.assertEquals(1, pos)48 self.assertEquals("Primary:Kerberos-Newer-Keys", package.name)49 (pos, package) = get_package(sc, "Primary:Kerberos")50 self.assertEquals(2, pos)51 self.assertEquals("Primary:Kerberos", package.name)52 (pos, wd_package) = get_package(sc, "Primary:WDigest")53 self.assertEquals(3, pos)54 self.assertEquals("Primary:WDigest", wd_package.name)55 (pos, package) = get_package(sc, "Packages")56 self.assertEquals(4, pos)57 self.assertEquals("Packages", package.name)58 (pos, package) = get_package(sc, "Primary:SambaGPG")59 self.assertEquals(5, pos)60 self.assertEquals("Primary:SambaGPG", package.name)61 # Check that the WDigest values are correct.62 #63 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,64 binascii.a2b_hex(wd_package.data))65 self.check_wdigests(digests)66 def test_supplementalCredentials_cleartext(self):67 self.add_user(clear_text=True)68 if not self.lp.get("password hash gpg key ids"):69 self.skipTest("No password hash gpg key ids, " +70 "Primary:SambaGPG will not be generated");71 sc = self.get_supplemental_creds()72 # Check that we got all the expected supplemental credentials73 # And they are in the expected order.74 size = len(sc.sub.packages)75 self.assertEquals(6, size)76 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")77 self.assertEquals(1, pos)78 self.assertEquals("Primary:Kerberos-Newer-Keys", package.name)79 (pos, package) = get_package(sc, "Primary:Kerberos")80 self.assertEquals(2, pos)81 self.assertEquals("Primary:Kerberos", package.name)82 (pos, wd_package) = get_package(sc, "Primary:WDigest")83 self.assertEquals(3, pos)84 self.assertEquals("Primary:WDigest", wd_package.name)85 (pos, ct_package) = get_package(sc, "Primary:CLEARTEXT")86 self.assertEquals(4, pos)87 self.assertEquals("Primary:CLEARTEXT", ct_package.name)88 (pos, package) = get_package(sc, "Packages")89 self.assertEquals(5, pos)90 self.assertEquals("Packages", package.name)91 (pos, package) = get_package(sc, "Primary:SambaGPG")92 self.assertEquals(6, pos)93 self.assertEquals("Primary:SambaGPG", package.name)94 # Check that the WDigest values are correct.95 #96 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,97 binascii.a2b_hex(wd_package.data))98 self.check_wdigests(digests)99 # Check the clear text value is correct.100 ct = ndr_unpack(drsblobs.package_PrimaryCLEARTEXTBlob,101 binascii.a2b_hex(ct_package.data))102 self.assertEquals(USER_PASS.encode('utf-16-le'), ct.cleartext)103 def test_userPassword_multiple_hashes(self):104 self.add_user(options=[(105 "password hash userPassword schemes",106 "CryptSHA512 CryptSHA256 CryptSHA512")])107 sc = self.get_supplemental_creds()108 # Check that we got all the expected supplemental credentials109 # And they are in the expected order.110 size = len(sc.sub.packages)111 self.assertEquals(6, size)112 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")113 self.assertEquals(1, pos)114 self.assertEquals("Primary:Kerberos-Newer-Keys", package.name)115 (pos, package) = get_package(sc, "Primary:Kerberos")116 self.assertEquals(2, pos)117 self.assertEquals("Primary:Kerberos", package.name)118 (pos, wp_package) = get_package(sc, "Primary:WDigest")119 self.assertEquals(3, pos)120 self.assertEquals("Primary:WDigest", wp_package.name)121 (pos, up_package) = get_package(sc, "Primary:userPassword")122 self.assertEquals(4, pos)123 self.assertEquals("Primary:userPassword", up_package.name)124 (pos, package) = get_package(sc, "Packages")125 self.assertEquals(5, pos)126 self.assertEquals("Packages", package.name)127 (pos, package) = get_package(sc, "Primary:SambaGPG")128 self.assertEquals(6, pos)129 self.assertEquals("Primary:SambaGPG", package.name)130 # Check that the WDigest values are correct.131 #132 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,133 binascii.a2b_hex(wp_package.data))134 self.check_wdigests(digests)135 # Check that the userPassword hashes are computed correctly136 # Expect three hashes to be calculated137 up = ndr_unpack(drsblobs.package_PrimaryUserPasswordBlob,138 binascii.a2b_hex(up_package.data))139 self.checkUserPassword(up, [140 ("{CRYPT}", "6", None),141 ("{CRYPT}", "5", None),142 ("{CRYPT}", "6", None)143 ])144 self.checkNtHash(USER_PASS, up.current_nt_hash.hash)145 def test_userPassword_multiple_hashes_rounds_specified(self):146 self.add_user(options=[(147 "password hash userPassword schemes",148 "CryptSHA512:rounds=5120 CryptSHA256:rounds=2560 CryptSHA512:rounds=5122")])149 sc = self.get_supplemental_creds()150 # Check that we got all the expected supplemental credentials151 # And they are in the expected order.152 size = len(sc.sub.packages)153 self.assertEquals(6, size)154 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")155 self.assertEquals(1, pos)156 self.assertEquals("Primary:Kerberos-Newer-Keys", package.name)157 (pos, package) = get_package(sc, "Primary:Kerberos")158 self.assertEquals(2, pos)159 self.assertEquals("Primary:Kerberos", package.name)160 (pos, wp_package) = get_package(sc, "Primary:WDigest")161 self.assertEquals(3, pos)162 self.assertEquals("Primary:WDigest", wp_package.name)163 (pos, up_package) = get_package(sc, "Primary:userPassword")164 self.assertEquals(4, pos)165 self.assertEquals("Primary:userPassword", up_package.name)166 (pos, package) = get_package(sc, "Packages")167 self.assertEquals(5, pos)168 self.assertEquals("Packages", package.name)169 (pos, package) = get_package(sc, "Primary:SambaGPG")170 self.assertEquals(6, pos)171 self.assertEquals("Primary:SambaGPG", package.name)172 # Check that the WDigest values are correct.173 #174 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,175 binascii.a2b_hex(wp_package.data))176 self.check_wdigests(digests)177 # Check that the userPassword hashes are computed correctly178 # Expect three hashes to be calculated179 up = ndr_unpack(drsblobs.package_PrimaryUserPasswordBlob,180 binascii.a2b_hex(up_package.data))181 self.checkUserPassword(up, [182 ("{CRYPT}", "6", 5120),183 ("{CRYPT}", "5", 2560),...

Full Screen

Full Screen

password_hash_fl2008.py

Source:password_hash_fl2008.py Github

copy

Full Screen

...40 # Check that we got all the expected supplemental credentials41 # And they are in the expected order.42 size = len(sc.sub.packages)43 self.assertEqual(4, size)44 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")45 self.assertEqual(1, pos)46 self.assertEqual("Primary:Kerberos-Newer-Keys", package.name)47 (pos, package) = get_package(sc, "Primary:Kerberos")48 self.assertEqual(2, pos)49 self.assertEqual("Primary:Kerberos", package.name)50 (pos, package) = get_package(sc, "Packages")51 self.assertEqual(3, pos)52 self.assertEqual("Packages", package.name)53 (pos, package) = get_package(sc, "Primary:WDigest")54 self.assertEqual(4, pos)55 self.assertEqual("Primary:WDigest", package.name)56 # Check that the WDigest values are correct.57 #58 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,59 binascii.a2b_hex(package.data))60 self.check_wdigests(digests)61 def test_userPassword_sha512(self):62 self.add_user(options=[("password hash userPassword schemes",63 "CryptSHA512")])64 sc = self.get_supplemental_creds()65 # Check that we got all the expected supplemental credentials66 # And they are in the expected order.67 size = len(sc.sub.packages)68 self.assertEqual(5, size)69 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")70 self.assertEqual(1, pos)71 self.assertEqual("Primary:Kerberos-Newer-Keys", package.name)72 (pos, package) = get_package(sc, "Primary:Kerberos")73 self.assertEqual(2, pos)74 self.assertEqual("Primary:Kerberos", package.name)75 (pos, wp_package) = get_package(sc, "Primary:WDigest")76 self.assertEqual(3, pos)77 self.assertEqual("Primary:WDigest", wp_package.name)78 (pos, package) = get_package(sc, "Packages")79 self.assertEqual(4, pos)80 self.assertEqual("Packages", package.name)81 (pos, up_package) = get_package(sc, "Primary:userPassword")82 self.assertEqual(5, pos)83 self.assertEqual("Primary:userPassword", up_package.name)84 # Check that the WDigest values are correct.85 #86 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,87 binascii.a2b_hex(wp_package.data))88 self.check_wdigests(digests)89 # Check that the userPassword hashes are computed correctly90 #91 up = ndr_unpack(drsblobs.package_PrimaryUserPasswordBlob,92 binascii.a2b_hex(up_package.data))93 self.checkUserPassword(up, [("{CRYPT}", "6", None)])94 self.checkNtHash(USER_PASS, up.current_nt_hash.hash)95 def test_supplementalCredentials_cleartext(self):96 self.add_user(clear_text=True)97 sc = self.get_supplemental_creds()98 # Check that we got all the expected supplemental credentials99 # And they are in the expected order.100 size = len(sc.sub.packages)101 self.assertEqual(5, size)102 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")103 self.assertEqual(1, pos)104 self.assertEqual("Primary:Kerberos-Newer-Keys", package.name)105 (pos, package) = get_package(sc, "Primary:Kerberos")106 self.assertEqual(2, pos)107 self.assertEqual("Primary:Kerberos", package.name)108 (pos, wd_package) = get_package(sc, "Primary:WDigest")109 self.assertEqual(3, pos)110 self.assertEqual("Primary:WDigest", wd_package.name)111 (pos, package) = get_package(sc, "Packages")112 self.assertEqual(4, pos)113 self.assertEqual("Packages", package.name)114 (pos, ct_package) = get_package(sc, "Primary:CLEARTEXT")115 self.assertEqual(5, pos)116 self.assertEqual("Primary:CLEARTEXT", ct_package.name)117 # Check that the WDigest values are correct.118 #119 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,120 binascii.a2b_hex(wd_package.data))121 self.check_wdigests(digests)122 # Check the clear text value is correct.123 ct = ndr_unpack(drsblobs.package_PrimaryCLEARTEXTBlob,124 binascii.a2b_hex(ct_package.data))125 self.assertEqual(USER_PASS.encode('utf-16-le'), ct.cleartext)126 def test_userPassword_cleartext_sha256(self):127 self.add_user(clear_text=True,128 options=[("password hash userPassword schemes",129 "CryptSHA256:rounds=5000")])130 sc = self.get_supplemental_creds()131 # Check that we got all the expected supplemental credentials132 # And they are in the expected order.133 size = len(sc.sub.packages)134 self.assertEqual(6, size)135 (pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")136 self.assertEqual(1, pos)137 self.assertEqual("Primary:Kerberos-Newer-Keys", package.name)138 (pos, package) = get_package(sc, "Primary:Kerberos")139 self.assertEqual(2, pos)140 self.assertEqual("Primary:Kerberos", package.name)141 (pos, wd_package) = get_package(sc, "Primary:WDigest")142 self.assertEqual(3, pos)143 self.assertEqual("Primary:WDigest", wd_package.name)144 (pos, ct_package) = get_package(sc, "Primary:CLEARTEXT")145 self.assertEqual(4, pos)146 self.assertEqual("Primary:CLEARTEXT", ct_package.name)147 (pos, package) = get_package(sc, "Packages")148 self.assertEqual(5, pos)149 self.assertEqual("Packages", package.name)150 (pos, up_package) = get_package(sc, "Primary:userPassword")151 self.assertEqual(6, pos)152 self.assertEqual("Primary:userPassword", up_package.name)153 # Check that the WDigest values are correct.154 #155 digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,156 binascii.a2b_hex(wd_package.data))157 self.check_wdigests(digests)158 # Check the clear text value is correct.159 ct = ndr_unpack(drsblobs.package_PrimaryCLEARTEXTBlob,160 binascii.a2b_hex(ct_package.data))161 self.assertEqual(USER_PASS.encode('utf-16-le'), ct.cleartext)162 # Check that the userPassword hashes are computed correctly163 #164 up = ndr_unpack(drsblobs.package_PrimaryUserPasswordBlob,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful