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

Function assert_namespace_packages_warning

tests/test_environment.py:382–410  ·  view source on GitHub ↗
(distribution, version, expected_warning)

Source from the content-addressed store, hash-verified

380
381
382def assert_namespace_packages_warning(distribution, version, expected_warning):
383 # type: (str, str, bool) -> None
384 requirement = parse_requirement_string("{}=={}".format(distribution, version))
385 pb = PEXBuilder()
386 for resolved_dist in resolver.resolve(
387 requirements=[requirement],
388 resolver=ConfiguredResolver.default(),
389 ).distributions:
390 pb.add_dist_location(resolved_dist.distribution.location)
391 pb.freeze()
392
393 process = PEX(pb.path()).run(args=["-c", ""], blocking=False, stderr=subprocess.PIPE)
394 _, stderr = process.communicate()
395 stderr_text = stderr.decode("utf8")
396
397 if sys.version_info[:2] >= (3, 12):
398 partial_warning_preamble = (
399 "PEXWarning: The legacy `pkg_resources` package cannot be imported by"
400 )
401 else:
402 partial_warning_preamble = "PEXWarning: The `pkg_resources` package was loaded"
403 partial_warning_detail = "{} namespace packages:".format(requirement)
404
405 if expected_warning:
406 assert partial_warning_preamble in stderr_text, stderr_text
407 assert partial_warning_detail in stderr_text, stderr_text
408 else:
409 assert partial_warning_preamble not in stderr_text, stderr_text
410 assert partial_warning_detail not in stderr_text, stderr_text
411
412
413def test_present_non_empty_namespace_packages_metadata_does_warn():

Calls 11

add_dist_locationMethod · 0.95
freezeMethod · 0.95
pathMethod · 0.95
parse_requirement_stringFunction · 0.90
PEXBuilderClass · 0.90
PEXClass · 0.90
communicateMethod · 0.80
decodeMethod · 0.80
resolveMethod · 0.45
defaultMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected