From 570048a2e0b5e9798103934dc5f196b7159045b5 Mon Sep 17 00:00:00 2001 From: Tryndaron Date: Tue, 23 Jan 2024 13:08:59 +0100 Subject: [PATCH 1/3] Docstrings I applied the Changes which were mentioned in the tests_audio.py file --- scraibe/test/test_audio.py | 42 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/scraibe/test/test_audio.py b/scraibe/test/test_audio.py index a0c37ad..5a35055 100644 --- a/scraibe/test/test_audio.py +++ b/scraibe/test/test_audio.py @@ -1,29 +1,25 @@ import pytest -#from scraibe import Transcriber -#from unittest.mock import patch, mock_open -#import unittest -#import os from .audio import AudioProcessor import torch +device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') - -test_waveform = torch.tensor([]).to('cuda') -test_sr = 16000 +test_waveform = torch.tensor([]).to(device) +TEST_SR = 16000 SAMPLE_RATE = 16000 NORMALIZATION_FACTOR = 32768 @pytest.fixture def probe_audio_processor(): - """_summary_ + """Creates a dummy AudioProcessor Object Returns: - _type_: _description_ + AudioProcessor Object with given parameters test_waveform and TEST_SR """ - return AudioProcessor(test_waveform, test_sr) + return AudioProcessor(test_waveform, TEST_SR) @@ -31,10 +27,11 @@ def probe_audio_processor(): def test_AudioProcessor_init(probe_audio_processor): - """_summary_ + """ + testing if the audio_processor Object gets initialized correctly - Args: - probe_audio_processor (_type_): _description_ + Args: probe_audio_processor Object + """ assert isinstance(probe_audio_processor, AudioProcessor) assert probe_audio_processor.waveform.device == test_waveform.device @@ -44,39 +41,32 @@ def test_AudioProcessor_init(probe_audio_processor): def test_cut(): - """_summary_ + """Test for the test_cut Method for fixed parameters """ waveform = torch.Tensor(10, 3) sr = 16000 start = 4 end = 7 - assert AudioProcessor(waveform, sr).cut(start, end).size() == int((end - start) * test_sr) + assert AudioProcessor(waveform, sr).cut(start, end).size() == int((end - start) * TEST_SR) -""" def test_cut(probe_audio_processor): - 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_ + """Testing the audio_processor Object with invalid Sample rate """ with pytest.raises(ValueError): AudioProcessor(test_waveform, [44100,48000]) def test_audio_processor_SAMPLE_RATE(): - """_summary_ + """Making sure Sample Rate of Audio_processor Sample Rate matches global Sample Rate """ probe_audio_processor = AudioProcessor(test_waveform) assert probe_audio_processor.sr == SAMPLE_RATE From fdb16f2f45cb79d574d3bc0ba850c76b3b7d5352 Mon Sep 17 00:00:00 2001 From: Tryndaron Date: Fri, 15 Mar 2024 12:54:08 +0100 Subject: [PATCH 2/3] fixed comments --- scraibe/test/test_audio.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scraibe/test/test_audio.py b/scraibe/test/test_audio.py index 5a35055..2a0ce53 100644 --- a/scraibe/test/test_audio.py +++ b/scraibe/test/test_audio.py @@ -3,10 +3,9 @@ from .audio import AudioProcessor import torch -device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') - -test_waveform = torch.tensor([]).to(device) +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") +TEST_WAVEFORM = torch.tensor([]).to(device) TEST_SR = 16000 SAMPLE_RATE = 16000 NORMALIZATION_FACTOR = 32768 @@ -43,11 +42,10 @@ def test_AudioProcessor_init(probe_audio_processor): def test_cut(): """Test for the test_cut Method for fixed parameters """ - waveform = torch.Tensor(10, 3) - sr = 16000 + start = 4 end = 7 - assert AudioProcessor(waveform, sr).cut(start, end).size() == int((end - start) * TEST_SR) + assert AudioProcessor(TEST_WAVEFORM, TEST_SR).cut(start, end).size() == int((end - start) * TEST_SR) From 22ca00fea953786e0576e0812d0d629311e110e1 Mon Sep 17 00:00:00 2001 From: Tryndaron Date: Thu, 21 Mar 2024 11:06:01 +0100 Subject: [PATCH 3/3] Docstrings and global Variables got fixed --- scraibe/test/test_audio.py | 66 +++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/scraibe/test/test_audio.py b/scraibe/test/test_audio.py index 2a0ce53..6b46c1b 100644 --- a/scraibe/test/test_audio.py +++ b/scraibe/test/test_audio.py @@ -4,8 +4,8 @@ import torch -device = torch.device("cuda" if torch.cuda.is_available() else "cpu") -TEST_WAVEFORM = torch.tensor([]).to(device) +DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu") +TEST_WAVEFORM = torch.tensor([]).to(DEVICE) TEST_SR = 16000 SAMPLE_RATE = 16000 NORMALIZATION_FACTOR = 32768 @@ -13,12 +13,16 @@ NORMALIZATION_FACTOR = 32768 @pytest.fixture def probe_audio_processor(): - """Creates a dummy AudioProcessor Object + """Fixture for creating an instance of the AudioProcessor class with test waveform and sample rate. + + This fixture is used to create an instance of the AudioProcessor class with a predfined test waveform and sample rate (TEST_SR). It returns the instantiated AudioProcessor , which can bes used as a + dependency in other test functions. + Returns: - AudioProcessor Object with given parameters test_waveform and TEST_SR + AudioProcessor (obj): An instance of the AudioProcessor class with the test waveform and sample rate. """ - return AudioProcessor(test_waveform, TEST_SR) + return AudioProcessor(TEST_WAVEFORM, TEST_SR) @@ -27,20 +31,40 @@ def probe_audio_processor(): def test_AudioProcessor_init(probe_audio_processor): """ - testing if the audio_processor Object gets initialized correctly + Test the initialization of the AudioProcessor class. + + This test verifies that the AUdioProcessor class is correctly initialized with the provided waveform and sample rate. It checks whether the instantiated AhdioProcessor object has the correct attributes + and whether the waveform and sample rate match the expected values. + + Args: + probe_audio_processor (obj): An instance of the AudioProcessor class to be tested. + + + Returns: + None + + - Args: probe_audio_processor Object """ 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 + 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(): - """Test for the test_cut Method for fixed parameters + """Test the cut function of the AudioProcessor class. + + This test verifies that the cut function correctly extracts a segment of audio data from + the waveform, given start and end indices. It checks whether the size of the extracted segment matches + the expected size based on the provided start and end indices and the sample rate. + + Returns: + None + + """ start = 4 @@ -57,16 +81,28 @@ def test_cut(): def test_audio_processor_invalid_sr(): - """Testing the audio_processor Object with invalid Sample rate + """Test the behavior of AudioProcessor when an invalid smaple rate is provided. + + This test verifies that the AudioProcessor constructor raises a ValueError when an invalid sample rate is provided. It uses the pytest.raises context manager to check if the ValueError is raised when initializing an + AudioProcessor object with an invalid sample rate. + + Returns: + None """ with pytest.raises(ValueError): - AudioProcessor(test_waveform, [44100,48000]) + AudioProcessor(TEST_WAVEFORM, [44100,48000]) def test_audio_processor_SAMPLE_RATE(): - """Making sure Sample Rate of Audio_processor Sample Rate matches global Sample Rate + """Test the default sample rate of the AudioProcessor class. + + This test verifies that the default sample rate of the AudioProcessor class matches the expected value defined by the constant SAMPLE_RATE. It instantiates an AudioProcessor object with a test waveform + and checks whether the sample rate attribute (sr) of the AudioProcessor object equals the predefined constant SAMPLE_RATE. + + Returns: + None """ - probe_audio_processor = AudioProcessor(test_waveform) + probe_audio_processor = AudioProcessor(TEST_WAVEFORM) assert probe_audio_processor.sr == SAMPLE_RATE