Skip to content

Commit

Permalink
Add test for soxi returning \r char on Windows bugfix
Browse files Browse the repository at this point in the history
Trigger the bug and prove that the bugfix solves it.
  • Loading branch information
nullptr-0 committed Mar 7, 2024
1 parent 10db84a commit 9047b4b
Showing 1 changed file with 26 additions and 0 deletions.
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 9047b4b

Please sign in to comment.