From ae6c0e6b95b138ec6b3ec75167097e3055fcbec3 Mon Sep 17 00:00:00 2001 From: fabiocat93 Date: Fri, 12 Apr 2024 12:38:27 -0400 Subject: [PATCH] fixing unit tests --- pyproject.toml | 2 +- .../services/example_service/service.py | 1 - src/pipepal/audio/tasks/input_output/interface.py | 4 ++-- .../input_output/services/datasets/service.py | 1 + src/pipepal/utils/abstract_component.py | 2 +- src/pipepal/utils/functions.py | 1 + .../services/example_service/service.py | 1 - src/pipepal/video/tasks/input_output/interface.py | 10 +++++++++- .../tasks/input_output/services/ffmpeg/service.py | 1 + .../test_audio_exampletask_exampleservice.py | 7 ++++--- src/tests/test_audio_iotask_datasets.py | 15 +++++++-------- .../test_video_exampletask_exampleservice.py | 7 ++++--- src/tests/test_video_iotask_datasets.py | 6 +++--- 13 files changed, 34 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9dc68785..3df7383d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ exclude = [ "node_modules", "venv" ] -line-length = 100 +line-length = 200 indent-width = 4 src = ["src"] target-version = "py310" diff --git a/src/pipepal/audio/tasks/example_task/services/example_service/service.py b/src/pipepal/audio/tasks/example_task/services/example_service/service.py index fbcc61eb..6627c4dc 100644 --- a/src/pipepal/audio/tasks/example_task/services/example_service/service.py +++ b/src/pipepal/audio/tasks/example_task/services/example_service/service.py @@ -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 diff --git a/src/pipepal/audio/tasks/input_output/interface.py b/src/pipepal/audio/tasks/input_output/interface.py index aaef9d1d..e0ed4f05 100644 --- a/src/pipepal/audio/tasks/input_output/interface.py +++ b/src/pipepal/audio/tasks/input_output/interface.py @@ -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: @@ -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: diff --git a/src/pipepal/audio/tasks/input_output/services/datasets/service.py b/src/pipepal/audio/tasks/input_output/services/datasets/service.py index a01e5932..1f5e7d5c 100644 --- a/src/pipepal/audio/tasks/input_output/services/datasets/service.py +++ b/src/pipepal/audio/tasks/input_output/services/datasets/service.py @@ -2,6 +2,7 @@ import os from typing import Any, Dict + from datasets import Audio, Dataset, load_dataset from ...abstract_service import AbstractService diff --git a/src/pipepal/utils/abstract_component.py b/src/pipepal/utils/abstract_component.py index 6c759e87..3be8bf55 100644 --- a/src/pipepal/utils/abstract_component.py +++ b/src/pipepal/utils/abstract_component.py @@ -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__))) diff --git a/src/pipepal/utils/functions.py b/src/pipepal/utils/functions.py index e69de29b..5b6d55cd 100644 --- a/src/pipepal/utils/functions.py +++ b/src/pipepal/utils/functions.py @@ -0,0 +1 @@ +"""This module is for utility functions.""" \ No newline at end of file diff --git a/src/pipepal/video/tasks/example_task/services/example_service/service.py b/src/pipepal/video/tasks/example_task/services/example_service/service.py index fbcc61eb..6627c4dc 100644 --- a/src/pipepal/video/tasks/example_task/services/example_service/service.py +++ b/src/pipepal/video/tasks/example_task/services/example_service/service.py @@ -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 diff --git a/src/pipepal/video/tasks/input_output/interface.py b/src/pipepal/video/tasks/input_output/interface.py index efa18fa4..8943dec8 100644 --- a/src/pipepal/video/tasks/input_output/interface.py +++ b/src/pipepal/video/tasks/input_output/interface.py @@ -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: @@ -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 \ No newline at end of file diff --git a/src/pipepal/video/tasks/input_output/services/ffmpeg/service.py b/src/pipepal/video/tasks/input_output/services/ffmpeg/service.py index b411434a..046142b5 100644 --- a/src/pipepal/video/tasks/input_output/services/ffmpeg/service.py +++ b/src/pipepal/video/tasks/input_output/services/ffmpeg/service.py @@ -4,6 +4,7 @@ from typing import Any, Dict, List import ffmpeg + from ...abstract_service import AbstractService diff --git a/src/tests/test_audio_exampletask_exampleservice.py b/src/tests/test_audio_exampletask_exampleservice.py index f4040471..5c471839 100644 --- a/src/tests/test_audio_exampletask_exampleservice.py +++ b/src/tests/test_audio_exampletask_exampleservice.py @@ -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: @@ -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. diff --git a/src/tests/test_audio_iotask_datasets.py b/src/tests/test_audio_iotask_datasets.py index 16e42787..b333b0ee 100644 --- a/src/tests/test_audio_iotask_datasets.py +++ b/src/tests/test_audio_iotask_datasets.py @@ -1,6 +1,5 @@ """This module tests the audio's IOTask class.""" -import shutil import pytest from datasets import Dataset @@ -8,7 +7,7 @@ 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. @@ -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": { @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/tests/test_video_exampletask_exampleservice.py b/src/tests/test_video_exampletask_exampleservice.py index f41214ad..ff9b0e29 100644 --- a/src/tests/test_video_exampletask_exampleservice.py +++ b/src/tests/test_video_exampletask_exampleservice.py @@ -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: @@ -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. diff --git a/src/tests/test_video_iotask_datasets.py b/src/tests/test_video_iotask_datasets.py index dc1c764e..e4ff768b 100644 --- a/src/tests/test_video_iotask_datasets.py +++ b/src/tests/test_video_iotask_datasets.py @@ -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. @@ -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": { @@ -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.