Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make build_array function consider requested output file_type #132

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ target/
#Ipython Notebook
.ipynb_checkpoints

**/noise.prof
**/noise.prof

# IDE Stuff
.idea/
.vscode/
3 changes: 3 additions & 0 deletions sox/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ def build_array(self,
'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']

Expand Down
13 changes: 13 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):

Expand Down