Example #1
0
def test_recv_binary_search():
    buf = BytesIO()
    gains = [0.5, 0.25, 0.38, 0.44, 0.41, 0.39, 0.40, 0.40]
    for gain in gains:
        calib.send(config, buf, gain=gain, limit=2)
    buf.seek(0)

    dump = BytesIO()
    with mock.patch('subprocess.check_call') as check_call:
        calib.recv(config, src=buf, volume_cmd='ctl', dump_audio=dump)
    assert dump.getvalue() == buf.getvalue()

    gains.append(gains[-1])
    fmt = 'ctl {0:.0f}%'
    expected = [mock.call(shell=True, args=fmt.format(100 * g)) for g in gains]
    assert check_call.mock_calls == expected
Example #2
0
def test_errors():
    class WriteError(ProcessMock):
        def write(self, data):
            raise KeyboardInterrupt()
    p = WriteError()
    with pytest.raises(KeyboardInterrupt):
        calib.send(config, p, limit=32)
    assert p.buf.tell() == 0

    class ReadError(ProcessMock):
        def read(self, n):
            raise KeyboardInterrupt()
    p = ReadError()
    with pytest.raises(KeyboardInterrupt):
        calib.recv(config, p, verbose=True)
    assert p.buf.tell() == 0
Example #3
0
def test_recv_binary_search():
    buf = BytesIO()
    gains = [0.5, 0.25, 0.38, 0.44, 0.41, 0.39, 0.40, 0.40]
    for gain in gains:
        calib.send(config, buf, gain=gain, limit=2)
    buf.seek(0)

    dump = BytesIO()
    with mock.patch('subprocess.check_call') as check_call:
        calib.recv(config, src=buf, volume_cmd='ctl', dump_audio=dump)
    assert dump.getvalue() == buf.getvalue()

    gains.append(gains[-1])
    fmt = 'ctl {0:.0f}%'
    expected = [mock.call(shell=True, args=fmt.format(100 * g)) for g in gains]
    assert check_call.mock_calls == expected
Example #4
0
def test_errors():
    class WriteError(ProcessMock):
        def write(self, data):
            raise KeyboardInterrupt()

    p = WriteError()
    with pytest.raises(KeyboardInterrupt):
        calib.send(config, p, limit=32)
    assert p.buf.tell() == 0

    class ReadError(ProcessMock):
        def read(self, n):
            raise KeyboardInterrupt()

    p = ReadError()
    with pytest.raises(KeyboardInterrupt):
        calib.recv(config, p, verbose=True)
    assert p.buf.tell() == 0
Example #5
0
def test_success():
    p = ProcessMock()
    calib.send(config, p, gain=0.5, limit=32)
    p.buf.seek(0)
    calib.recv(config, p)
Example #6
0
def test_success():
    p = ProcessMock()
    calib.send(config, p, gain=0.5, limit=32)
    p.buf.seek(0)
    calib.recv(config, p)