Skip to content

Commit

Permalink
Update example tests on kedro-starters templates (#261)
Browse files Browse the repository at this point in the history
* Update example tests

Signed-off-by: Laura Couto <[email protected]>

* Remove unused fixture

Signed-off-by: Laura Couto <[email protected]>

* Base example tests on KedroSession

Signed-off-by: Laura Couto <[email protected]>

* Handle config loader tests through the session

Signed-off-by: Laura Couto <[email protected]>

* Add a little runner test

Signed-off-by: Laura Couto <[email protected]>

* Simplify session.run() test

Signed-off-by: Laura Couto <[email protected]>

---------

Signed-off-by: Laura Couto <[email protected]>
  • Loading branch information
lrcouto authored Dec 6, 2024
1 parent a94a86d commit 9b91456
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 169 deletions.
39 changes: 11 additions & 28 deletions astro-airflow-iris/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -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
40 changes: 11 additions & 29 deletions databricks-iris/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
39 changes: 11 additions & 28 deletions spaceflights-pandas/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
39 changes: 11 additions & 28 deletions spaceflights-pyspark/{{ cookiecutter.repo_name }}/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9b91456

Please sign in to comment.