def test_get_pkg_version(self, requirements_file): """Test get_pkg_version(), which extracts package version from the provided requirements file.""" sa_version = "SQLAlchemy>=1.2.0, <2.0" assert get_pkg_version(requirements_file, "SQLAlchemy") == sa_version assert get_pkg_version(requirements_file, "pandas") == "pandas==0.23.0" assert get_pkg_version(requirements_file, "toposort") == "toposort" with raises(KedroCliError): get_pkg_version(requirements_file, "nonexistent") with raises(KedroCliError): non_existent_file = str(requirements_file) + "-nonexistent" get_pkg_version(non_existent_file, "pandas")
def modify_kedro_ver(req_file: Path, version: str) -> str: """ Modify project kedro requirement to deal with invalid kedro version bug when bumping up version. Args: req_file: Path to `requirements.txt` in kedro project. version: Version of kedro to insert into project `requirements.txt`. Returns: Version of kedro in original project `requirements.txt` """ project_reqs = req_file.read_text("utf-8") org_version = get_pkg_version(req_file, "kedro") project_reqs = project_reqs.replace(org_version, version) req_file.write_text(project_reqs) return org_version