def test_preserve_req_suffixes(self): # NOTE: the reqs here aren't technically valid themselves due to duplicates verta_reqs_suffixes = [ ";python_version>'2.7' and python_version<3.9 # very important!", ";python_version<='2.7'", " # very important!", ] cloudpickle_reqs_suffixes = [ ";python_version>'2.7' and python_version<3.9 # very important!", ";python_version<='2.7'", "", ] input_verta_reqs = ["verta" + suffix for suffix in verta_reqs_suffixes] input_cloudpickle_reqs = [ "cloudpickle" + suffix for suffix in cloudpickle_reqs_suffixes ] reqs = input_verta_reqs + input_cloudpickle_reqs expected_verta_reqs = [ "verta==" + verta.__version__ + suffix for suffix in verta_reqs_suffixes ] expected_cloudpickle_reqs = [ "cloudpickle==" + cloudpickle.__version__ + suffix for suffix in cloudpickle_reqs_suffixes ] expected_reqs = expected_verta_reqs + expected_cloudpickle_reqs _pip_requirements_utils.pin_verta_and_cloudpickle(reqs) assert reqs == expected_reqs
def test_from_files(self, requirements_file): reqs = Python.read_pip_file(requirements_file.name) env = Python(requirements=reqs) assert env._msg.python.requirements assert not env._msg.python.raw_requirements _pip_requirements_utils.pin_verta_and_cloudpickle(reqs) assert_parsed_reqs_match(env.requirements, reqs)
def test_from_env(self): reqs = Python.read_pip_environment( skip_options=True, ) env = Python(requirements=reqs) assert env._msg.python.requirements assert not env._msg.python.raw_requirements _pip_requirements_utils.pin_verta_and_cloudpickle(reqs) assert_parsed_reqs_match(env.requirements, reqs)
def test_repr(self): requirements = ["pytest=={}".format(pytest.__version__)] constraints = ["six=={}".format(six.__version__)] env_vars = ["HOME"] env = Python( requirements=requirements, constraints=constraints, env_vars=env_vars, ) _pip_requirements_utils.pin_verta_and_cloudpickle(requirements) for line in requirements: assert line in repr(env) for line in constraints: assert line in repr(env) for line in env_vars: assert line in repr(env)
def test_raw_repr(self): requirements = [ "-e git+https://github.com/matplotlib/matplotlib.git@master#egg=matplotlib", ] constraints = ["pytest > 6; python_version >= '2.7'"] env = Python( requirements=requirements, constraints=constraints, ) assert env._msg.python.raw_requirements assert env._msg.python.raw_constraints _pip_requirements_utils.pin_verta_and_cloudpickle(requirements) for line in requirements: assert line in repr(env) for line in constraints: assert line in repr(env)
def test_unsupported_lines( self, requirements_file_with_unsupported_lines, caplog ): """Requirements with unsupported lines get logged raw.""" reqs = Python.read_pip_file(requirements_file_with_unsupported_lines.name) # each line gets logged raw for req in reqs: with caplog.at_level(logging.WARNING, logger="verta"): env = Python(requirements=[req]) assert "failed to manually parse requirements; falling back to capturing raw contents" in caplog.text caplog.clear() assert not env._msg.python.requirements assert env._msg.python.raw_requirements expected_reqs = [req] _pip_requirements_utils.pin_verta_and_cloudpickle(expected_reqs) assert env.requirements == expected_reqs