Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanSara committed May 22, 2023
1 parent 0bd0f4b commit c9ac535
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ def samples_path():
return Path(__file__).parent / "samples"


@pytest.fixture
def preview_samples_path():
return Path(__file__).parent / "preview" / "test_files"


@pytest.fixture(autouse=True)
def request_blocker(request: pytest.FixtureRequest, monkeypatch):
"""
Expand Down
33 changes: 17 additions & 16 deletions test/preview/components/audio/test_whisper_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
from test.preview.components.base import BaseTestComponent


SAMPLES_PATH = Path(__file__).parent.parent.parent / "test_files"


class TestRemoteWhisperTranscriber(BaseTestComponent):
"""
Tests for RemoteWhisperTranscriber.
"""

@pytest.fixture
@pytest.mark.unit
def test_save_load(self, tmp_path):
self.assert_can_be_saved_and_loaded_in_pipeline(RemoteWhisperTranscriber(api_key="just a test"), tmp_path)

Expand All @@ -39,7 +36,7 @@ def test_init_no_key(self):
RemoteWhisperTranscriber(api_key=None)

@pytest.mark.unit
def test_run_with_path(self):
def test_run_with_path(self, preview_samples_path):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
Expand All @@ -50,20 +47,20 @@ def test_run_with_path(self):

result = comp.run(
RemoteWhisperTranscriber.Input(
audio_files=[SAMPLES_PATH / "audio" / "this is the content of the document.wav"]
audio_files=[preview_samples_path / "audio" / "this is the content of the document.wav"]
)
)
expected = Document(
content="test transcription",
metadata={
"audio_file": SAMPLES_PATH / "audio" / "this is the content of the document.wav",
"audio_file": preview_samples_path / "audio" / "this is the content of the document.wav",
"other_metadata": ["other", "meta", "data"],
},
)
assert result.documents == [expected]

@pytest.mark.unit
def test_run_with_str(self):
def test_run_with_str(self, preview_samples_path):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
Expand All @@ -74,20 +71,24 @@ def test_run_with_str(self):

result = comp.run(
RemoteWhisperTranscriber.Input(
audio_files=[str((SAMPLES_PATH / "audio" / "this is the content of the document.wav").absolute())]
audio_files=[
str((preview_samples_path / "audio" / "this is the content of the document.wav").absolute())
]
)
)
expected = Document(
content="test transcription",
metadata={
"audio_file": str((SAMPLES_PATH / "audio" / "this is the content of the document.wav").absolute()),
"audio_file": str(
(preview_samples_path / "audio" / "this is the content of the document.wav").absolute()
),
"other_metadata": ["other", "meta", "data"],
},
)
assert result.documents == [expected]

@pytest.mark.unit
def test_transcribe_with_stream(self):
def test_transcribe_with_stream(self, preview_samples_path):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
Expand All @@ -96,7 +97,7 @@ def test_transcribe_with_stream(self):
with patch("haystack.utils.requests.requests") as mocked_requests:
mocked_requests.request.return_value = mock_response

with open(SAMPLES_PATH / "audio" / "this is the content of the document.wav", "rb") as audio_stream:
with open(preview_samples_path / "audio" / "this is the content of the document.wav", "rb") as audio_stream:
result = comp.transcribe(audio_files=[audio_stream])
expected = Document(
content="test transcription",
Expand All @@ -105,7 +106,7 @@ def test_transcribe_with_stream(self):
assert result == [expected]

@pytest.mark.unit
def test_api_transcription(self):
def test_api_transcription(self, preview_samples_path):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
Expand All @@ -116,7 +117,7 @@ def test_api_transcription(self):

comp.run(
RemoteWhisperTranscriber.Input(
audio_files=[SAMPLES_PATH / "audio" / "this is the content of the document.wav"]
audio_files=[preview_samples_path / "audio" / "this is the content of the document.wav"]
)
)
requests_params = mocked_requests.request.call_args.kwargs
Expand All @@ -130,7 +131,7 @@ def test_api_transcription(self):
}

@pytest.mark.unit
def test_api_translation(self):
def test_api_translation(self, preview_samples_path):
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
Expand All @@ -141,7 +142,7 @@ def test_api_translation(self):

comp.run(
RemoteWhisperTranscriber.Input(
audio_files=[SAMPLES_PATH / "audio" / "this is the content of the document.wav"],
audio_files=[preview_samples_path / "audio" / "this is the content of the document.wav"],
whisper_params={"translate": True},
)
)
Expand Down

0 comments on commit c9ac535

Please sign in to comment.