MCPcopy
hub / github.com/pex-tool/pex / test_lock_single_target

Function test_lock_single_target

tests/integration/test_locked_resolve.py:93–158  ·  view source on GitHub ↗
(
    tmpdir,  # type: Any
    requirements,  # type: Iterable[str]
    lock_style,  # type: LockStyle.Value
)

Source from the content-addressed store, hash-verified

91 [pytest.param(style, id=str(style)) for style in (LockStyle.STRICT, LockStyle.SOURCES)],
92)
93def test_lock_single_target(
94 tmpdir, # type: Any
95 requirements, # type: Iterable[str]
96 lock_style, # type: LockStyle.Value
97):
98 # type: (...) -> None
99
100 downloaded, locked_resolves = create_lock(lock_style, requirements=requirements)
101 assert 1 == len(locked_resolves)
102 lock = locked_resolves[0]
103
104 assert targets.current().platform.tag == lock.platform_tag
105
106 def pin(local_distribution):
107 # type: (LocalDistribution) -> Pin
108 project_name_and_version = dist_metadata.project_name_and_version(local_distribution.path)
109 assert project_name_and_version is not None
110 return Pin.canonicalize(project_name_and_version)
111
112 local_distributions_by_pin = {
113 pin(local_dist): local_dist for local_dist in downloaded.local_distributions
114 } # type: Dict[Pin, LocalDistribution]
115
116 assert sorted(local_distributions_by_pin) == sorted(
117 locked_req.pin for locked_req in lock.locked_requirements
118 ), (
119 "Expected the actual set of downloaded distributions to match the set of pinned "
120 "requirements in the lock."
121 )
122
123 for locked_req in lock.locked_requirements:
124 fingerprint = locked_req.artifact.fingerprint
125 assert fingerprint.hash == CacheHelper.hash(
126 path=local_distributions_by_pin[locked_req.pin].path,
127 hasher=lambda: hashlib.new(fingerprint.algorithm),
128 ), (
129 "Expected the fingerprint of the downloaded distribution to match the fingerprint "
130 "recorded in the lock."
131 )
132
133 find_links_repo = os.path.join(str(tmpdir), "find-links")
134 os.mkdir(find_links_repo)
135 for local_dist in downloaded.local_distributions:
136 safe_symlink(
137 local_dist.path, os.path.join(find_links_repo, os.path.basename(local_dist.path))
138 )
139 _, find_links_locked_resolves = create_lock(
140 lock_style,
141 requirements=requirements,
142 repos_configuration=ReposConfiguration.create(
143 indexes=[],
144 find_links=[Repo(find_links_repo)],
145 ),
146 )
147 assert normalize(
148 locked_resolves, skip_additional_artifacts=True, skip_urls=True, skip_verified=True
149 ) == normalize(
150 find_links_locked_resolves,

Callers

nothing calls this directly

Calls 9

safe_symlinkFunction · 0.90
RepoClass · 0.90
normalizeFunction · 0.85
hashMethod · 0.80
create_lockFunction · 0.70
pinFunction · 0.70
currentMethod · 0.45
joinMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected