mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 01:18:02 +08:00
31 lines
913 B
Python
31 lines
913 B
Python
from amodem import audio, config
|
|
|
|
import mock
|
|
import pytest
|
|
|
|
|
|
def test():
|
|
length = 1024
|
|
data = b'\x12\x34' * length
|
|
with mock.patch('ctypes.CDLL') as cdll:
|
|
lib = mock.Mock()
|
|
lib.Pa_GetErrorText = lambda code: 'Error' if code else 'Success'
|
|
lib.Pa_GetDefaultInputDevice.return_value = 1
|
|
lib.Pa_OpenStream.return_value = 0
|
|
cdll.return_value = lib
|
|
interface = audio.Interface(name='portaudio', config=config.fastest())
|
|
with interface:
|
|
s = interface.player()
|
|
s.stream = 1 # simulate non-zero output stream handle
|
|
s.write(data=data)
|
|
s.close()
|
|
|
|
with interface:
|
|
s = interface.recorder()
|
|
s.stream = 2 # simulate non-zero input stream handle
|
|
s.read(len(data))
|
|
s.close()
|
|
|
|
with pytest.raises(Exception):
|
|
interface._error_check(1)
|