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_request_download_success_dfi(self):
memloc = MemoryLocation(address=0x1234, memorysize=0xFF, address_format=16, memorysize_format=8)
dfi =DataFormatIdentifier(compression=5, encryption=2)
response = self.udsclient.request_download(memory_location=memloc, dfi=dfi)
self.assertEqual(response.service_data.max_length,0xabcd)
def _test_read_file_bad_moop_echo(self):
with self.assertRaises(UnexpectedResponseException):
self.udsclient.read_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2))
def _test_read_file_bad_dfi(self):
with self.assertRaises(UnexpectedResponseException):
self.udsclient.read_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2))
def _test_add_file_bad_dfi(self):
with self.assertRaises(UnexpectedResponseException):
self.udsclient.add_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = 0x100)
def _test_replace_file_extra_bytes_response_zero_padding_ok(self):
self.udsclient.config['tolerate_zero_padding'] = True
response = self.udsclient.replace_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
self.assertTrue(response.valid)
self.assertTrue(response.positive)
self.assertEqual(response.service_data.moop_echo, 3)
self.assertEqual(response.service_data.max_length, 0xabcd)
self.assertEqual(response.service_data.dfi.compression, 5)
self.assertEqual(response.service_data.dfi.encryption, 2)
self.assertIsNone(response.service_data.filesize) # No filesize info when doing AddFile. Only for ReadFile
self.assertIsNone(response.service_data.dirinfo_length)
def _test_replace_file_negative_response_no_exception(self):
self.udsclient.config['exception_on_negative_response'] = False
response = self.udsclient.replace_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2), filesize = Filesize(uncompressed=0x222, compressed=0x111, width=4))
self.assertTrue(response.valid)
self.assertFalse(response.positive)
def _test_read_file_extra_bytes_response(self):
with self.assertRaises(InvalidResponseException):
self.udsclient.read_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2))
def _test_read_file_extra_bytes_response_zero_padding_ok(self):
self.udsclient.config['tolerate_zero_padding'] = True
response = self.udsclient.read_file("my_file.txt", dfi= DataFormatIdentifier(compression=5, encryption=2))
self.assertTrue(response.valid)
self.assertTrue(response.positive)
self.assertEqual(response.service_data.moop_echo, 4)
self.assertEqual(response.service_data.max_length, 0xabcd)
self.assertEqual(response.service_data.dfi.compression, 5)
self.assertEqual(response.service_data.dfi.encryption, 2)
self.assertEqual(response.service_data.filesize.uncompressed, 0x9876)
self.assertEqual(response.service_data.filesize.compressed, 0x1234)
self.assertIsNone(response.service_data.dirinfo_length)
def __init__(self, memory_location, dfi=None):
from udsoncan import DataFormatIdentifier, MemoryLocation
if dfi is None:
dfi = DataFormatIdentifier()
if not isinstance(memory_location, MemoryLocation):
raise ValueError('memory_location must be an instance of MemoryLocation')
if not isinstance(dfi, DataFormatIdentifier):
raise ValueError('dfi must be an instance of DataFormatIdentifier')
self.memory_location = memory_location
self.dfi = dfi