From 9b914560bffc0a39d4bd04c9973a1598d168b924 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:50:02 -0300 Subject: [PATCH] Update example tests on kedro-starters templates (#261) * Update example tests Signed-off-by: Laura Couto * Remove unused fixture Signed-off-by: Laura Couto * Base example tests on KedroSession Signed-off-by: Laura Couto * Handle config loader tests through the session Signed-off-by: Laura Couto * Add a little runner test Signed-off-by: Laura Couto * Simplify session.run() test Signed-off-by: Laura Couto --------- Signed-off-by: Laura Couto --- .../tests/test_run.py | 39 +++++------------- .../tests/test_run.py | 40 +++++-------------- .../tests/test_run.py | 39 +++++------------- .../tests/test_run.py | 39 +++++------------- .../tests/test_run.py | 39 +++++------------- .../tests/test_run.py | 39 +++++------------- 6 files changed, 66 insertions(+), 169 deletions(-) diff --git a/astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py b/astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..addd1f9c 100644 --- a/astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -1,37 +1,20 @@ """ -This module contains an example test. - +This module contains example tests for a Kedro project. Tests should be placed in ``src/tests``, in modules that mirror your -project's structure, and in files named test_*.py. They are simply functions -named ``test_*`` which test a unit of logic. +project's structure, and in files named test_*.py. """ from pathlib import Path -import pytest -from kedro.config import OmegaConfigLoader -from kedro.framework.context import KedroContext -from kedro.framework.hooks import _create_hook_manager - - -@pytest.fixture -def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) - - -@pytest.fixture -def project_context(config_loader): - return KedroContext( - package_name="{{ cookiecutter.python_package }}", - project_path=Path.cwd(), - env="local", - config_loader=config_loader, - hook_manager=_create_hook_manager(), - ) - +from kedro.framework.session import KedroSession +from kedro.framework.startup import bootstrap_project # The tests below are here for the demonstration purpose # and should be replaced with the ones testing the project # functionality -class TestProjectContext: - def test_project_path(self, project_context): - assert project_context.project_path == Path.cwd() + +class TestKedroRun: + def test_kedro_run(self): + bootstrap_project(Path.cwd()) + + with KedroSession.create(project_path=Path.cwd()) as session: + assert session.run() is not None diff --git a/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py b/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py index d1de7c3f..addd1f9c 100644 --- a/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -1,38 +1,20 @@ """ -This module contains an example test. - +This module contains example tests for a Kedro project. Tests should be placed in ``src/tests``, in modules that mirror your -project's structure, and in files named test_*.py. They are simply functions -named ``test_*`` which test a unit of logic. +project's structure, and in files named test_*.py. """ - from pathlib import Path -import pytest -from kedro.config import OmegaConfigLoader -from kedro.framework.context import KedroContext -from kedro.framework.hooks import _create_hook_manager - - -@pytest.fixture -def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) - - -@pytest.fixture -def project_context(config_loader): - return KedroContext( - package_name="{{ cookiecutter.python_package }}", - project_path=Path.cwd(), - env="local", - config_loader=config_loader, - hook_manager=_create_hook_manager(), - ) - +from kedro.framework.session import KedroSession +from kedro.framework.startup import bootstrap_project # The tests below are here for the demonstration purpose # and should be replaced with the ones testing the project # functionality -class TestProjectContext: - def test_project_path(self, project_context): - assert project_context.project_path == Path.cwd() + +class TestKedroRun: + def test_kedro_run(self): + bootstrap_project(Path.cwd()) + + with KedroSession.create(project_path=Path.cwd()) as session: + assert session.run() is not None diff --git a/spaceflights-pandas-viz/{{ cookiecutter.repo_name }}/tests/test_run.py b/spaceflights-pandas-viz/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..addd1f9c 100644 --- a/spaceflights-pandas-viz/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pandas-viz/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -1,37 +1,20 @@ """ -This module contains an example test. - +This module contains example tests for a Kedro project. Tests should be placed in ``src/tests``, in modules that mirror your -project's structure, and in files named test_*.py. They are simply functions -named ``test_*`` which test a unit of logic. +project's structure, and in files named test_*.py. """ from pathlib import Path -import pytest -from kedro.config import OmegaConfigLoader -from kedro.framework.context import KedroContext -from kedro.framework.hooks import _create_hook_manager - - -@pytest.fixture -def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) - - -@pytest.fixture -def project_context(config_loader): - return KedroContext( - package_name="{{ cookiecutter.python_package }}", - project_path=Path.cwd(), - env="local", - config_loader=config_loader, - hook_manager=_create_hook_manager(), - ) - +from kedro.framework.session import KedroSession +from kedro.framework.startup import bootstrap_project # The tests below are here for the demonstration purpose # and should be replaced with the ones testing the project # functionality -class TestProjectContext: - def test_project_path(self, project_context): - assert project_context.project_path == Path.cwd() + +class TestKedroRun: + def test_kedro_run(self): + bootstrap_project(Path.cwd()) + + with KedroSession.create(project_path=Path.cwd()) as session: + assert session.run() is not None diff --git a/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py b/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..addd1f9c 100644 --- a/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -1,37 +1,20 @@ """ -This module contains an example test. - +This module contains example tests for a Kedro project. Tests should be placed in ``src/tests``, in modules that mirror your -project's structure, and in files named test_*.py. They are simply functions -named ``test_*`` which test a unit of logic. +project's structure, and in files named test_*.py. """ from pathlib import Path -import pytest -from kedro.config import OmegaConfigLoader -from kedro.framework.context import KedroContext -from kedro.framework.hooks import _create_hook_manager - - -@pytest.fixture -def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) - - -@pytest.fixture -def project_context(config_loader): - return KedroContext( - package_name="{{ cookiecutter.python_package }}", - project_path=Path.cwd(), - env="local", - config_loader=config_loader, - hook_manager=_create_hook_manager(), - ) - +from kedro.framework.session import KedroSession +from kedro.framework.startup import bootstrap_project # The tests below are here for the demonstration purpose # and should be replaced with the ones testing the project # functionality -class TestProjectContext: - def test_project_path(self, project_context): - assert project_context.project_path == Path.cwd() + +class TestKedroRun: + def test_kedro_run(self): + bootstrap_project(Path.cwd()) + + with KedroSession.create(project_path=Path.cwd()) as session: + assert session.run() is not None diff --git a/spaceflights-pyspark-viz/{{ cookiecutter.repo_name }}/tests/test_run.py b/spaceflights-pyspark-viz/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..addd1f9c 100644 --- a/spaceflights-pyspark-viz/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pyspark-viz/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -1,37 +1,20 @@ """ -This module contains an example test. - +This module contains example tests for a Kedro project. Tests should be placed in ``src/tests``, in modules that mirror your -project's structure, and in files named test_*.py. They are simply functions -named ``test_*`` which test a unit of logic. +project's structure, and in files named test_*.py. """ from pathlib import Path -import pytest -from kedro.config import OmegaConfigLoader -from kedro.framework.context import KedroContext -from kedro.framework.hooks import _create_hook_manager - - -@pytest.fixture -def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) - - -@pytest.fixture -def project_context(config_loader): - return KedroContext( - package_name="{{ cookiecutter.python_package }}", - project_path=Path.cwd(), - env="local", - config_loader=config_loader, - hook_manager=_create_hook_manager(), - ) - +from kedro.framework.session import KedroSession +from kedro.framework.startup import bootstrap_project # The tests below are here for the demonstration purpose # and should be replaced with the ones testing the project # functionality -class TestProjectContext: - def test_project_path(self, project_context): - assert project_context.project_path == Path.cwd() + +class TestKedroRun: + def test_kedro_run(self): + bootstrap_project(Path.cwd()) + + with KedroSession.create(project_path=Path.cwd()) as session: + assert session.run() is not None diff --git a/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py b/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..addd1f9c 100644 --- a/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -1,37 +1,20 @@ """ -This module contains an example test. - +This module contains example tests for a Kedro project. Tests should be placed in ``src/tests``, in modules that mirror your -project's structure, and in files named test_*.py. They are simply functions -named ``test_*`` which test a unit of logic. +project's structure, and in files named test_*.py. """ from pathlib import Path -import pytest -from kedro.config import OmegaConfigLoader -from kedro.framework.context import KedroContext -from kedro.framework.hooks import _create_hook_manager - - -@pytest.fixture -def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) - - -@pytest.fixture -def project_context(config_loader): - return KedroContext( - package_name="{{ cookiecutter.python_package }}", - project_path=Path.cwd(), - env="local", - config_loader=config_loader, - hook_manager=_create_hook_manager(), - ) - +from kedro.framework.session import KedroSession +from kedro.framework.startup import bootstrap_project # The tests below are here for the demonstration purpose # and should be replaced with the ones testing the project # functionality -class TestProjectContext: - def test_project_path(self, project_context): - assert project_context.project_path == Path.cwd() + +class TestKedroRun: + def test_kedro_run(self): + bootstrap_project(Path.cwd()) + + with KedroSession.create(project_path=Path.cwd()) as session: + assert session.run() is not None