def test_sample_rate_error(art_warning): try: exc_msg = "Sample rate be must a positive integer." with pytest.raises(ValueError, match=exc_msg): Mp3Compression(sample_rate=0) except ARTTestException as e: art_warning(e)
def test_non_temporal_data_error(self, image_batch): test_input = image_batch mp3compression = Mp3Compression(sample_rate=16000) exc_msg = "Mp3 compression can only be applied to temporal data across at least one channel." with pytest.raises(ValueError, match=exc_msg): mp3compression(test_input)
def test_check_params(art_warning): try: with pytest.raises(ValueError): _ = Mp3Compression(sample_rate=1000, verbose="False") except ARTTestException as e: art_warning(e)
def test_mp3_compresssion(art_warning, audio_batch, channels_first): try: test_input, test_output, sample_rate = audio_batch mp3compression = Mp3Compression(sample_rate=sample_rate, channels_first=channels_first) assert_array_equal(mp3compression(test_input)[0], test_output) except ARTTestException as e: art_warning(e)
def test_non_temporal_data_error(art_warning, image_batch_small): try: test_input = image_batch_small mp3compression = Mp3Compression(sample_rate=16000) exc_msg = "Mp3 compression can only be applied to temporal data across at least one channel." with pytest.raises(ValueError, match=exc_msg): mp3compression(test_input) except ARTTestException as e: art_warning(e)
def test_mp3_compresssion_object(art_warning, audio_batch, channels_first): try: test_input, test_output, sample_rate = audio_batch test_input_object = np.array([x for x in test_input], dtype=object) mp3compression = Mp3Compression(sample_rate=sample_rate, channels_first=channels_first) assert_array_equal(mp3compression(test_input_object)[0], test_output) grad = mp3compression.estimate_gradient( x=test_input_object, grad=np.ones_like(test_input_object)) assert grad.dtype == object assert grad.shape == (2, test_input.shape[1], 44100) if channels_first else ( 2, 44100, test_input.shape[2]) except ARTTestException as e: art_warning(e)
def test_mp3_compresssion(self, audio_batch, channels_first): test_input, test_output, sample_rate = audio_batch mp3compression = Mp3Compression(sample_rate=sample_rate, channels_first=channels_first) assert_array_equal(mp3compression(test_input)[0], test_output)
def test_sample_rate_error(self): exc_msg = "Sample rate be must a positive integer." with pytest.raises(ValueError, match=exc_msg): Mp3Compression(sample_rate=0)