Skip to content

Commit

Permalink
Merge pull request #163 from nullptr-0/master
Browse files Browse the repository at this point in the history
Add bugfix and test for soxi returning \r char on Windows
  • Loading branch information
lostanlen authored Mar 8, 2024
2 parents b10b361 + 9047b4b commit e2ff3ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def soxi(filepath: Union[str, Path], argument: str) -> str:

shell_output = shell_output.decode("utf-8")

return str(shell_output).strip('\n')
return str(shell_output).strip('\n\r')


def play(args: Iterable[str]) -> bool:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_file_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ def relpath(f):
SILENT_FILE = relpath('data/silence.wav')


class TestCarriageReturnStrip(unittest.TestCase):

def test_carriage_return_strip(self):
def part_of_file_info_bitrate(output):
# The characters below stand for kilo, Mega, Giga, etc.
greek_prefixes = '\0kMGTPEZY'
# Don't need the 'if output == "0":' branch here
if output[-1] in greek_prefixes:
multiplier = 1000.0**(greek_prefixes.index(output[-1]))
return float(output[:-1])*multiplier
else:
return float(output[:-1])
# Simulate a shell output with carriage return
shell_output = '256k\n\r'
# When only '\n' is stripped
output = shell_output.strip('\n')
with self.assertRaises(ValueError):
part_of_file_info_bitrate(output)
# When '\n\r' is stripped
output = shell_output.strip('\n\r')
actual = part_of_file_info_bitrate(output)
expected = 256000.0
self.assertIsInstance(actual, float)
self.assertEqual(expected, actual)


class TestBitrate(unittest.TestCase):

def test_wav(self):
Expand Down

0 comments on commit e2ff3ad

Please sign in to comment.