Skip to content

Commit

Permalink
fixing tests and HF_login
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocat93 committed Apr 12, 2024
1 parent ae6c0e6 commit d2ef1e9
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
shell: bash
- name: Run unit tests
id: run-tests
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: >
poetry run pytest \
--junitxml=pytest.xml \
Expand Down
2 changes: 1 addition & 1 deletion src/pipepal/audio/tasks/input_output/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_service(cls, service_data: Dict[str, Any]) -> Any: # noqa: ANN401
ValueError: If the service name is unsupported.
"""
# Use a composite key to uniquely identify instances
key: str = cls.get_data_uuid(service_data)
key: str = str(cls.get_data_uuid(service_data))

if key not in cls._instances:
if service_data["service_name"] == DatasetsService.NAME:
Expand Down
2 changes: 1 addition & 1 deletion src/pipepal/video/tasks/input_output/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_service(cls, service_data: Dict[str, Any]) -> Any: # noqa: ANN401
ValueError: If the service name is unsupported.
"""
# Use a composite key to uniquely identify instances
key: str = cls.get_data_uuid(service_data)
key: str = str(cls.get_data_uuid(service_data))

if key not in cls._instances:
if service_data["service_name"] == FfmpegService.NAME:
Expand Down
File renamed without changes.
16 changes: 9 additions & 7 deletions src/tests/test_audio_iotask_datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""This module tests the audio's IOTask class."""


from typing import Any, Dict, List

import pytest
from datasets import Dataset

Expand Down Expand Up @@ -46,7 +48,7 @@ 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": {
"files": ["../../data_for_testing/audio_48khz_mono_16bits.wav", "../../data_for_testing/audio_48khz_stereo_16bits.wav"]
"files": ["./data_for_testing/audio_48khz_mono_16bits.wav", "./data_for_testing/audio_48khz_stereo_16bits.wav"]
},
"service": {
"service_name": "Datasets"
Expand All @@ -61,15 +63,15 @@ def test_read_audios_from_disk_output_dimensions() -> None:
This test checks if the dimensions of the output HF datasets object match the input list of audio files.
Uses mocker to patch the DatasetsService to avoid actual file I/O and simulate reading files.
"""
test_input = {
test_input: Dict[str, Any] = {
"data": {
"files": ["../../data_for_testing/audio_48khz_mono_16bits.wav", "../../data_for_testing/audio_48khz_stereo_16bits.wav"]
"files": ["./data_for_testing/audio_48khz_mono_16bits.wav", "./data_for_testing/audio_48khz_stereo_16bits.wav"]
},
"service": {
"service_name": "Datasets"
}
}
response = AudioIOTask().read_audios_from_disk(test_input)
response: Dict[str, List[str]] = AudioIOTask().read_audios_from_disk(test_input)
assert len(response["output"]) == len(test_input["data"]["files"]), "The number of items in the output should match the number of input files."


Expand Down Expand Up @@ -97,7 +99,7 @@ def test_save_HF_dataset_to_disk() -> None:
},
"data": {
"dataset": Dataset.from_dict({"pokemon": ["bulbasaur", "squirtle"], "type": ["grass", "water"]}),
"output_path": "../../data_for_testing/output_dataset"
"output_path": "./data_for_testing/output_dataset"
}
}

Expand All @@ -107,7 +109,7 @@ def test_save_HF_dataset_to_disk() -> None:
except Exception as e:
pytest.fail(f"Function raised an exception with valid input: {e}")

# shutil.rmtree("../../data_for_testing/output_dataset")
# shutil.rmtree("./data_for_testing/output_dataset")


def test_upload_HF_dataset_to_HF_hub() -> None:
Expand Down Expand Up @@ -163,7 +165,7 @@ def test_read_local_HF_dataset() -> None:
"service_name": "Datasets"
},
"data": {
"path": '../../data_for_testing/output_dataset'
"path": './data_for_testing/output_dataset'
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/tests/test_video_iotask_datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module tests the video's IOTask class."""

import os
from typing import Any, Dict, List

import pytest

Expand Down Expand Up @@ -39,7 +40,7 @@ def test_extract_audios_from_videos_input_errors() -> None:
VideoIOTask().extract_audios_from_videos({
"data": {
"files": ["/non/existent/path/file1.mp4"],
"output_folder": "../../data_for_testing",
"output_folder": "./data_for_testing",
"audio_format": "wav",
"audio_codec": "pcm_s16le"
},
Expand All @@ -52,8 +53,8 @@ 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": {
"files": ["../../data_for_testing/video_48khz_stereo_16bits.mp4"],
"output_folder": "../../data_for_testing",
"files": ["./data_for_testing/video_48khz_stereo_16bits.mp4"],
"output_folder": "./data_for_testing",
"audio_format": "wav",
"audio_codec": "pcm_s16le"
},
Expand All @@ -74,18 +75,18 @@ def test_read_audios_from_disk_output_dimensions() -> None:
This test checks if the dimensions of the output list of audio files match the input list of video files.
"""
test_input = {
test_input: Dict[str, Any] = {
"data": {
"files": ["../../data_for_testing/video_48khz_stereo_16bits.mp4"],
"output_folder": "../../data_for_testing",
"files": ["./data_for_testing/video_48khz_stereo_16bits.mp4"],
"output_folder": "./data_for_testing",
"audio_format": "wav",
"audio_codec": "pcm_s16le"
},
"service": {
"service_name": "ffmpeg"
}
}
response = VideoIOTask().extract_audios_from_videos(test_input)
response: Dict[str, List[str]] = VideoIOTask().extract_audios_from_videos(test_input)
assert len(response["output"]) == len(test_input["data"]["files"]), "The number of items in the output should match the number of input files."

# Clean up
Expand Down

0 comments on commit d2ef1e9

Please sign in to comment.