Skip to content

Commit

Permalink
Add simple unit tests to check output length for both encode
Browse files Browse the repository at this point in the history
and decode.
  • Loading branch information
sobomax committed Jul 29, 2024
1 parent c71d667 commit e915513
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ jobs:
run: pip install dist/[Gg]722*.gz
shell: bash

- if: ${{ matrix.os != 'windows' }}
name: test
- name: test
if: ${{ matrix.os != 'windows' }}
run: ./scripts/do-test.sh "python test.py"
shell: bash

- name: unit tests
run: python -m unittest discover tests '*.py'
shell: bash

publish_wheels:
needs: [build_and_test_python, build_in_docker]
if: github.event_name == 'release' && github.event.action == 'created'
Expand Down
22 changes: 22 additions & 0 deletions tests/test_decode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest

from G722 import G722

class TestDecoder(unittest.TestCase):
def test_decode_len(self):
bitrates = [48000, 56000, 64000]
sample_rates = [8000, 16000]

for bitrate in bitrates:
for sample_rate in sample_rates:
with self.subTest(bitrate=bitrate, sample_rate=sample_rate):
g722 = G722(sample_rate, bitrate)
encoded_data = b"0123" # Example encoded data
decoded_data = g722.decode(encoded_data)
got = len(decoded_data)
want = 4 if sample_rate == 8000 else 8
self.assertEqual(want, got)


if __name__ == '__main__':
unittest.main()
21 changes: 21 additions & 0 deletions tests/test_encode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest

from G722 import G722

class TestEncoder(unittest.TestCase):
def test_encode_len(self):
bitrates = [48000, 56000, 64000]
sample_rates = [8000, 16000]

for bitrate in bitrates:
for sample_rate in sample_rates:
with self.subTest(bitrate=bitrate, sample_rate=sample_rate):
g722 = G722(sample_rate, bitrate)
audio_data = b"\x00\x01\x02\x03" # Example raw audio data
encoded_data = g722.encode(audio_data)
got = len(encoded_data)
want = 4 if sample_rate == 8000 else 2
self.assertEqual(want, got)

if __name__ == '__main__':
unittest.main()

0 comments on commit e915513

Please sign in to comment.