def test_init_linux_setbaud_rsp_err(self, mocker, transport): # noqa: F811 mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None mocker.patch('nfc.clf.pn532.open').return_value = ["cpuinfo"] stty = mocker.patch('os.system') stty.side_effect = [-1, 0, None] sys.platform = "linux" transport.write.return_value = None transport.read.side_effect = [ ACK(), RSP('03 32010607'), # GetFirmwareVersion ACK(), RSP('15'), # SAMConfiguration ACK(), ERR(), # SetSerialBaudrate ] with pytest.raises(IOError) as excinfo: nfc.clf.pn532.init(transport) assert excinfo.value.errno == errno.ENODEV assert stty.mock_calls == [ call('stty -F /dev/ttyS0 921600 2> /dev/null'), call('stty -F /dev/ttyS0 460800 2> /dev/null'), call('stty -F /dev/ttyS0 115200 2> /dev/null'), ] assert transport.write.mock_calls == [call(_) for _ in [ HEX(10 * '00') + CMD('02'), # GetFirmwareVersion HEX(10 * '00') + CMD('14 010000'), # SAMConfiguration HEX(10 * '00') + CMD('10 06'), # SetSerialBaudrate ]]
def __test_chipset_communication_fails(self, transport): transport.write.return_value = None transport.read.side_effect = [ACK(), ERR()] # Diagnose chipset = nfc.clf.rcs956.Chipset(transport, logger=nfc.clf.rcs956.log) with pytest.raises(IOError): nfc.clf.rcs956.Device(chipset, logger=nfc.clf.rcs956.log) assert chipset.transport.write.mock_calls == [call( CMD('00 00' + ''.join(["%02x" % (x % 256) for x in range(262)]))) ]
def test_init_version_rsp_err(self, mocker, transport): # noqa: F811 mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None sys.platform = "" transport.write.return_value = None transport.read.side_effect = [ ACK(), ERR(), # GetFirmwareVersion ] with pytest.raises(IOError) as excinfo: nfc.clf.pn532.init(transport) assert excinfo.value.errno == errno.ENODEV assert transport.write.mock_calls == [call(_) for _ in [ HEX(10 * '00') + CMD('02'), # GetFirmwareVersion ]]
def test_init_linux_sam_cfg_rsp_err(self, mocker, transport): # noqa: F811 mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None mocker.patch('nfc.clf.pn532.open').return_value = ["cpuinfo"] mocker.patch('os.system').return_value = -1 sys.platform = "linux" transport.write.return_value = None transport.read.side_effect = [ ACK(), RSP('03 32010607'), # GetFirmwareVersion ACK(), ERR(), # SAMConfiguration ] with pytest.raises(IOError) as excinfo: nfc.clf.pn532.init(transport) assert excinfo.value.errno == errno.ENODEV assert transport.write.mock_calls == [call(_) for _ in [ HEX(10 * '00') + CMD('02'), # GetFirmwareVersion HEX(10 * '00') + CMD('14 010000'), # SAMConfiguration ]]