Skip to content

Commit

Permalink
fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocat93 committed Apr 12, 2024
1 parent d56f9c5 commit ae6c0e6
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exclude = [
"node_modules",
"venv"
]
line-length = 100
line-length = 200
indent-width = 4
src = ["src"]
target-version = "py310"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
NAME (str): A class attribute which gives the service a name, used internally.
"""

import os
from typing import Any, Dict

from ...abstract_service import AbstractService
Expand Down
4 changes: 2 additions & 2 deletions src/pipepal/audio/tasks/input_output/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self) -> None:
super().__init__(os.path.dirname(__file__))

@classmethod
def get_service(cls, service_data: Dict[str, Any]) -> Any:
def get_service(cls, service_data: Dict[str, Any]) -> Any: # noqa: ANN401
"""Retrieves or creates a service instance based on the provided service data.
Parameters:
Expand All @@ -45,7 +45,7 @@ def get_service(cls, service_data: Dict[str, Any]) -> Any:

@AbstractComponent.get_response_time
@AbstractComponent.schema_validator
def read_audios_from_disk(self, input: Dict[str, Any]) -> Any:
def read_audios_from_disk(self, input: Dict[str, Any]) -> Dict[str, Any]:
"""Processes input through a workflow.
Parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from typing import Any, Dict

from datasets import Audio, Dataset, load_dataset

from ...abstract_service import AbstractService
Expand Down
2 changes: 1 addition & 1 deletion src/pipepal/utils/abstract_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
def schema_validator(func: Callable) -> Callable:
"""Decorator to validate input and output against schemas."""
@wraps(func)
def wrapper(self: "AbstractComponent", *args: Any, **kwargs: Any) -> Any:
def wrapper(self: "AbstractComponent", *args: Any, **kwargs: Any) -> Any: # noqa: ANN401
input_schema = self.read_json_schema(os.path.join(self.base_dir, self.base_input_schema.replace("__FUNCTION_NAME_PLACEHOLDER__", func.__name__)))
output_schema = self.read_json_schema(os.path.join(self.base_dir, self.base_output_schema.replace("__FUNCTION_NAME_PLACEHOLDER__", func.__name__)))

Expand Down
1 change: 1 addition & 0 deletions src/pipepal/utils/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""This module is for utility functions."""
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
NAME (str): A class attribute which gives the service a name, used internally.
"""

import os
from typing import Any, Dict

from ...abstract_service import AbstractService
Expand Down
10 changes: 9 additions & 1 deletion src/pipepal/video/tasks/input_output/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self) -> None:
super().__init__(os.path.dirname(__file__))

@classmethod
def get_service(cls, service_data: Dict[str, Any]) -> Any:
def get_service(cls, service_data: Dict[str, Any]) -> Any: # noqa: ANN401
"""Retrieves or creates a service instance based on the provided service data.
Parameters:
Expand All @@ -46,6 +46,14 @@ def get_service(cls, service_data: Dict[str, Any]) -> Any:
@AbstractComponent.get_response_time
@AbstractComponent.schema_validator
def extract_audios_from_videos(self, input_obj: Dict[str, Any]) -> Dict[str, Any]:
"""Extracts audios from videos using the specified service and input data.
Args:
input_obj (Dict[str, Any]): The input object containing the service and data.
Returns:
Dict[str, Any]: The output from the service after extracting audios from videos.
"""
service = self.get_service(input_obj["service"])
output = service.extract_audios_from_videos(input_obj["data"])
return output
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Dict, List

import ffmpeg

from ...abstract_service import AbstractService


Expand Down
7 changes: 4 additions & 3 deletions src/tests/test_audio_exampletask_exampleservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from pipepal.audio.tasks import ExampleTask

def test_exampletask_run():

def test_exampletask_run() -> None:
"""Test the run method of ExampleTask.
This test verifies:
Expand All @@ -27,11 +28,11 @@ def test_exampletask_run():
})

# Assert conditions about the output
assert type(output) == dict, "Output should be a dictionary"
assert type(output) == dict, "Output should be a dictionary" # noqa: E721
expected_output_output = "ExampleService output"
assert output['output'] == expected_output_output, "The output of the run method does not match the expected output"

def test_exampletask_run_missing_service_fields():
def test_exampletask_run_missing_service_fields() -> None:
"""Test the run method of ExampleTask.
This test checks for its handling of missing required service fields.
Expand Down
15 changes: 7 additions & 8 deletions src/tests/test_audio_iotask_datasets.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""This module tests the audio's IOTask class."""

import shutil

import pytest
from datasets import Dataset

from pipepal.audio.tasks import IOTask as AudioIOTask


