Mercurial > hg > auditok
changeset 209:9047740c5092
Reformat with black
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Fri, 14 Jun 2019 22:43:21 +0100 |
parents | 29472a5a798a |
children | 74864841228a |
files | auditok/io.py tests/test_AudioSource.py tests/test_io.py |
diffstat | 3 files changed, 54 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/auditok/io.py Fri Jun 14 22:40:04 2019 +0100 +++ b/auditok/io.py Fri Jun 14 22:43:21 2019 +0100 @@ -837,7 +837,9 @@ "-", raw data will be read from stdin. If None, read audio data from microphone using PyAudio. """ - sampling_rate, sample_width, channels, use_channel = _get_audio_parameters(kwargs) + sampling_rate, sample_width, channels, use_channel = _get_audio_parameters( + kwargs + ) if input == "-": return StdinAudioSource( sampling_rate, sample_width, channels, use_channel @@ -845,7 +847,9 @@ if isinstance(input, bytes): use_channel = _normalize_use_channel(use_channel) - data = _extract_selected_channel(input, channels, sample_width, use_channel) + data = _extract_selected_channel( + input, channels, sample_width, use_channel + ) return BufferAudioSource(data, sampling_rate, sample_width, channels) # read data from a file @@ -1151,4 +1155,4 @@ ) else: err_message = "cannot write file format {} (file name: {})" - raise AudioIOError(err_message.format(audio_format, file)) \ No newline at end of file + raise AudioIOError(err_message.format(audio_format, file))
--- a/tests/test_AudioSource.py Fri Jun 14 22:40:04 2019 +0100 +++ b/tests/test_AudioSource.py Fri Jun 14 22:43:21 2019 +0100 @@ -37,7 +37,12 @@ multichannel_default=("3channel_400-800-1600Hz", 3, None, 400), multichannel_channel_select_1st=("3channel_400-800-1600Hz", 3, 1, 400), multichannel_channel_select_2nd=("3channel_400-800-1600Hz", 3, 2, 800), - multichannel_channel_select_3rd=("3channel_400-800-1600Hz", 3, 3, 1600), + multichannel_channel_select_3rd=( + "3channel_400-800-1600Hz", + 3, + 3, + 1600, + ), ) def test_RawAudioSource( self, file_suffix, channels, use_channel, frequency @@ -72,7 +77,12 @@ multichannel_default=("3channel_400-800-1600Hz", 3, None, 400), multichannel_channel_select_1st=("3channel_400-800-1600Hz", 3, 1, 400), multichannel_channel_select_2nd=("3channel_400-800-1600Hz", 3, 2, 800), - multichannel_channel_select_3rd=("3channel_400-800-1600Hz", 3, 3, 1600), + multichannel_channel_select_3rd=( + "3channel_400-800-1600Hz", + 3, + 3, + 1600, + ), ) def test_WaveAudioSource( self, file_suffix, channels, use_channel, frequency @@ -446,6 +456,7 @@ with self.assertRaises(Exception): self.audio_source.read(1) + @genty class TestBufferAudioSource_SR16_SW2_CH1(unittest.TestCase): def setUp(self): @@ -556,10 +567,9 @@ @genty_dataset( empty=([], 0, 0, 0), zero=([0], 0, 0, 0), - two=([2], 2, 2/16, int(2000/16)), - eleven=([11], 11, 11/16, int(11*1000/16)), + two=([2], 2, 2 / 16, int(2000 / 16)), + eleven=([11], 11, 11 / 16, int(11 * 1000 / 16)), multiple=([4, 8], 12, 0.75, 750), - ) def test_position( self, block_sizes, expected_sample, expected_second, expected_ms @@ -603,10 +613,10 @@ @genty_dataset( zero=(0, 0, 0, 0), - one=(1, 1, 1/16, int(1000/16)), - ten=(10, 10, 10/16, int(10000/16)), - negative_1=(-1, 15, 15/16, int(15000/16)), - negative_2=(-7, 9, 9/16, int(9000/16)), + one=(1, 1, 1 / 16, int(1000 / 16)), + ten=(10, 10, 10 / 16, int(10000 / 16)), + negative_1=(-1, 15, 15 / 16, int(15000 / 16)), + negative_2=(-7, 9, 9 / 16, int(9000 / 16)), ) def test_position_setter( self, position, expected_sample, expected_second, expected_ms @@ -642,11 +652,11 @@ @genty_dataset( zero=(0, 0, 0, 0), - one=(0.1, 1, 1/16, int(1000/16)), - two=(1/8, 2, 1/8, int(1/8 * 1000)), - twelve=(0.75, 12, .75, 750), - negative_1=(-0.1, 15, 15/16, int(15000/16)), - negative_2=(-0.7, 5, 5/16, int(5000/16)), + one=(0.1, 1, 1 / 16, int(1000 / 16)), + two=(1 / 8, 2, 1 / 8, int(1 / 8 * 1000)), + twelve=(0.75, 12, 0.75, 750), + negative_1=(-0.1, 15, 15 / 16, int(15000 / 16)), + negative_2=(-0.7, 5, 5 / 16, int(5000 / 16)), ) def test_position_s_setter( self, position_s, expected_sample, expected_second, expected_ms @@ -682,11 +692,11 @@ @genty_dataset( zero=(0, 0, 0, 0), - one=(100, 1, 1/16, int(1000/16)), + one=(100, 1, 1 / 16, int(1000 / 16)), ten=(1000, 16, 1, 1000), - negative_1=(-100, 15, 15/16, int(15*1000/16)), + negative_1=(-100, 15, 15 / 16, int(15 * 1000 / 16)), negative_2=(-500, 8, 0.5, 500), - negative_3=(-700, 5, 5/16, int(5*1000/16)), + negative_3=(-700, 5, 5 / 16, int(5 * 1000 / 16)), ) def test_position_ms_setter( self, position_ms, expected_sample, expected_second, expected_ms @@ -720,8 +730,6 @@ ), ) - - def test_sr16_sw2_ch1_rewind(self): self.audio_source.read(10) self.audio_source.rewind() @@ -1076,4 +1084,4 @@ if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main()
--- a/tests/test_io.py Fri Jun 14 22:40:04 2019 +0100 +++ b/tests/test_io.py Fri Jun 14 22:43:21 2019 +0100 @@ -107,7 +107,12 @@ no_use_channel=((8000, 2, 2), (8000, 2, 2, 0)), ) def test_get_audio_parameters_long_params(self, values, expected): - params = dict(zip(("sampling_rate", "sample_width", "channels", "use_channel"), values)) + params = dict( + zip( + ("sampling_rate", "sample_width", "channels", "use_channel"), + values, + ) + ) result = _get_audio_parameters(params) self.assertEqual(result, expected) @@ -115,7 +120,12 @@ def test_get_audio_parameters_long_params_shadow_short_ones( self, values, expected ): - params = dict(zip(("sampling_rate", "sample_width", "channels", "use_channel"), values)) + params = dict( + zip( + ("sampling_rate", "sample_width", "channels", "use_channel"), + values, + ) + ) params.update(dict(zip(("sr", "sw", "ch", "uc"), "xxxx"))) result = _get_audio_parameters(params) self.assertEqual(result, expected) @@ -132,7 +142,12 @@ # TODO 0 or negative use_channel must raise AudioParameterError # change implementation, don't accept negative uc # hifglight everywhere in doc that uc must be positive - params = dict(zip(("sampling_rate", "sample_width", "channels", "use_channel"), values)) + params = dict( + zip( + ("sampling_rate", "sample_width", "channels", "use_channel"), + values, + ) + ) with self.assertRaises(AudioParameterError): _get_audio_parameters(params) @@ -761,4 +776,4 @@ if extra_args is not None: kwargs.update(extra_args) audio_source = get_audio_source(input, **kwargs) - self.assertIsInstance(audio_source, expected_type) \ No newline at end of file + self.assertIsInstance(audio_source, expected_type)