From 033ce8c92ce91b3676c822117031ea9dcb810dc8 Mon Sep 17 00:00:00 2001 From: Tryndaron Date: Tue, 23 Jan 2024 13:21:42 +0100 Subject: [PATCH 1/3] Diarisation basics tests for the Diarisation object --- scraibe/test/test_diarisation.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scraibe/test/test_diarisation.py b/scraibe/test/test_diarisation.py index 148b1a8..b911b88 100644 --- a/scraibe/test/test_diarisation.py +++ b/scraibe/test/test_diarisation.py @@ -7,26 +7,31 @@ from scraibe import Diariser @pytest.fixture def diariser_instance(): + """Creates a instance of the Diariser Object for further testing + + Returns: + _type_: _description_ + """ with mock.patch.object(Diariser, '_get_token', return_value = 'personal Hugging-Face token') return Diariser('pyannote') def test_Diariser_init(diariser_instance): - """_summary_ + """Tests if the Diariser gets initiated correctly Args: - diariser_instance (_type_): _description_ + diariser_instance """ assert diariser_instance.model == 'pyannote' def test_diarisation_function(diariser_instance): - """_summary_ + """tests if the Diariser object with an example audio File Args: - diariser_instance (_type_): _description_ + diariser_instance """ with mock.patch.object(diariser_instance.model, 'apply', return_value='diarization_result'): diarization_output = diariser_instance.diarization('example_audio_file.wav') From e40860c92fad790caed9d1610905eec60433276b Mon Sep 17 00:00:00 2001 From: Tryndaron Date: Thu, 21 Mar 2024 09:29:37 +0100 Subject: [PATCH 2/3] docstring added and variable type --- scraibe/test/test_diarisation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scraibe/test/test_diarisation.py b/scraibe/test/test_diarisation.py index b911b88..8b63151 100644 --- a/scraibe/test/test_diarisation.py +++ b/scraibe/test/test_diarisation.py @@ -10,7 +10,7 @@ def diariser_instance(): """Creates a instance of the Diariser Object for further testing Returns: - _type_: _description_ + Object: Diariser Object for handling the diarization process of an audio file using a pretrained model from pyannote.audio. Diarization is the task of determining "who spoke when." """ with mock.patch.object(Diariser, '_get_token', return_value = 'personal Hugging-Face token') return Diariser('pyannote') @@ -21,17 +21,17 @@ def test_Diariser_init(diariser_instance): """Tests if the Diariser gets initiated correctly Args: - diariser_instance + diariser_instance (obj): instance of the Diariser object """ assert diariser_instance.model == 'pyannote' def test_diarisation_function(diariser_instance): - """tests if the Diariser object with an example audio File + """tests if the Diariser works object with an example audio File Args: - diariser_instance + diariser_instance (obj): instance of the Diariser object """ with mock.patch.object(diariser_instance.model, 'apply', return_value='diarization_result'): diarization_output = diariser_instance.diarization('example_audio_file.wav') From 2117353332f454f2808d54aac4cf76340e8a1528 Mon Sep 17 00:00:00 2001 From: Tryndaron Date: Fri, 22 Mar 2024 11:05:39 +0100 Subject: [PATCH 3/3] docstring added --- scraibe/test/test_diarisation.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/scraibe/test/test_diarisation.py b/scraibe/test/test_diarisation.py index 8b63151..1976016 100644 --- a/scraibe/test/test_diarisation.py +++ b/scraibe/test/test_diarisation.py @@ -7,10 +7,13 @@ from scraibe import Diariser @pytest.fixture def diariser_instance(): - """Creates a instance of the Diariser Object for further testing + """Fixture for creating an instance of the Diariser class with mocked token. + + This fixture is used to create an instance of the the Diariser class with a mocked token returned by the _get_token method. It patches the _get_token method of the Diariser class + using unit.test.mock.patch.object, ensuring that it returns a predetrmined value ('personal Hugging-Face token'). The mocked Diariser object is retunrned and can be used as a dependency in otehr tests. Returns: - Object: Diariser Object for handling the diarization process of an audio file using a pretrained model from pyannote.audio. Diarization is the task of determining "who spoke when." + Diariser(Obj): An instance of the Diariser class with a mocked token. """ with mock.patch.object(Diariser, '_get_token', return_value = 'personal Hugging-Face token') return Diariser('pyannote') @@ -18,20 +21,37 @@ def diariser_instance(): def test_Diariser_init(diariser_instance): - """Tests if the Diariser gets initiated correctly + """Test the initialization of the Diariser class. + + This test verifies that the Diariser class is correctly initialized with the specified model. + It checks whether the 'model' attribute of the instantiated Diariser object equals 'pyannote'. + Args: - diariser_instance (obj): instance of the Diariser object + diariser_instance (obj): instance of the Diariser class + + Returns: + None """ assert diariser_instance.model == 'pyannote' def test_diarisation_function(diariser_instance): - """tests if the Diariser works object with an example audio File + """Test the diarization function of the Diariser class. + + This test verifies that the diarization function of the Diariser class correctly processes + an audio file and returns the diarization result. It patches the apply method of the model + attribute of the Diariser instance using unittest.mock.patch.object, ensuring that it returns + a predetermined value ('diarization_result') when called with the audio file argument. + It then calls the diarization function with an example audio file and checks whether the returned + diarization output matches the expected result ('diarization_result'). Args: diariser_instance (obj): instance of the Diariser object + + Returns: + None """ with mock.patch.object(diariser_instance.model, 'apply', return_value='diarization_result'): diarization_output = diariser_instance.diarization('example_audio_file.wav')