Skip to content

Commit

Permalink
✅ Update tests with new kedro template to make them pass (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Galileo-Galilei committed Nov 21, 2023
1 parent fb9e5cb commit b146f13
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion tests/config/test_get_mlflow_config.py
Expand Up @@ -178,9 +178,9 @@ def fake_project(tmp_path, local_logging_config):
payload = {
"tool": {
"kedro": {
"project_version": kedro_version,
"project_name": "fake_project",
"package_name": "fake_package",
"kedro_init_version": kedro_version,
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/conftest.py
Expand Up @@ -53,27 +53,27 @@ def cleanup_mlflow_after_runs():
def kedro_project(tmp_path):
# TODO : this is also an integration test since this depends from the kedro version
config = {
"output_dir": tmp_path,
# "output_dir": tmp_path,
"project_name": _FAKE_PROJECT_NAME,
"repo_name": _FAKE_PROJECT_NAME,
"python_package": _FAKE_PROJECT_NAME,
"kedro_version": kedro_version,
"project_name": "This is a fake project",
"repo_name": "fake-project",
"python_package": "fake_project",
"include_example": True,
"add_ons": "none",
}

cookiecutter(
str(TEMPLATE_PATH),
output_dir=config["output_dir"],
output_dir=tmp_path, # config["output_dir"],
no_input=True,
extra_context=config,
accept_hooks=False,
)

shutil.rmtree(
tmp_path / "fake-project" / "src" / "tests"
tmp_path / _FAKE_PROJECT_NAME / "tests"
) # avoid conflicts with pytest

return tmp_path / "fake-project"
return tmp_path / _FAKE_PROJECT_NAME


@pytest.fixture
Expand Down
48 changes: 23 additions & 25 deletions tests/framework/cli/test_cli.py
@@ -1,14 +1,10 @@
import re
import shutil
import subprocess # noqa: F401

import pytest
import yaml
from click.testing import CliRunner
from cookiecutter.main import cookiecutter
from kedro import __version__ as kedro_version
from kedro.framework.cli.cli import info
from kedro.framework.cli.starters import TEMPLATE_PATH
from kedro.framework.project import _ProjectSettings
from kedro.framework.session import KedroSession
from kedro.framework.startup import bootstrap_project
Expand Down Expand Up @@ -253,41 +249,43 @@ def test_ui_overwrite_conf_at_runtime(
)


def test_ui_open_http_uri(monkeypatch, mocker, tmp_path):
config = {
"output_dir": tmp_path,
"kedro_version": kedro_version,
"project_name": "This is a fake project",
"repo_name": "fake-project-with-http-uri",
"python_package": "fake_project_with_http_uri",
"include_example": True,
}

cookiecutter(
str(TEMPLATE_PATH),
output_dir=config["output_dir"],
no_input=True,
extra_context=config,
accept_hooks=False,
)
def test_ui_open_http_uri(monkeypatch, mocker, kedro_project):
# config = {
# "output_dir": tmp_path,
# "kedro_version": kedro_version,
# "project_name": "This is a fake project",
# "repo_name": "fake-project-with-http-uri",
# "python_package": "fake_project_with_http_uri",
# "include_example": True,
# }

# cookiecutter(
# str(TEMPLATE_PATH),
# output_dir=config["output_dir"],
# no_input=True,
# extra_context=config,
# accept_hooks=False,
# )

project_path = tmp_path / config["repo_name"]
shutil.rmtree(project_path / "src" / "tests") # avoid conflicts with pytest
# project_path = tmp_path / config["repo_name"]
# shutil.rmtree(project_path / "src" / "tests") # avoid conflicts with pytest

mlflow_config = KedroMlflowConfig(
server=dict(mlflow_tracking_uri="http://google.com")
)

with open(
(project_path / "conf" / "local" / "mlflow.yml").as_posix(), "w"
# (project_path / "conf" / "local" / "mlflow.yml").as_posix(), "w"
(kedro_project / "conf" / "local" / "mlflow.yml").as_posix(),
"w",
) as fhandler:
yaml.dump(
mlflow_config.dict(),
fhandler,
default_flow_style=False,
)

monkeypatch.chdir(project_path.as_posix())
monkeypatch.chdir(kedro_project.as_posix())
cli_runner = CliRunner()

# This does not test anything : the goal is to check whether it raises an error
Expand Down
35 changes: 20 additions & 15 deletions tests/framework/cli/test_cli_modelify.py
Expand Up @@ -27,24 +27,26 @@ def kp_for_modelify(tmp_path):
# TODO: find a better way to inject dynamically
# the templated config loader without modifying the template

_FAKE_MODELIFY_PROJECT_NAME = r"kp_for_modelify"
config = {
"output_dir": tmp_path,
# "output_dir": tmp_path,
"project_name": _FAKE_MODELIFY_PROJECT_NAME,
"repo_name": _FAKE_MODELIFY_PROJECT_NAME,
"python_package": _FAKE_MODELIFY_PROJECT_NAME,
"kedro_version": kedro_version,
"project_name": "A kedro project with a pipeline for modelify command",
"repo_name": "kp-for-modelify", # "kp" for "kedro_project"
"python_package": "kp_for_modelify",
"add_ons": "none",
}

cookiecutter(
str(TEMPLATE_PATH),
output_dir=config["output_dir"],
output_dir=tmp_path, # config["output_dir"],
no_input=True,
extra_context=config,
accept_hooks=False,
)

shutil.rmtree(
tmp_path / config["repo_name"] / "src" / "tests"
tmp_path / _FAKE_MODELIFY_PROJECT_NAME / "tests"
) # avoid conflicts with pytest

pipeline_registry_py = """
Expand Down Expand Up @@ -74,7 +76,7 @@ def register_pipelines():
"""

model_filepath = (
config["output_dir"] / config["repo_name"] / "data" / "my_model.pkl"
tmp_path / config["repo_name"] / "data" / "my_model.pkl"
).as_posix()

catalog_yml = f"""
Expand Down Expand Up @@ -131,24 +133,26 @@ def kp_for_modelify_with_parameters(tmp_path):
# TODO: find a better way to inject dynamically
# the templated config loader without modifying the template

_FAKE_MODELIFY_PROJECT_NAME = r"kp_for_modelify_with_params"
config = {
"output_dir": tmp_path,
# "output_dir": tmp_path,
"project_name": _FAKE_MODELIFY_PROJECT_NAME,
"repo_name": _FAKE_MODELIFY_PROJECT_NAME,
"python_package": _FAKE_MODELIFY_PROJECT_NAME,
"kedro_version": kedro_version,
"project_name": "A kedro project with a pipeline for modelify command",
"repo_name": "kp-for-modelify-params", # "kp" for "kedro_project"
"python_package": "kp_for_modelify_params",
"add_ons": "none",
}

cookiecutter(
str(TEMPLATE_PATH),
output_dir=config["output_dir"],
output_dir=tmp_path, # config["output_dir"],
no_input=True,
extra_context=config,
accept_hooks=False,
)

shutil.rmtree(
tmp_path / config["repo_name"] / "src" / "tests"
tmp_path / _FAKE_MODELIFY_PROJECT_NAME / "tests"
) # avoid conflicts with pytest

pipeline_registry_py = """
Expand Down Expand Up @@ -179,7 +183,7 @@ def register_pipelines():
"""

model_filepath = (
config["output_dir"] / config["repo_name"] / "data" / "my_model.pkl"
tmp_path / config["repo_name"] / "data" / "my_model.pkl"
).as_posix()

catalog_yml = f"""
Expand Down Expand Up @@ -467,6 +471,7 @@ def test_modelify_with_pip_requirements(monkeypatch, kp_for_modelify):
runs_list_before_cmd = context.mlflow.server._mlflow_client.search_runs(
context.mlflow.tracking.experiment._experiment.experiment_id
)
print(runs_list_before_cmd)
cli_runner = CliRunner()

result = cli_runner.invoke(
Expand All @@ -477,7 +482,7 @@ def test_modelify_with_pip_requirements(monkeypatch, kp_for_modelify):
"--input-name",
"my_input_data",
"--pip-requirements",
"./src/requirements.txt",
"./requirements.txt",
],
catch_exceptions=True,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/framework/hooks/test_hook_deactivate_tracking.py
Expand Up @@ -5,7 +5,7 @@
import toml
import yaml
from kedro import __version__ as kedro_version
from kedro.config import ConfigLoader
from kedro.config import AbstractConfigLoader, OmegaConfigLoader
from kedro.framework.hooks import hook_impl
from kedro.framework.project import (
Validator,
Expand Down Expand Up @@ -126,8 +126,8 @@ def config_dir(

class DummyProjectHooks:
@hook_impl
def register_config_loader(self, conf_paths: Iterable[str]) -> ConfigLoader:
return ConfigLoader(conf_paths)
def register_config_loader(self, conf_paths: Iterable[str]) -> AbstractConfigLoader:
return OmegaConfigLoader(conf_paths)

@hook_impl
def register_catalog(
Expand Down
6 changes: 3 additions & 3 deletions tests/framework/hooks/test_hook_on_pipeline_error.py
Expand Up @@ -2,7 +2,7 @@

import mlflow
import pytest
from kedro.config import ConfigLoader
from kedro.config import AbstractConfigLoader, OmegaConfigLoader
from kedro.framework.hooks import hook_impl
from kedro.framework.project import Validator, _ProjectPipelines, _ProjectSettings
from kedro.framework.session import KedroSession
Expand All @@ -17,8 +17,8 @@

class DummyProjectHooks:
@hook_impl
def register_config_loader(self, conf_paths: Iterable[str]) -> ConfigLoader:
return ConfigLoader(conf_paths)
def register_config_loader(self, conf_paths: Iterable[str]) -> AbstractConfigLoader:
return OmegaConfigLoader(conf_paths)

@hook_impl
def register_catalog(
Expand Down

0 comments on commit b146f13

Please sign in to comment.