Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _test_bad_echo_ali_no_exception(self):
self.udsclient.config['exception_on_unexpected_response'] = False
memloc = MemoryLocation(address=0x1234, memorysize=4, address_format=16, memorysize_format=8)
response = self.udsclient.write_memory_by_address(memloc, b'\x66\x77\x88\x99')
self.assertTrue(response.valid)
self.assertTrue(response.unexpected)
def _test_request_invalid_service_no_exception(self):
self.udsclient.config['exception_on_invalid_response'] = False
memloc = MemoryLocation(address=0x1234, memorysize=4, address_format=16, memorysize_format=8)
response = self.udsclient.write_memory_by_address(memloc, b'\x66\x77\x88\x99')
self.assertFalse(response.valid)
def test_memloc_autosize2(self):
memloc = MemoryLocation(address=0x1234567, memorysize=0x789abb)
self.assertEqual(memloc.get_address_bytes(), b'\x01\x23\x45\x67')
self.assertEqual(memloc.get_memorysize_bytes(), b'\x78\x9a\xbb')
def _test_4byte_block(self):
memloc = MemoryLocation(address=0x1234, memorysize=4, address_format=16, memorysize_format=8)
response = self.udsclient.write_memory_by_address(memloc, b'\x66\x77\x88\x99')
self.assertEqual(response.service_data.alfid_echo, memloc.alfid.get_byte_as_int())
self.assertEqual(response.service_data.memory_location_echo.address, 0x1234)
self.assertEqual(response.service_data.memory_location_echo.memorysize, 4)
def test_memloc_from_bytes(self):
memloc = MemoryLocation.from_bytes(address_bytes=b'\x12\x34', memorysize_bytes=b'\xFF')
self.assertEqual(memloc.address, 0x1234)
self.assertEqual(memloc.memorysize, 0xFF)
self.assertEqual(memloc.address_format, 16)
self.assertEqual(memloc.memorysize_format, 8)
memloc = MemoryLocation.from_bytes(address_bytes=b'\x12\x34\x56', memorysize_bytes=b'\x66\x77\x88')
self.assertEqual(memloc.address, 0x123456)
self.assertEqual(memloc.memorysize, 0x667788)
self.assertEqual(memloc.address_format, 24)
self.assertEqual(memloc.memorysize_format, 24)
def test_memloc1(self):
memloc = MemoryLocation(address=0x1234, memorysize=0x78, address_format=16, memorysize_format=8)
self.assertEqual(memloc.get_address_bytes(), b'\x12\x34')
self.assertEqual(memloc.get_memorysize_bytes(), b'\x78')
def _test_request_upload_invalidservice_no_exception(self):
self.udsclient.config['exception_on_invalid_response'] = False
memloc = MemoryLocation(address=0x1234, memorysize=0xFF, address_format=16, memorysize_format=8)
response = self.udsclient.request_upload(memory_location=memloc)
self.assertFalse(response.valid)
def _test_request_invalid_service_exception(self):
with self.assertRaises(InvalidResponseException) as handle:
self.udsclient.read_memory_by_address(MemoryLocation(address=0x1234, memorysize=4, address_format=16, memorysize_format=8))
def _test_4byte_block_zeropadding_ok(self):
self.udsclient.config['tolerate_zero_padding'] = True
for i in range(8):
response = self.udsclient.read_memory_by_address(MemoryLocation(address=0x1234, memorysize=4, address_format=16, memorysize_format=8))
self.assertEqual(response.service_data.memory_block, b'\x99\x88\x77\x66')
def _test_wrong_service_exception(self):
with self.assertRaises(UnexpectedResponseException) as handle:
self.udsclient.read_memory_by_address(MemoryLocation(address=0x1234, memorysize=4, address_format=16, memorysize_format=8))