From cb283b7dfd5b0baa326ee36b7cd0ae58090b4e70 Mon Sep 17 00:00:00 2001 From: "d.lazukov" Date: Tue, 9 Feb 2021 21:39:09 +0700 Subject: [PATCH 1/2] Make build_array function consider requested output file_type --- sox/transform.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sox/transform.py b/sox/transform.py index d76344b..585420a 100644 --- a/sox/transform.py +++ b/sox/transform.py @@ -807,6 +807,9 @@ def build_array(self, input_filepath=None, input_array=None, 'append_comments': True, } + if self.output_format.get('file_type') is not None: + output_format['file_type'] = self.output_format['file_type'] + if self.output_format.get('rate') is not None: output_format['rate'] = self.output_format['rate'] From faf04ab4853d124c8635cf8f0c4d838c0e6603b9 Mon Sep 17 00:00:00 2001 From: "d.lazukov" Date: Thu, 18 Feb 2021 00:04:50 +0700 Subject: [PATCH 2/2] Add test for output file type. Add IDE stuff to gitignore. --- .gitignore | 6 +++++- tests/test_transform.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7a928b4..b6d1948 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,8 @@ target/ #Ipython Notebook .ipynb_checkpoints -**/noise.prof \ No newline at end of file +**/noise.prof + +# IDE Stuff +.idea/ +.vscode/ \ No newline at end of file diff --git a/tests/test_transform.py b/tests/test_transform.py index 14a99f8..5bef3dd 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -1,6 +1,7 @@ from pathlib import Path import os import unittest +from unittest.mock import patch from sox import transform, file_info from sox.core import SoxError @@ -676,6 +677,7 @@ def test_append_comments_invalid(self): with self.assertRaises(ValueError): self.tfm._output_format_args({'append_comments': None}) + class TestTransformerBuild(unittest.TestCase): def setUp(self): self.tfm = new_transformer() @@ -814,6 +816,17 @@ def test_bits_invalid(self): with self.assertRaises(ValueError): self.tfm.build_array(INPUT_FILE) + def test_output_file_type(self): + with patch("sox.transform.sox") as patched_sox_call: + patched_sox_call.return_value = 0, b"", b"" + self.tfm.build_array(INPUT_FILE) + sox_cmd_args, src_array, decode_out_with_utf = patched_sox_call.call_args[0] + self.assertIn("raw", sox_cmd_args) # default output file type + self.tfm.set_output_format(file_type="gsm") + self.tfm.build_array(INPUT_FILE) + sox_cmd_args, src_array, decode_out_with_utf = patched_sox_call.call_args[0] + self.assertIn("gsm", sox_cmd_args) # desired output file type + class TestTransformerClearEffects(unittest.TestCase):