Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move integration test into examples #756

Merged
merged 24 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: test-${{ matrix.python-version }}

integration-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10' ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install poetry==1.4.0
poetry install --all-extras --with test
mrchtr marked this conversation as resolved.
Show resolved Hide resolved

- name: Execute sample pipeline
run: ./scripts/run_integration_tests.sh

finish-coveralls:
needs: test
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion docs/runners/local.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ about this in the [installation](../guides/installation.md) guide.
fondant run local <pipeline_ref> --auth-azure
```

You can also use the `--extra_volumes` argument to mount extra credentials or additional files.
You can also use the `--extra-volumes` argument to mount extra credentials or additional files.
This volumes will be mounted to every component/service of the docker-compose spec.


Expand Down
13 changes: 13 additions & 0 deletions examples/sample_pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample pipeline

This example is a simple sample pipeline which uses two reusable components
(load_from_parquet, chunk_text), and a custom dummy component. The custom dummy component only
returns the received dataframe.

The pipeline can be executed with the Fondant cli:

```bash
fondant run local pipeline.py
```

The automated integration test will use the `run.sh` script.
13 changes: 13 additions & 0 deletions examples/sample_pipeline/components/dummy_component/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM --platform=linux/amd64 python:3.8-slim

# install requirements
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt

# Set the working directory to the component folder
WORKDIR /component/src

# Copy over src-files and spec of the component
COPY src/ .

ENTRYPOINT ["fondant", "execute", "main"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Dummy component
description: Dummy component for testing custom components

image: fndnt/dummy_component:dev
image: dummy_component

consumes:
text_data:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fondant[component]
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
class DummyComponent(PandasTransformComponent):
"""Dummy component that returns the dataframe as it is."""

def __init__(self, *_):
def __init__(self, *_, **kwargs):
pass

def transform(self, dataframe: pd.DataFrame) -> pd.DataFrame:
"""Dummy component that returns the dataframe as it is."""
# raise RuntimeError
return dataframe
37 changes: 37 additions & 0 deletions examples/sample_pipeline/pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file contains a sample pipeline. Loading data from a parquet file,
# using the load_from_parquet component, chain a custom dummy component, and use
# the reusable chunking component
import pyarrow as pa
from pathlib import Path
from fondant.pipeline import Pipeline

BASE_PATH = Path("./.artifacts").resolve()
BASE_PATH.mkdir(parents=True, exist_ok=True)

# Define pipeline
pipeline = Pipeline(name="dummy-pipeline", base_path=str(BASE_PATH))

# Load from hub component
load_component_column_mapping = {
"text": "text_data",
}

dataset = pipeline.read(
name_or_path="load_from_parquet",
arguments={
"dataset_uri": "/data/sample.parquet",
"column_name_mapping": load_component_column_mapping,
"n_rows_to_load": 5,
},
produces={"text_data": pa.string()},
)

dataset = dataset.apply(
name_or_path="./components/dummy_component",
)

dataset.apply(
name_or_path="chunk_text",
arguments={"chunk_size": 10, "chunk_overlap": 2},
consumes={"text": "text_data"},
)
29 changes: 29 additions & 0 deletions examples/sample_pipeline/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# This script executes the sample pipeline in the example folder, checks the correct execution and
# cleans up the directory again
set -e


# Setup teardown
cleanup() {
rv=$?

# Try to remove .artifact folder
artifact_directory="./.artifacts"

if [ -d "$artifact_directory" ]; then
# Directory exists, remove it
rm -rf "$artifact_directory"
fi

exit $rv
}

trap cleanup EXIT

# Bind local data directory to pipeline
data_dir=$(readlink -f "data")

# Run pipeline
fondant run local pipeline.py \
--extra-volumes $data_dir:/data
34 changes: 34 additions & 0 deletions scripts/run_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# This script executes the sample pipeline in the example folder, checks the correct execution and
# cleans up the directory again
echo "Start integration tests execution ..."

failed_tests=()

# Find all run.sh scripts and execute them
for test_script in ./examples/*/run.sh; do
test_name=$(basename "$(dirname "$test_script")")

echo "Running test: $test_name"

# Set working dir to the currect integration test
cd $(dirname "$test_script")

# Execute the run.sh script
bash ./run.sh

# Check the exit status
if [ $? -ne 0 ]; then
echo "Test $test_name failed!"
failed_tests+=("$test_name")
fi
done

echo "Tests completed"

if [ ${#failed_tests[@]} -eq 0 ]; then
echo "All tests passed!"
else
echo "Failed tests: ${failed_tests[@]}"
exit 1 # Indicate failure to cicd
fi
3 changes: 2 additions & 1 deletion src/fondant/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ def _validate_pipeline_definition(self, run_id: str):
msg = (
f"Component '{component_op.name}' is trying to invoke the field "
f"'{component_field_name}', which has not been defined or created "
f"in the previous components."
f"in the previous components. \n"
f"Available field names: {list(manifest.fields.keys())}"
)
raise InvalidPipelineDefinition(
msg,
Expand Down
2 changes: 1 addition & 1 deletion src/fondant/pipeline/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _run(self, input_spec: str, *args, **kwargs):
]

print("Starting pipeline run...")
subprocess.call(cmd) # nosec
subprocess.check_call(cmd) # nosec
print("Finished pipeline run.")

def run(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

79 changes: 0 additions & 79 deletions tests/integration_tests/test_sample_pipeline.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/pipeline/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def test_docker_runner():
"""Test that the docker runner while mocking subprocess.call."""
with mock.patch("subprocess.call") as mock_call:
with mock.patch("subprocess.check_call") as mock_call:
DockerRunner().run("some/path")
mock_call.assert_called_once_with(
[
Expand All @@ -41,7 +41,7 @@ def test_docker_runner():


def test_docker_runner_from_pipeline():
with mock.patch("subprocess.call") as mock_call:
with mock.patch("subprocess.check_call") as mock_call:
DockerRunner().run(PIPELINE)
mock_call.assert_called_once_with(
[
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_local_run():
extra_volumes=[],
build_arg=[],
)
with patch("subprocess.call") as mock_call:
with patch("subprocess.check_call") as mock_call:
run_local(args)
mock_call.assert_called_once_with(
[
Expand All @@ -290,7 +290,7 @@ def test_local_run():
],
)

with patch("subprocess.call") as mock_call:
with patch("subprocess.check_call") as mock_call:
args1 = argparse.Namespace(
local=True,
vertex=False,
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_local_run_cloud_credentials():
with patch(
"fondant.pipeline.compiler.DockerCompiler.compile",
) as mock_compiler, patch(
"subprocess.call",
"subprocess.check_call",
) as mock_runner:
args = argparse.Namespace(
local=True,
Expand Down