Change {matches -> contains}_expected_lines

This also updates invocations that can't be translated as-is into a
different equivalent check.
This commit is contained in:
Pradyun Gedam 2020-07-27 19:23:59 +05:30
parent a89ede7da3
commit e4f8e0a2b8
No known key found for this signature in database
GPG Key ID: FF99710C4332258E
1 changed files with 9 additions and 18 deletions

View File

@ -1,10 +1,7 @@
from tests.lib import create_test_package_with_setup from tests.lib import create_test_package_with_setup
def matches_expected_lines(string, expected_lines, exact=True): def contains_expected_lines(string, expected_lines):
if exact:
return set(string.splitlines()) == set(expected_lines)
# If not exact, check that all expected lines are present
return set(expected_lines) <= set(string.splitlines()) return set(expected_lines) <= set(string.splitlines())
@ -41,8 +38,7 @@ def test_check_install_canonicalization(script, deprecated_python):
"ERROR: pkga 1.0 requires SPECIAL.missing, which is not installed.", "ERROR: pkga 1.0 requires SPECIAL.missing, which is not installed.",
] ]
# Deprecated python versions produce an extra warning on stderr # Deprecated python versions produce an extra warning on stderr
assert matches_expected_lines( assert contains_expected_lines(result.stderr, expected_lines)
result.stderr, expected_lines, exact=not deprecated_python)
assert result.returncode == 0 assert result.returncode == 0
# Install the second missing package and expect that there is no warning # Install the second missing package and expect that there is no warning
@ -51,8 +47,7 @@ def test_check_install_canonicalization(script, deprecated_python):
result = script.pip( result = script.pip(
'install', '--no-index', special_path, '--quiet', 'install', '--no-index', special_path, '--quiet',
) )
assert matches_expected_lines( assert "requires" not in result.stderr
result.stderr, [], exact=not deprecated_python)
assert result.returncode == 0 assert result.returncode == 0
# Double check that all errors are resolved in the end # Double check that all errors are resolved in the end
@ -60,7 +55,7 @@ def test_check_install_canonicalization(script, deprecated_python):
expected_lines = [ expected_lines = [
"No broken requirements found.", "No broken requirements found.",
] ]
assert matches_expected_lines(result.stdout, expected_lines) assert contains_expected_lines(result.stdout, expected_lines)
assert result.returncode == 0 assert result.returncode == 0
@ -85,33 +80,29 @@ def test_check_install_does_not_warn_for_out_of_graph_issues(
# Install a package without it's dependencies # Install a package without it's dependencies
result = script.pip('install', '--no-index', pkg_broken_path, '--no-deps') result = script.pip('install', '--no-index', pkg_broken_path, '--no-deps')
# Deprecated python versions produce an extra warning on stderr assert "requires" not in result.stderr
assert matches_expected_lines(
result.stderr, [], exact=not deprecated_python)
# Install conflict package # Install conflict package
result = script.pip( result = script.pip(
'install', '--no-index', pkg_conflict_path, allow_stderr_error=True, 'install', '--no-index', pkg_conflict_path, allow_stderr_error=True,
) )
assert matches_expected_lines(result.stderr, [ assert contains_expected_lines(result.stderr, [
"ERROR: broken 1.0 requires missing, which is not installed.",
( (
"ERROR: broken 1.0 has requirement conflict<1.0, but " "ERROR: broken 1.0 has requirement conflict<1.0, but "
"you'll have conflict 1.0 which is incompatible." "you'll have conflict 1.0 which is incompatible."
), ),
], exact=not deprecated_python) ])
# Install unrelated package # Install unrelated package
result = script.pip( result = script.pip(
'install', '--no-index', pkg_unrelated_path, '--quiet', 'install', '--no-index', pkg_unrelated_path, '--quiet',
) )
# should not warn about broken's deps when installing unrelated package # should not warn about broken's deps when installing unrelated package
assert matches_expected_lines( assert "requires" not in result.stderr
result.stderr, [], exact=not deprecated_python)
result = script.pip('check', expect_error=True) result = script.pip('check', expect_error=True)
expected_lines = [ expected_lines = [
"broken 1.0 requires missing, which is not installed.", "broken 1.0 requires missing, which is not installed.",
"broken 1.0 has requirement conflict<1.0, but you have conflict 1.0.", "broken 1.0 has requirement conflict<1.0, but you have conflict 1.0.",
] ]
assert matches_expected_lines(result.stdout, expected_lines) assert contains_expected_lines(result.stdout, expected_lines)