def test_read_audios_from_disk_input_errors():
def test_read_audios_from_disk_input_errors() -> None:
"""Test the read_audios_from_disk method.
This test checks if the read_audios_from_disk method raises appropriate errors for invalid inputs.
Expand Down Expand Up @@ -43,7 +42,7 @@ def test_read_audios_from_disk_input_errors():
}
})

def test_read_audios_from_disk_output_type():
def test_read_audios_from_disk_output_type() -> None:
"""Test the read_audios_from_disk method to check if the output is of type HF datasets."""
test_input = {
"data": {
Expand All @@ -56,7 +55,7 @@ def test_read_audios_from_disk_output_type():
response = AudioIOTask().read_audios_from_disk(test_input)
assert isinstance(response["output"], Dataset), "The output should be an instance of HF_datasets."

def test_read_audios_from_disk_output_dimensions():
def test_read_audios_from_disk_output_dimensions() -> None:
"""Test the read_audios_from_disk method.
This test checks if the dimensions of the output HF datasets object match the input list of audio files.
Expand All @@ -74,7 +73,7 @@ def test_read_audios_from_disk_output_dimensions():
assert len(response["output"]) == len(test_input["data"]["files"]), "The number of items in the output should match the number of input files."


def test_save_HF_dataset_to_disk():
def test_save_HF_dataset_to_disk() -> None:
"""Test the `save_HF_dataset_to_disk` method for successful execution with valid inputs.
This test ensures that when given a correctly formatted input dictionary that includes
Expand Down Expand Up @@ -111,7 +110,7 @@ def test_save_HF_dataset_to_disk():
# shutil.rmtree("../../data_for_testing/output_dataset")


def test_upload_HF_dataset_to_HF_hub():
def test_upload_HF_dataset_to_HF_hub() -> None:
"""Test the `upload_HF_dataset_to_HF_hub` method for successful execution with valid inputs.
This test checks that the `upload_HF_dataset_to_HF_hub` method does not produce any
Expand Down Expand Up @@ -150,7 +149,7 @@ def test_upload_HF_dataset_to_HF_hub():
pytest.fail(f"Function raised an exception with valid input: {e}")


def test_read_local_HF_dataset():
def test_read_local_HF_dataset() -> None:
"""Test the `read_local_HF_dataset` method for successful loading with valid local path input.
This test ensures that the `read_local_HF_dataset` method can correctly load a dataset from
Expand All @@ -176,7 +175,7 @@ def test_read_local_HF_dataset():
except Exception as e:
pytest.fail(f"Function raised an exception with valid input: {e}")

def test_read_HF_dataset_from_HF_hub():
def test_read_HF_dataset_from_HF_hub() -> None:
"""Test the `read_HF_dataset_from_HF_hub` method for successful loading with valid URI input.
This test checks that the `read_HF_dataset_from_HF_hub` method can correctly load a dataset from
Expand Down
7 changes: 4 additions & 3 deletions src/tests/test_video_exampletask_exampleservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from pipepal.video.tasks import ExampleTask

def test_exampletask_run():

def test_exampletask_run() -> None:
"""Test the run method of ExampleTask.
This test verifies:
Expand All @@ -27,11 +28,11 @@ def test_exampletask_run():
})

# Assert conditions about the output
assert type(output) == dict, "Output should be a dictionary"
assert type(output) == dict, "Output should be a dictionary" # noqa: E721
expected_output_output = "ExampleService output"
assert output['output'] == expected_output_output, "The output of the run method does not match the expected output"

def test_exampletask_run_missing_service_fields():
def test_exampletask_run_missing_service_fields() -> None:
"""Test the run method of ExampleTask.
This test checks for its handling of missing required service fields.
Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_video_iotask_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pipepal.video.tasks import IOTask as VideoIOTask


def test_extract_audios_from_videos_input_errors():
def test_extract_audios_from_videos_input_errors() -> None:
"""Test the extract_audios_from_videos method.
This test checks if the extract_audios_from_videos method raises appropriate errors for invalid inputs.
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_extract_audios_from_videos_input_errors():
}
})

def test_extract_audios_from_videos_output_type():
def test_extract_audios_from_videos_output_type() -> None:
"""Test the extract_audios_from_videos method to check if the output is of type list of strings."""
test_input = {
"data": {
Expand All @@ -69,7 +69,7 @@ def test_extract_audios_from_videos_output_type():
for audio_file in response["output"]:
os.remove(audio_file)

def test_read_audios_from_disk_output_dimensions():
def test_read_audios_from_disk_output_dimensions() -> None:
"""Test the read_audios_from_disk method.
This test checks if the dimensions of the output list of audio files match the input list of video files.
Expand Down

0 comments on commit ae6c0e6

Please sign in to comment.