Skip to content

Commit

Permalink
Add test_chipset_communication_fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nehpetsde committed Mar 21, 2017
1 parent 4641571 commit 92d74ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
42 changes: 26 additions & 16 deletions tests/test_clf_pn531.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,44 +86,54 @@ def device(self, transport):
transport.write.return_value = None
transport.read.side_effect = [
ACK(), RSP('01 00' + hexlify(bytearray(range(251)))), # Diagnose
ACK(), RSP('03 0304'), # GetFirmwareVersion
ACK(), RSP('15'), # SAMConfiguration
ACK(), RSP('13'), # SetTAMAParameters
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('03 0304'), # GetFirmwareVersion
ACK(), RSP('15'), # SAMConfiguration
ACK(), RSP('13'), # SetTAMAParameters
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
]
device = nfc.clf.pn531.init(transport)
device._path = 'usb:001:001'
assert isinstance(device, nfc.clf.pn531.Device)
assert isinstance(device.chipset, nfc.clf.pn531.Chipset)
assert transport.write.mock_calls == [call(_) for _ in [
CMD('00 00' + hexlify(bytearray(range(251)))), # Diagnose
CMD('02'), # GetFirmwareVersion
CMD('14 0100'), # SAMConfiguration
CMD('12 00'), # SetTAMAParameters
CMD('32 02000b0a'), # RFConfiguration
CMD('32 0400'), # RFConfiguration
CMD('32 05010001'), # RFConfiguration
CMD('32 0102'), # RFConfiguration
CMD('02'), # GetFirmwareVersion
CMD('14 0100'), # SAMConfiguration
CMD('12 00'), # SetTAMAParameters
CMD('32 02000b0a'), # RFConfiguration
CMD('32 0400'), # RFConfiguration
CMD('32 05010001'), # RFConfiguration
CMD('32 0102'), # RFConfiguration
]]
transport.write.reset_mock()
transport.read.reset_mock()
yield device
transport.write.reset_mock()
transport.read.reset_mock()
transport.read.side_effect = [
ACK(), RSP('33'), # RFConfiguration
ACK(), RSP('33'), # RFConfiguration
]
device.close()
assert transport.write.mock_calls == [
call(CMD('32 0102')), # RFConfiguration
call(CMD('32 0102')), # RFConfiguration
]

def reg_rsp(self, hexdata):
return RSP('07' + hexdata)

def test_chipset_communication_fails(self, transport):
transport.write.return_value = None
transport.read.side_effect = [ACK(), ERR()] # Diagnose
chipset = nfc.clf.pn531.Chipset(transport, logger=nfc.clf.pn531.log)
with pytest.raises(IOError):
nfc.clf.pn531.Device(chipset, logger=nfc.clf.pn531.log)
assert chipset.transport.write.mock_calls == [call(
CMD('00 00' + ''.join(["%02x" % x for x in range(251)])))
]

def test_sense_tta_no_target_found(self, device):
self.pn53x_test_sense_tta_no_target_found(device)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_clf_pn532.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ def device(self, transport):
CMD('16 b000'), # PowerDown
]]

def test_chipset_communication_fails(self, transport):
transport.write.return_value = None
transport.read.side_effect = [ACK(), ERR()] # Diagnose
chipset = nfc.clf.pn532.Chipset(transport, logger=nfc.clf.pn532.log)
with pytest.raises(IOError):
nfc.clf.pn532.Device(chipset, logger=nfc.clf.pn532.log)
assert chipset.transport.write.mock_calls == [call(
CMD('00 00' + ''.join(["%02x" % (x % 256) for x in range(262)])))
]

def test_init_linux_stty_set_none(self, mocker, transport): # noqa: F811
mocker.patch('nfc.clf.pn532.Device.__init__').return_value = None
mocker.patch('nfc.clf.pn532.open').return_value = ["cpuinfo"]
Expand Down
10 changes: 10 additions & 0 deletions tests/test_clf_pn533.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def device(self, transport):
def reg_rsp(self, hexdata):
return RSP('07 00' + hexdata)

def test_chipset_communication_fails(self, transport):
transport.write.return_value = None
transport.read.side_effect = [ACK(), ERR()] # Diagnose
chipset = nfc.clf.pn533.Chipset(transport, logger=nfc.clf.pn533.log)
with pytest.raises(IOError):
nfc.clf.pn533.Device(chipset, logger=nfc.clf.pn533.log)
assert chipset.transport.write.mock_calls == [call(
CMD('00 00' + ''.join(["%02x" % (x % 256) for x in range(262)])))
]

def test_sense_tta_no_target_found(self, device):
self.pn53x_test_sense_tta_no_target_found(device)

Expand Down

0 comments on commit 92d74ac

Please sign in to comment.