-
Notifications
You must be signed in to change notification settings - Fork 9
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
Tests #33
Tests #33
Changes from 12 commits
296efec
073ca37
8a5cd15
0a7200c
2e0989b
f90d168
ffe4dc8
f501d76
ee8c980
6f6c31a
fd7e899
abec1e1
570048a
033ce8c
f872fb1
fdb16f2
e40860c
22ca00f
2117353
7cb4010
20e4614
ae3dfb0
169d088
fc4f6a0
beab5df
b018182
ab54afd
72107a6
cce570f
c4d1ecb
b8ef01f
2e9d5b5
6f9c0c8
d114841
f499930
5ee519d
d458c28
d8fa121
b8d9195
77bfc5e
4da3623
cb5be10
4551933
a3a0491
566cd5b
2f9f86e
f8e5c2b
2668f6a
45ae587
ea8e973
2b4819c
018a2bd
c5e44ec
ccdb125
eabd573
c55c12d
6663357
a5fb4c9
328f7d4
f03069b
d1f36eb
ac9d341
fb0c7a9
2844ecd
b4576ab
6144e65
9340b83
54bedc5
1e86245
559c2aa
90a90f9
ba2eac6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import pytest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove unused modules |
||
#from scraibe import Transcriber | ||
#from unittest.mock import patch, mock_open | ||
#import unittest | ||
#import os | ||
from .audio import AudioProcessor | ||
import torch | ||
|
||
|
||
|
||
|
||
|
||
test_waveform = torch.tensor([]).to('cuda') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please handle cpu as well |
||
test_sr = 16000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global Variables should be upper Case letters |
||
SAMPLE_RATE = 16000 | ||
NORMALIZATION_FACTOR = 32768 | ||
|
||
|
||
@pytest.fixture | ||
def probe_audio_processor(): | ||
"""_summary_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add proper doc stings remove summary |
||
|
||
Returns: | ||
_type_: _description_ | ||
""" | ||
return AudioProcessor(test_waveform, test_sr) | ||
|
||
|
||
|
||
|
||
|
||
|
||
def test_AudioProcessor_init(probe_audio_processor): | ||
"""_summary_ | ||
|
||
Args: | ||
probe_audio_processor (_type_): _description_ | ||
""" | ||
assert isinstance(probe_audio_processor, AudioProcessor) | ||
assert probe_audio_processor.waveform.device == test_waveform.device | ||
assert torch.equal(probe_audio_processor.waveform, test_waveform) | ||
assert probe_audio_processor.sr == test_sr | ||
|
||
|
||
|
||
def test_cut(): | ||
"""_summary_ | ||
""" | ||
waveform = torch.Tensor(10, 3) | ||
sr = 16000 | ||
start = 4 | ||
end = 7 | ||
assert AudioProcessor(waveform, sr).cut(start, end).size() == int((end - start) * test_sr) | ||
|
||
|
||
|
||
""" def test_cut(probe_audio_processor): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused func |
||
start = 10 | ||
end = 100 | ||
test_segment = probe_audio_processor.cut(start, end) | ||
print(test_segment) | ||
erwartetes_segment = int((end - start) * test_sr) | ||
print(test_segment.size()) | ||
assert len(test_segment) == erwartetes_segment | ||
""" | ||
|
||
|
||
|
||
|
||
|
||
def test_audio_processor_invalid_sr(): | ||
"""_summary_ | ||
""" | ||
with pytest.raises(ValueError): | ||
AudioProcessor(test_waveform, [44100,48000]) | ||
|
||
|
||
def test_audio_processor_SAMPLE_RATE(): | ||
"""_summary_ | ||
""" | ||
probe_audio_processor = AudioProcessor(test_waveform) | ||
assert probe_audio_processor.sr == SAMPLE_RATE | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
import os | ||
from unittest import mock | ||
from scraibe import Diariser | ||
|
||
|
||
|
||
@pytest.fixture | ||
def diariser_instance(): | ||
with mock.patch.object(Diariser, '_get_token', return_value = 'personal Hugging-Face token') | ||
return Diariser('pyannote') | ||
|
||
|
||
|
||
def test_Diariser_init(diariser_instance): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something seems to be wrong here |
||
"""_summary_ | ||
|
||
Args: | ||
diariser_instance (_type_): _description_ | ||
""" | ||
assert diariser_instance.model == 'pyannote' | ||
|
||
|
||
|
||
def test_diarisation_function(diariser_instance): | ||
"""_summary_ | ||
|
||
Args: | ||
diariser_instance (_type_): _description_ | ||
""" | ||
with mock.patch.object(diariser_instance.model, 'apply', return_value='diarization_result'): | ||
diarization_output = diariser_instance.diarization('example_audio_file.wav') | ||
assert diarization_output == 'diarization_result' | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
from scraibe import Transcriber | ||
|
||
|
||
|
||
|
||
@pytest.mark.parametrize("audio_file, expected_transcription",[("path_to_test_audiofile", "test_transcription")] ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no spagetti |
||
@patch("scraibe.Transcriber.load_model") | ||
|
||
def test_transcriber(mock_load_model, audio_file, expected_transcription): | ||
"""_summary_ | ||
|
||
Args: | ||
mock_load_model (_type_): _description_ | ||
audio_file (_type_): _description_ | ||
expected_transcription (_type_): _description_ | ||
""" | ||
mock_model = mock_load_model.return_value | ||
mock_model.transcribe.return_value ={"text": expected_transcription} | ||
|
||
transcriber = Transcriber.load_model(model="medium") | ||
|
||
transcription_result = transcriber.transcribe(audio=audio_file) | ||
|
||
assert transcription_result == expected_transcription | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file!