|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import json |
3 | 4 | import logging
|
4 | 5 | import tempfile
|
| 6 | +import uuid |
5 | 7 |
|
| 8 | +from hashlib import sha256 |
6 | 9 | from pathlib import Path
|
7 | 10 | from typing import TYPE_CHECKING
|
8 | 11 |
|
@@ -94,7 +97,7 @@ def test_lock_file_data_is_ordered(locker: Locker, root: ProjectPackage):
|
94 | 97 | [metadata]
|
95 | 98 | lock-version = "1.1"
|
96 | 99 | python-versions = "*"
|
97 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 100 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
98 | 101 |
|
99 | 102 | [metadata.files]
|
100 | 103 | A = [
|
@@ -303,7 +306,7 @@ def test_lock_packages_with_null_description(locker: Locker, root: ProjectPackag
|
303 | 306 | [metadata]
|
304 | 307 | lock-version = "1.1"
|
305 | 308 | python-versions = "*"
|
306 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 309 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
307 | 310 |
|
308 | 311 | [metadata.files]
|
309 | 312 | A = []
|
@@ -343,7 +346,7 @@ def test_lock_file_should_not_have_mixed_types(locker: Locker, root: ProjectPack
|
343 | 346 | [metadata]
|
344 | 347 | lock-version = "1.1"
|
345 | 348 | python-versions = "*"
|
346 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 349 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
347 | 350 |
|
348 | 351 | [metadata.files]
|
349 | 352 | A = []
|
@@ -373,7 +376,7 @@ def test_reading_lock_file_should_raise_an_error_on_invalid_data(locker: Locker)
|
373 | 376 | [metadata]
|
374 | 377 | lock-version = "1.1"
|
375 | 378 | python-versions = "*"
|
376 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 379 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
377 | 380 |
|
378 | 381 | [metadata.files]
|
379 | 382 | A = []
|
@@ -420,7 +423,7 @@ def test_locking_legacy_repository_package_should_include_source_section(
|
420 | 423 | [metadata]
|
421 | 424 | lock-version = "1.1"
|
422 | 425 | python-versions = "*"
|
423 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 426 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
424 | 427 |
|
425 | 428 | [metadata.files]
|
426 | 429 | A = []
|
@@ -504,7 +507,7 @@ def test_extras_dependencies_are_ordered(locker: Locker, root: ProjectPackage):
|
504 | 507 | [metadata]
|
505 | 508 | lock-version = "1.1"
|
506 | 509 | python-versions = "*"
|
507 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 510 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
508 | 511 |
|
509 | 512 | [metadata.files]
|
510 | 513 | A = []
|
@@ -598,7 +601,7 @@ def test_locker_dumps_dependency_information_correctly(
|
598 | 601 | [metadata]
|
599 | 602 | lock-version = "1.1"
|
600 | 603 | python-versions = "*"
|
601 |
| -content-hash = "178f2cd01dc40e96be23a4a0ae1094816626346346618335e5ff4f0b2c0c5831" |
| 604 | +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" |
602 | 605 |
|
603 | 606 | [metadata.files]
|
604 | 607 | A = []
|
@@ -651,3 +654,46 @@ def test_locked_repository_uses_root_dir_of_package(
|
651 | 654 | assert root_dir.match("*/lib/libA")
|
652 | 655 | # relative_to raises an exception if not relative - is_relative_to comes in py3.9
|
653 | 656 | assert root_dir.relative_to(locker.lock.path.parent.resolve()) is not None
|
| 657 | + |
| 658 | + |
| 659 | +@pytest.mark.parametrize( |
| 660 | + ("local_config", "fresh"), |
| 661 | + [ |
| 662 | + ({}, True), |
| 663 | + ({"dependencies": [uuid.uuid4().hex]}, True), |
| 664 | + ( |
| 665 | + { |
| 666 | + "dependencies": [uuid.uuid4().hex], |
| 667 | + "dev-dependencies": [uuid.uuid4().hex], |
| 668 | + }, |
| 669 | + True, |
| 670 | + ), |
| 671 | + ( |
| 672 | + { |
| 673 | + "dependencies": [uuid.uuid4().hex], |
| 674 | + "dev-dependencies": None, |
| 675 | + }, |
| 676 | + True, |
| 677 | + ), |
| 678 | + ({"dependencies": [uuid.uuid4().hex], "groups": [uuid.uuid4().hex]}, False), |
| 679 | + ], |
| 680 | +) |
| 681 | +def test_content_hash_with_legacy_is_compatible( |
| 682 | + local_config: dict[str, list[str]], fresh: bool, locker: Locker |
| 683 | +) -> None: |
| 684 | + # old hash generation |
| 685 | + relevant_content = {} |
| 686 | + for key in locker._legacy_keys: |
| 687 | + relevant_content[key] = local_config.get(key) |
| 688 | + |
| 689 | + locker = locker.__class__( |
| 690 | + lock=locker.lock.path, |
| 691 | + local_config=local_config, |
| 692 | + ) |
| 693 | + |
| 694 | + old_content_hash = sha256( |
| 695 | + json.dumps(relevant_content, sort_keys=True).encode() |
| 696 | + ).hexdigest() |
| 697 | + content_hash = locker._get_content_hash() |
| 698 | + |
| 699 | + assert (content_hash == old_content_hash) or fresh |
0 commit comments