diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index ebba09e..d5c7dc7 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -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' diff --git a/tests/test_decode.py b/tests/test_decode.py new file mode 100644 index 0000000..2d84e11 --- /dev/null +++ b/tests/test_decode.py @@ -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() diff --git a/tests/test_encode.py b/tests/test_encode.py new file mode 100644 index 0000000..667b87c --- /dev/null +++ b/tests/test_encode.py @@ -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()