import os
import re
import testinfra.utils.ansible_runner
@@ -403,3 +404,30 @@ def test_pipreqcheck_virtualenv_wrong_python_version_not_present(host, wrong_pyt
wrong_python_path_file = host.file(wrong_python_path)
assert not wrong_python_path_file.exists
@pytest.mark.parametrize('environment,config_directory', [
('/var/lib/pipreqcheck/virtualenv', '/tmp/pip_check_requirements_upgrades'),
('/var/lib/pipreqcheck/virtualenv-py3', '/tmp/pip_check_requirements_upgrades-py3'),
])
def test_pipreqcheck_script_output(host, environment, config_directory):
"""
Tests if the pip_check_requirements_upgrades.sh script properly
reports available updates or not.
expected_line_count = 9
expected_warning_message = "[WARN] Upgrades available for: %s/with_updates/requirements.txt" % config_directory
expected_package_diff = "@@ -1 +1 @@\n-urllib3==1.24.2\n+urllib3==1.24.3"
with host.sudo("pipreqcheck"):
report = host.run("/usr/local/bin/pip_check_requirements_upgrades.sh -q -V %s %s", environment, config_directory)
# Clean-up the SSH warning from the beginning of stderr if
# present.
stderr = re.sub("^Warning: Permanently added.*?\r\n", "", report.stderr)
assert stderr == ""
assert len(report.stdout.split("\n")) == expected_line_count
assert expected_warning_message in report.stdout
assert expected_package_diff in report.stdout