def test_from_byte(self):
        comtype = CommunicationType.from_byte(b'\x01')
        self.assertEqual(comtype.get_byte(), b'\x01')

        comtype = CommunicationType.from_byte(b'\xF1')
        self.assertEqual(comtype.get_byte(), b'\xF1')

        comtype = CommunicationType.from_byte(b'\x33')
        self.assertEqual(comtype.get_byte(), b'\x33')
Example #2
0
    def _test_comcontrol_enable_node(self):
        control_type = services.CommunicationControl.ControlType.enableRxAndTx
        com_type = CommunicationType(subnet=CommunicationType.Subnet.node, normal_msg=True)
        response = self.udsclient.communication_control(control_type=control_type, communication_type=com_type)
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.control_type_echo, control_type)

        response = self.udsclient.communication_control(control_type=control_type, communication_type=com_type.get_byte())
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.control_type_echo, control_type)

        response = self.udsclient.communication_control(control_type=control_type, communication_type=com_type.get_byte_as_int())
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.control_type_echo, control_type)
Example #3
0
 def _test_comcontrol_bad_control_type_exception(self):
     with self.assertRaises(UnexpectedResponseException) as handle:
         com_type = CommunicationType(subnet=3,
                                      normal_msg=True,
                                      network_management_msg=True)
         self.udsclient.communication_control(control_type=9,
                                              communication_type=com_type)
Example #4
0
 def _test_comcontrol_negative_response_no_exception(self):
     self.udsclient.config[u'exception_on_negative_response'] = False
     control_type = services.CommunicationControl.ControlType.disableRxAndTx
     com_type = CommunicationType(subnet=3, normal_msg=True, network_management_msg=True)
     response = self.udsclient.communication_control(control_type=control_type, communication_type=com_type)				
     self.assertTrue(response.valid)
     self.assertFalse(response.positive)
Example #5
0
 def _test_comcontrol_enable_node_spr(self):
     control_type = services.CommunicationControl.ControlType.enableRxAndTx
     com_type = CommunicationType(subnet=CommunicationType.Subnet.node, normal_msg=True)
     with self.udsclient.suppress_positive_response:
         response = self.udsclient.communication_control(control_type=control_type, communication_type=com_type)
         self.assertEqual(response, None)
     self.conn.fromuserqueue.get(timeout=0.2)	#Avoid closing connection prematurely
Example #6
0
 def _test_set_params_invalidservice_exception(self):
     with self.assertRaises(InvalidResponseException) as handle:
         control_type = services.CommunicationControl.ControlType.disableRxAndTx
         com_type = CommunicationType(subnet=5,
                                      normal_msg=True,
                                      network_management_msg=True)
         self.udsclient.communication_control(control_type=control_type,
                                              communication_type=com_type)
Example #7
0
 def _test_comcontrol_negative_response_exception(self):
     with self.assertRaises(NegativeResponseException) as handle:
         control_type = services.CommunicationControl.ControlType.disableRxAndTx
         com_type = CommunicationType(subnet=3,
                                      normal_msg=True,
                                      network_management_msg=True)
         self.udsclient.communication_control(control_type=control_type,
                                              communication_type=com_type)
Example #8
0
 def _test_set_params_invalidservice_no_exception(self):
     self.udsclient.config['exception_on_invalid_response'] = False
     control_type = services.CommunicationControl.ControlType.disableRxAndTx
     com_type = CommunicationType(subnet=5,
                                  normal_msg=True,
                                  network_management_msg=True)
     response = self.udsclient.communication_control(
         control_type=control_type, communication_type=com_type)
     self.assertFalse(response.valid)
Example #9
0
 def _test_comcontrol_disable_subnet(self):
     control_type = services.CommunicationControl.ControlType.disableRxAndTx
     com_type = CommunicationType(subnet=3,
                                  normal_msg=True,
                                  network_management_msg=True)
     response = self.udsclient.communication_control(
         control_type=control_type, communication_type=com_type)
     self.assertTrue(response.positive)
     self.assertEqual(response.service_data.control_type_echo, control_type)
Example #10
0
 def _test_comcontrol_bad_control_type_no_exception(self):
     self.udsclient.config['exception_on_unexpected_response'] = False
     com_type = CommunicationType(subnet=3,
                                  normal_msg=True,
                                  network_management_msg=True)
     response = self.udsclient.communication_control(
         control_type=9, communication_type=com_type)
     self.assertTrue(response.valid)
     self.assertTrue(response.unexpected)
    def test_make(self):
        comtype = CommunicationType(subnet=CommunicationType.Subnet.node,
                                    normal_msg=True,
                                    network_management_msg=False)
        self.assertEqual(comtype.get_byte(), b'\x01')

        comtype = CommunicationType(subnet=CommunicationType.Subnet.network,
                                    normal_msg=True,
                                    network_management_msg=False)
        self.assertEqual(comtype.get_byte(), b'\xF1')

        comtype = CommunicationType(subnet=3,
                                    normal_msg=True,
                                    network_management_msg=True)
        self.assertEqual(comtype.get_byte(), b'\x33')
Example #12
0
    def normalize_communication_type(self, communication_type):
        from udsoncan import CommunicationType

        if not isinstance(communication_type, CommunicationType) and not isinstance(communication_type, (int, long)) and not isinstance(communication_type, str):
            raise ValueError(u'communication_type must either be a CommunicationType object or an integer')

        if isinstance(communication_type, (int, long)) or isinstance(communication_type, str):
            communication_type = CommunicationType.from_byte(communication_type)

        return communication_type
    def test_oob_values(self):
        with self.assertRaises(ValueError):
            CommunicationType(subnet=0,
                              normal_msg=False,
                              network_management_msg=False)

        with self.assertRaises(ValueError):
            CommunicationType(subnet='x',
                              normal_msg=True,
                              network_management_msg=False)

        with self.assertRaises(ValueError):
            CommunicationType(subnet=0,
                              normal_msg=1,
                              network_management_msg=True)

        with self.assertRaises(ValueError):
            CommunicationType(subnet=0,
                              normal_msg=True,
                              network_management_msg=1)
Example #14
0
    def _test_bad_param(self):
        valid_com_type = CommunicationType(subnet=3, normal_msg=True, network_management_msg=True)
        with self.assertRaises(ValueError):
            self.udsclient.communication_control(control_type=u'x', communication_type=valid_com_type)	

        with self.assertRaises(ValueError):
            self.udsclient.communication_control(control_type=0x80, communication_type=valid_com_type)

        with self.assertRaises(ValueError):
            self.udsclient.communication_control(control_type=-1, communication_type=valid_com_type)

        with self.assertRaises(ValueError):
            self.udsclient.communication_control(control_type=0, communication_type=u'x')
 def test_str_repr(self):
     comtype = CommunicationType(subnet=CommunicationType.Subnet.node,
                                 normal_msg=True,
                                 network_management_msg=False)
     str(comtype)
     comtype.__repr__()