Пример #1
0
    def test_disable_unpack(self):
        # Arrange
        command_word = pack_command_word(Command.POLL)

        self.interface.transmit_receive = Mock(return_value=[0b1111111110])

        # Act and assert
        self.assertEqual(_execute_read_command(self.interface, command_word, unpack=False), [0b1111111110])
Пример #2
0
    def test_allow_trta_response(self):
        # Arrange
        command_word = pack_command_word(Command.POLL)

        self.interface.transmit_receive = Mock(return_value=[0b0000000000])

        # Act and assert
        self.assertEqual(_execute_read_command(self.interface, command_word, allow_trta_response=True, trta_value='TRTA'), 'TRTA')
Пример #3
0
    def test(self):
        # Arrange
        command_word = pack_command_word(Command.READ_TERMINAL_ID)

        self.interface.transmit_receive = Mock(return_value=[0b0000000010])

        # Act and assert
        self.assertEqual(_execute_read_command(self.interface, command_word), bytes.fromhex('00'))
Пример #4
0
    def test_not_trta_response(self):
        # Arrange
        command_word = pack_command_word(Command.WRITE_DATA)

        self.interface.transmit_receive = Mock(return_value=[0b0000000010])

        # Act and assert
        with self.assertRaisesRegex(ProtocolError, 'Expected TR/TA response'):
            _execute_write_command(self.interface, command_word, bytes.fromhex('de ad be ef'))
Пример #5
0
    def test_unexpected_response_length(self):
        # Arrange
        command_word = pack_command_word(Command.READ_TERMINAL_ID)

        self.interface.transmit_receive = Mock(return_value=[])

        # Act and assert
        with self.assertRaisesRegex(ProtocolError, 'Expected 1 word response'):
            _execute_read_command(self.interface, command_word)
Пример #6
0
    def test(self):
        # Arrange
        command_word = pack_command_word(Command.WRITE_DATA)

        self.interface.transmit_receive = Mock(return_value=[0b0000000000])

        # Act and assert
        _execute_write_command(self.interface, command_word,
                               bytes.fromhex('de ad be ef'))
Пример #7
0
    def test_receive_timeout_is_passed_to_interface(self):
        # Arrange
        command_word = pack_command_word(Command.WRITE_DATA)

        self.interface.transmit_receive = Mock(return_value=[0b0000000000])

        # Assert
        _execute_write_command(self.interface, command_word, bytes.fromhex('de ad be ef'), receive_timeout=10)

        # Assert
        self.assertEqual(self.interface.transmit_receive.call_args[1].get('receive_timeout'), 10)
Пример #8
0
    def test_receive_timeout_is_passed_to_interface(self):
        # Arrange
        command_word = pack_command_word(Command.READ_TERMINAL_ID)

        self.interface.transmit_receive = Mock(return_value=[0b0000000010])

        # Act
        _execute_read_command(self.interface, command_word, receive_timeout=10)

        # Assert
        self.assertEqual(self.interface.transmit_receive.call_args[1].get('receive_timeout'), 10)
Пример #9
0
    def test(self):
        for jumbo_write_strategy in [None, 'split']:
            with self.subTest(jumbo_write_strategy=jumbo_write_strategy):
                # Arrange
                command_word = pack_command_word(Command.WRITE_DATA)

                self.interface.transmit_receive = Mock(return_value=[0b0000000000])

                # Act
                _execute_write_command(self.interface, command_word, bytes.fromhex('de ad be ef'), jumbo_write_strategy=jumbo_write_strategy)

                # Assert
                self.interface.transmit_receive.assert_called_once_with([0x0031, 0x037a, 0x02b4, 0x02fa, 0x03bc], None, receive_length=1)
Пример #10
0
    def test_jumbo_write_split_strategy(self):
        # Arrange
        command_word = pack_command_word(Command.WRITE_DATA)

        self.interface.transmit_receive = Mock(return_value=[0b0000000000])

        data = (bytes.fromhex('01') * 1023) + (bytes.fromhex('02') * 32)

        # Act
        _execute_write_command(self.interface, command_word, data, jumbo_write_strategy='split')

        # Assert
        self.assertEqual(self.interface.transmit_receive.call_count, 2)

        call_args_list = self.interface.transmit_receive.call_args_list

        self.assertEqual(len(call_args_list[0][0][0]), 1024)
        self.assertEqual(len(call_args_list[1][0][0]), 32)
Пример #11
0
 def test(self):
     self.assertEqual(pack_command_word(Command.POLL_ACK), 0b0001000101)