Пример #1
0
def test_dfuReader():
    nCard = Mock()
    d = dfu.dfuReader(nCard)

    assert (d.NCard == nCard)
    assert (d.OpenTimeoutSec == 120)
    assert d.DFUModeResetPeriodSec == 240
Пример #2
0
def test_dfuReader_privateProperties():
    nCard = Mock()
    d = dfu.dfuReader(nCard)

    assert d._length == 0
    assert d._offset == 0
    assert d._imageHash == None
    assert type(d._md5).__name__ == 'HASH'
Пример #3
0
def test_dfuReader_readToWriter_readsNoContent():
    nCard, port = createNotecardAndPort()
    reader = dfu.dfuReader(nCard)
    reader = preventHubModeReset(reader)

    writer = Mock()

    n = reader.read_to_writer(writer)

    assert n == 0
    assert writer.write.call_count == 0
Пример #4
0
def test_dfuReader_Open_failsToEstablishDfuMode_ClosesDfuMode():
    d = dfu.dfuReader(Mock())
    d._requestDfuModeEntry = Mock()
    f = Mock(return_value=False)
    d._waitForDfuMode = f
    d._requestDfuModeExit = Mock()

    with pytest.raises(Exception):
        d.Open()

    d._requestDfuModeExit.assert_called_once()
Пример #5
0
def test_dfuReader_Open_requestsDfuModeAndWaits():
    d = dfu.dfuReader(Mock())
    e = Mock()
    w = Mock()
    d._requestDfuModeEntry = e
    d._waitForDfuMode = w
    d.GetInfo = Mock(return_value={"length": 0})
    d.Open()

    e.assert_called_once()
    w.assert_called_once()
Пример #6
0
def createReaderWithBinaryContent(c):
    nCard = Mock()

    r = dfu.dfuReader(nCard)
    if c == None:
        r._requestDfuChunk = Mock(return_value=None)
        return r

    b = io.BytesIO(c)

    def f(o, s, num_retries=0):
        b.seek(o)
        return b.read(s)

    r._length = len(c)

    r._requestDfuChunk = Mock(side_effect=f)

    return r
Пример #7
0
def createReaderAndPort():
    nCard, port = createNotecardAndPort()
    r = dfu.dfuReader(nCard)
    return (r, port)
Пример #8
0
def createReaderWithMockNotecard(card=Mock()):
    return dfu.dfuReader(card)