scripts/pythondistdeps: Add tests for: Rework error messages
This commit is contained in:
parent
098c48d46d
commit
c2e0f33565
@ -1247,6 +1247,19 @@
|
||||
python3.9dist(coverage)
|
||||
python3.9dist(nose)
|
||||
python3.9dist(zope-testing)
|
||||
--requires --normalized-names-format pep503 --require-extras-subpackages --package-name python3-zope-component+missing:
|
||||
--provides --majorver-provides --normalized-names-format pep503 --package-name python3-zope-component+missing:
|
||||
usr/lib/python3.9/site-packages/zope.component-4.3.0-py3.9.egg-info:
|
||||
stderr:
|
||||
provides: |-
|
||||
Error: The package name contains an extras name `missing` that was not found in the metadata.
|
||||
Check if the extras were removed from the project. If so, consider removing the subpackage and obsoleting it from another.
|
||||
requires: |-
|
||||
Error: The package name contains an extras name `missing` that was not found in the metadata.
|
||||
Check if the extras were removed from the project. If so, consider removing the subpackage and obsoleting it from another.
|
||||
stdout:
|
||||
provides: '*** PYTHON_EXTRAS_NOT_FOUND_ERROR___SEE_STDERR ***'
|
||||
requires: '*** PYTHON_EXTRAS_NOT_FOUND_ERROR___SEE_STDERR ***'
|
||||
--requires --normalized-names-format pep503 --require-extras-subpackages --package-name python3-zope-component+testing:
|
||||
--provides --majorver-provides --normalized-names-format pep503 --package-name python3-zope-component+testing:
|
||||
usr/lib/python3.9/site-packages/zope.component-4.3.0-py3.9.egg-info:
|
||||
|
@ -41,18 +41,30 @@ PYTHONDISTDEPS_PATH = Path(__file__).parent / '..' / 'pythondistdeps.py'
|
||||
TEST_DATA_PATH = Path(__file__).parent / 'data' / 'scripts_pythondistdeps'
|
||||
|
||||
|
||||
def run_pythondistdeps(provides_params, requires_params, dist_egg_info_path):
|
||||
def run_pythondistdeps(provides_params, requires_params, dist_egg_info_path, expect_failure=False):
|
||||
"""Runs pythondistdeps.py on `dits_egg_info_path` with given
|
||||
provides and requires parameters and returns a dict with generated provides and requires"""
|
||||
info_path = TEST_DATA_PATH / dist_egg_info_path
|
||||
files = '\n'.join(map(str, info_path.iterdir()))
|
||||
|
||||
provides = subprocess.check_output((sys.executable, PYTHONDISTDEPS_PATH, *shlex.split(provides_params)),
|
||||
input=files, encoding="utf-8")
|
||||
requires = subprocess.check_output((sys.executable, PYTHONDISTDEPS_PATH, *shlex.split(requires_params)),
|
||||
input=files, encoding="utf-8")
|
||||
provides = subprocess.run((sys.executable, PYTHONDISTDEPS_PATH, *shlex.split(provides_params)),
|
||||
input=files, capture_output=True, check=False, encoding="utf-8")
|
||||
requires = subprocess.run((sys.executable, PYTHONDISTDEPS_PATH, *shlex.split(requires_params)),
|
||||
input=files, capture_output=True, check=False, encoding="utf-8")
|
||||
|
||||
return {"provides": provides.strip(), "requires": requires.strip()}
|
||||
if expect_failure:
|
||||
if provides.returncode == 0 or requires.returncode == 0:
|
||||
raise RuntimeError(f"pythondistdeps.py did not exit with a non-zero code as expected.\n"
|
||||
f"Used parameters: ({provides_params}, {requires_params}, {dist_egg_info_path})")
|
||||
stdout = {"provides": provides.stdout.strip(), "requires": requires.stdout.strip()}
|
||||
stderr = {"provides": provides.stderr.strip(), "requires": requires.stderr.strip()}
|
||||
return {"stderr": stderr, "stdout": stdout}
|
||||
|
||||
else:
|
||||
if provides.returncode != 0 or requires.returncode != 0:
|
||||
raise RuntimeError(f"pythondistdeps.py unexpectedly exited with a non-zero code.\n"
|
||||
f"Used parameters: ({provides_params}, {requires_params}, {dist_egg_info_path})")
|
||||
return {"provides": provides.stdout.strip(), "requires": requires.stdout.strip()}
|
||||
|
||||
|
||||
def load_test_data():
|
||||
@ -212,7 +224,8 @@ def fixture_check_and_install_test_data():
|
||||
def test_pythondistdeps(provides_params, requires_params, dist_egg_info_path, expected):
|
||||
"""Runs pythondistdeps with the given parameters and dist-info/egg-info
|
||||
path, compares the results with the expected results"""
|
||||
assert expected == run_pythondistdeps(provides_params, requires_params, dist_egg_info_path)
|
||||
expect_failure = "stderr" in expected
|
||||
assert expected == run_pythondistdeps(provides_params, requires_params, dist_egg_info_path, expect_failure)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -235,8 +248,10 @@ if __name__ == "__main__":
|
||||
for provides_params, requires_params, dist_egg_info_path, expected in generate_test_cases(test_data):
|
||||
# Print a dot to stderr for each test run to keep user informed about progress
|
||||
print(".", end="", flush=True, file=sys.stderr)
|
||||
|
||||
expect_failure = "stderr" in test_data[requires_params][provides_params][dist_egg_info_path]
|
||||
test_data[requires_params][provides_params][dist_egg_info_path] = \
|
||||
run_pythondistdeps(provides_params, requires_params, dist_egg_info_path)
|
||||
run_pythondistdeps(provides_params, requires_params, dist_egg_info_path, expect_failure)
|
||||
|
||||
print(yaml.dump(test_data, indent=4))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user