From 1d6f199105767f291384ea752fb49f9b7b9de91f Mon Sep 17 00:00:00 2001 From: Laura Couto Date: Mon, 2 Dec 2024 13:54:05 -0300 Subject: [PATCH] Update example tests Signed-off-by: Laura Couto --- .../tests/test_run.py | 46 +++++++++++++++--- .../tests/test_run.py | 47 ++++++++++++++++--- .../tests/test_run.py | 46 +++++++++++++++--- .../tests/test_run.py | 46 +++++++++++++++--- .../tests/test_run.py | 46 +++++++++++++++--- .../tests/test_run.py | 47 ++++++++++++++++--- 6 files changed, 241 insertions(+), 37 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..3401368c 100644 --- a/astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -11,27 +11,61 @@ from kedro.config import OmegaConfigLoader from kedro.framework.context import KedroContext from kedro.framework.hooks import _create_hook_manager +from kedro.io import DataCatalog @pytest.fixture def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) + return OmegaConfigLoader( + conf_source=str(Path.cwd() / "conf"), + base_env="base", + default_run_env="local" + ) @pytest.fixture -def project_context(config_loader): +def hook_manager(): + return _create_hook_manager() + + +@pytest.fixture +def kedro_context(config_loader, hook_manager): return KedroContext( package_name="{{ cookiecutter.python_package }}", project_path=Path.cwd(), env="local", config_loader=config_loader, - hook_manager=_create_hook_manager(), + hook_manager=hook_manager, ) # 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 TestConfigLoader: + def test_config_loader(self, config_loader): + # Test if the config loader is correctly utilizing the files in the conf directory + assert str(config_loader.conf_source) == str(Path.cwd() / "conf") + assert config_loader.base_env == "base" + assert config_loader.default_run_env == "local" + + def test_load_base_parameters(self, config_loader): + # Test if parameters.yml is being loaded, file is expected to be empty + base_params = config_loader.get("parameters", "base") + assert base_params == {} + + +class TestKedroContext: + def test_data_catalog(self, kedro_context): + # Test if the data catalog is properly loaded within the KedroContext + catalog = kedro_context.catalog + assert isinstance(catalog, DataCatalog) + + # Parameters should be loaded into the catalog + parameters = catalog.load("parameters") + assert isinstance(parameters, dict) + + def test_project_path(self, kedro_context): + # Test if the correct project path is set in the KedroContext + assert kedro_context.project_path == Path.cwd() diff --git a/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py b/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py index d1de7c3f..3401368c 100644 --- a/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -5,34 +5,67 @@ project's structure, and in files named test_*.py. They are simply functions named ``test_*`` which test a unit of logic. """ - 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 +from kedro.io import DataCatalog @pytest.fixture def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) + return OmegaConfigLoader( + conf_source=str(Path.cwd() / "conf"), + base_env="base", + default_run_env="local" + ) + + +@pytest.fixture +def hook_manager(): + return _create_hook_manager() @pytest.fixture -def project_context(config_loader): +def kedro_context(config_loader, hook_manager): return KedroContext( package_name="{{ cookiecutter.python_package }}", project_path=Path.cwd(), env="local", config_loader=config_loader, - hook_manager=_create_hook_manager(), + hook_manager=hook_manager, ) # 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 TestConfigLoader: + def test_config_loader(self, config_loader): + # Test if the config loader is correctly utilizing the files in the conf directory + assert str(config_loader.conf_source) == str(Path.cwd() / "conf") + assert config_loader.base_env == "base" + assert config_loader.default_run_env == "local" + + def test_load_base_parameters(self, config_loader): + # Test if parameters.yml is being loaded, file is expected to be empty + base_params = config_loader.get("parameters", "base") + assert base_params == {} + + +class TestKedroContext: + def test_data_catalog(self, kedro_context): + # Test if the data catalog is properly loaded within the KedroContext + catalog = kedro_context.catalog + assert isinstance(catalog, DataCatalog) + + # Parameters should be loaded into the catalog + parameters = catalog.load("parameters") + assert isinstance(parameters, dict) + + def test_project_path(self, kedro_context): + # Test if the correct project path is set in the KedroContext + assert kedro_context.project_path == Path.cwd() 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..3401368c 100644 --- a/spaceflights-pandas-viz/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pandas-viz/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -11,27 +11,61 @@ from kedro.config import OmegaConfigLoader from kedro.framework.context import KedroContext from kedro.framework.hooks import _create_hook_manager +from kedro.io import DataCatalog @pytest.fixture def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) + return OmegaConfigLoader( + conf_source=str(Path.cwd() / "conf"), + base_env="base", + default_run_env="local" + ) @pytest.fixture -def project_context(config_loader): +def hook_manager(): + return _create_hook_manager() + + +@pytest.fixture +def kedro_context(config_loader, hook_manager): return KedroContext( package_name="{{ cookiecutter.python_package }}", project_path=Path.cwd(), env="local", config_loader=config_loader, - hook_manager=_create_hook_manager(), + hook_manager=hook_manager, ) # 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 TestConfigLoader: + def test_config_loader(self, config_loader): + # Test if the config loader is correctly utilizing the files in the conf directory + assert str(config_loader.conf_source) == str(Path.cwd() / "conf") + assert config_loader.base_env == "base" + assert config_loader.default_run_env == "local" + + def test_load_base_parameters(self, config_loader): + # Test if parameters.yml is being loaded, file is expected to be empty + base_params = config_loader.get("parameters", "base") + assert base_params == {} + + +class TestKedroContext: + def test_data_catalog(self, kedro_context): + # Test if the data catalog is properly loaded within the KedroContext + catalog = kedro_context.catalog + assert isinstance(catalog, DataCatalog) + + # Parameters should be loaded into the catalog + parameters = catalog.load("parameters") + assert isinstance(parameters, dict) + + def test_project_path(self, kedro_context): + # Test if the correct project path is set in the KedroContext + assert kedro_context.project_path == Path.cwd() diff --git a/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py b/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..3401368c 100644 --- a/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -11,27 +11,61 @@ from kedro.config import OmegaConfigLoader from kedro.framework.context import KedroContext from kedro.framework.hooks import _create_hook_manager +from kedro.io import DataCatalog @pytest.fixture def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) + return OmegaConfigLoader( + conf_source=str(Path.cwd() / "conf"), + base_env="base", + default_run_env="local" + ) @pytest.fixture -def project_context(config_loader): +def hook_manager(): + return _create_hook_manager() + + +@pytest.fixture +def kedro_context(config_loader, hook_manager): return KedroContext( package_name="{{ cookiecutter.python_package }}", project_path=Path.cwd(), env="local", config_loader=config_loader, - hook_manager=_create_hook_manager(), + hook_manager=hook_manager, ) # 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 TestConfigLoader: + def test_config_loader(self, config_loader): + # Test if the config loader is correctly utilizing the files in the conf directory + assert str(config_loader.conf_source) == str(Path.cwd() / "conf") + assert config_loader.base_env == "base" + assert config_loader.default_run_env == "local" + + def test_load_base_parameters(self, config_loader): + # Test if parameters.yml is being loaded, file is expected to be empty + base_params = config_loader.get("parameters", "base") + assert base_params == {} + + +class TestKedroContext: + def test_data_catalog(self, kedro_context): + # Test if the data catalog is properly loaded within the KedroContext + catalog = kedro_context.catalog + assert isinstance(catalog, DataCatalog) + + # Parameters should be loaded into the catalog + parameters = catalog.load("parameters") + assert isinstance(parameters, dict) + + def test_project_path(self, kedro_context): + # Test if the correct project path is set in the KedroContext + assert kedro_context.project_path == Path.cwd() 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..3401368c 100644 --- a/spaceflights-pyspark-viz/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pyspark-viz/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -11,27 +11,61 @@ from kedro.config import OmegaConfigLoader from kedro.framework.context import KedroContext from kedro.framework.hooks import _create_hook_manager +from kedro.io import DataCatalog @pytest.fixture def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) + return OmegaConfigLoader( + conf_source=str(Path.cwd() / "conf"), + base_env="base", + default_run_env="local" + ) @pytest.fixture -def project_context(config_loader): +def hook_manager(): + return _create_hook_manager() + + +@pytest.fixture +def kedro_context(config_loader, hook_manager): return KedroContext( package_name="{{ cookiecutter.python_package }}", project_path=Path.cwd(), env="local", config_loader=config_loader, - hook_manager=_create_hook_manager(), + hook_manager=hook_manager, ) # 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 TestConfigLoader: + def test_config_loader(self, config_loader): + # Test if the config loader is correctly utilizing the files in the conf directory + assert str(config_loader.conf_source) == str(Path.cwd() / "conf") + assert config_loader.base_env == "base" + assert config_loader.default_run_env == "local" + + def test_load_base_parameters(self, config_loader): + # Test if parameters.yml is being loaded, file is expected to be empty + base_params = config_loader.get("parameters", "base") + assert base_params == {} + + +class TestKedroContext: + def test_data_catalog(self, kedro_context): + # Test if the data catalog is properly loaded within the KedroContext + catalog = kedro_context.catalog + assert isinstance(catalog, DataCatalog) + + # Parameters should be loaded into the catalog + parameters = catalog.load("parameters") + assert isinstance(parameters, dict) + + def test_project_path(self, kedro_context): + # Test if the correct project path is set in the KedroContext + assert kedro_context.project_path == Path.cwd() diff --git a/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py b/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py index a8d54125..617b7564 100644 --- a/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py +++ b/spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py @@ -11,27 +11,62 @@ from kedro.config import OmegaConfigLoader from kedro.framework.context import KedroContext from kedro.framework.hooks import _create_hook_manager +from kedro.io import DataCatalog @pytest.fixture def config_loader(): - return OmegaConfigLoader(conf_source=str(Path.cwd())) + return OmegaConfigLoader( + conf_source=str(Path.cwd() / "conf"), + base_env="base", + default_run_env="local" + ) + + +@pytest.fixture +def hook_manager(): + return _create_hook_manager() @pytest.fixture -def project_context(config_loader): +def kedro_context(config_loader, hook_manager): return KedroContext( package_name="{{ cookiecutter.python_package }}", project_path=Path.cwd(), env="local", config_loader=config_loader, - hook_manager=_create_hook_manager(), + hook_manager=hook_manager, ) # 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 TestConfigLoader: + def test_config_loader(self, config_loader): + # Test if the config loader is correctly utilizing the files in the conf directory + assert str(config_loader.conf_source) == str(Path.cwd() / "conf") + assert config_loader.base_env == "base" + assert config_loader.default_run_env == "local" + + def test_load_base_parameters(self, config_loader): + # Test if parameters.yml is being loaded, file is expected to be empty + base_params = config_loader.get("parameters", "base") + assert base_params == {} + + +class TestKedroContext: + def test_data_catalog(self, kedro_context): + # Test if the data catalog is properly loaded within the KedroContext + catalog = kedro_context.catalog + assert isinstance(catalog, DataCatalog) + + # Parameters should be loaded into the catalog + parameters = catalog.load("parameters") + assert isinstance(parameters, dict) + + def test_project_path(self, kedro_context): + # Test if the correct project path is set in the KedroContext + assert kedro_context.project_path == Path.cwd() +