def defrost(exit_mode, requirement_file, pip_freeze_file): """ Check if the output of pip freeze satisfies the YAML requirement file. The pip freeze output may be passed as stdin: pip freeze | defrost reqs.yml - """ reqs = _parse_yaml(requirement_file) pip_freeze = PipFreeze(pip_freeze_file.read()) pip_freeze.load_requirements(reqs) exit_code = 0 for package in pip_freeze.deprecated: click.echo("{}: {!r} does not satisfy {!r}: {}".format( package.deprecation_severity, package, package.deprecated_by, package.deprecation_reason, ), err=True) if exit_code == 0: exit_code = exit_codes[package.deprecation_severity][exit_mode] sys.exit(exit_code)
def test_pip_freeze__load_requirements(freeze, reqs, expected_deprecated): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) pip_freeze.load_requirements(reqs) assert len(pip_freeze.deprecated) == len(expected_deprecated) for package, (pin, reason, severity) in zip(pip_freeze.deprecated, expected_deprecated): assert package.deprecated is True assert str(package) == pin assert package.deprecation_reason == reason assert package.deprecation_severity == severity
def test_pip_freeze__contains(freeze, package, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert (package in pip_freeze) is expected
def test_pip_freeze__len(freeze, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert len(pip_freeze) == expected
def test_pip_freeze__iter(freeze, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert list(pip_freeze) == expected
def test_pip_freeze__bool(freeze, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert bool(pip_freeze) is expected
def test_pip_freeze__getitems_KeyError(freeze, package): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) pytest.raises(KeyError, pip_freeze.__getitem__, package)
def test_pip_freeze__getitems_found(freeze, package, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert pip_freeze[package] == expected
def test_pip_freeze__get_with_default(freeze, package, default, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert pip_freeze.get(package, default) == expected
def test_pip_freeze__get_without_default(freeze, package, expected): from defrost import PipFreeze pip_freeze = PipFreeze(freeze) assert pip_freeze.get(package) == expected