def test_dfuReader(): nCard = Mock() d = dfu.dfuReader(nCard) assert (d.NCard == nCard) assert (d.OpenTimeoutSec == 120) assert d.DFUModeResetPeriodSec == 240
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'
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
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()
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()
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
def createReaderAndPort(): nCard, port = createNotecardAndPort() r = dfu.dfuReader(nCard) return (r, port)
def createReaderWithMockNotecard(card=Mock()): return dfu.dfuReader(card)