Skip to content

Commit

Permalink
Update example tests
Browse files Browse the repository at this point in the history
Signed-off-by: Laura Couto <[email protected]>
  • Loading branch information
lrcouto committed Dec 2, 2024
1 parent a94a86d commit 1d6f199
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 37 deletions.
46 changes: 40 additions & 6 deletions astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
47 changes: 40 additions & 7 deletions databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
46 changes: 40 additions & 6 deletions spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading

0 comments on commit 1d6f199

Please sign in to comment.