Improve UX and tests of check command

This should really be 3 atomic commits but I'm short on time.

- Prints a message on clean environment
- Marked tests as network based
- Added helper that matches lines irrespective of order.
This commit is contained in:
Pradyun S. Gedam 2016-06-26 19:50:09 +05:30
parent d7444b784a
commit 8b4ebc1ee5
2 changed files with 57 additions and 10 deletions

View File

@ -35,3 +35,5 @@ class CheckCommand(Command):
if missing_reqs_dict or incompatible_reqs_dict:
return 1
else:
logger.info("No broken requirements found.")

View File

@ -1,11 +1,26 @@
import pytest
def matches_expected_lines(string, expected_lines):
# Ignore empty lines
output_lines = set(filter(None, string.splitlines()))
# Match regardless of order
return set(output_lines) == set(expected_lines)
def test_check_clean(script):
"""On a clean environment, check shouldn't return anything.
"""On a clean environment, check should print a helpful message.
"""
result = script.pip('check')
assert result.stdout == ""
expected_lines = (
"No broken requirements found.",
)
assert matches_expected_lines(result.stdout, expected_lines)
@pytest.mark.network
def test_check_missing_dependency(script):
# this will also install ipython, a dependency
script.pip('install', 'ipdb==0.7')
@ -15,11 +30,14 @@ def test_check_missing_dependency(script):
result = script.pip('check', expect_error=True)
assert result.stdout == ("ipdb 0.7 requires ipython, "
"which is not installed.\n")
expected_lines = (
"ipdb 0.7 requires ipython, which is not installed.",
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 1
@pytest.mark.network
def test_check_missing_dependency_normalize_case(script):
# Install some things
script.pip('install', 'devpi-web==2.2.2')
@ -31,13 +49,15 @@ def test_check_missing_dependency_normalize_case(script):
result = script.pip('check', expect_error=True)
assert ('devpi-web 2.2.2 requires pygments, '
'which is not installed.') in result.stdout
assert ('pyramid 1.5.2 requires zope.deprecation, '
'which is not installed.') in result.stdout
expected_lines = (
"devpi-web 2.2.2 requires pygments, which is not installed.",
"pyramid 1.5.2 requires zope.deprecation, which is not installed.",
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 1
@pytest.mark.network
def test_check_broken_dependency(script):
# this will also install a compatible version of jinja2
script.pip('install', 'flask==0.10.1')
@ -47,6 +67,31 @@ def test_check_broken_dependency(script):
result = script.pip('check', expect_error=True)
assert result.stdout == ("Flask 0.10.1 has requirement Jinja2>=2.4, "
"but you have Jinja2 2.3.\n")
expected_lines = (
"Flask 0.10.1 has requirement Jinja2>=2.4, but you have Jinja2 2.3.",
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 1
@pytest.mark.network
def test_check_broken_dependency_and_missing_dependency(script):
# this will also install a compatible version of jinja2
script.pip('install', 'flask==0.10.1')
script.pip('install', 'pyramid==1.5.2')
# deliberately remove a dependency
script.pip('uninstall', 'zope.deprecation', '--yes')
# deliberately change dependency to a version that is too old
script.pip('install', 'jinja2==2.3')
result = script.pip('check', expect_error=True)
expected_lines = (
"pyramid 1.5.2 requires zope.deprecation, which is not installed.",
"Flask 0.10.1 has requirement Jinja2>=2.4, but you have Jinja2 2.3."
)
assert matches_expected_lines(result.stdout, expected_lines)
assert result.returncode == 1