Coverage for /home/runner/work/zserio/zserio/compiler/extensions/python/runtime/tests/test_service.py: 100%

42 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-12-05 10:43 +0000

1import unittest 

2 

3from zserio import ServiceData, ServiceInterface, ServiceClientInterface 

4from zserio.service import ObjectServiceData, RawServiceData 

5 

6 

7class ServiceTest(unittest.TestCase): 

8 def test_object_service_data(self): 

9 class ZserioObject: 

10 def __init__(self, value): 

11 self._value = value 

12 

13 def __eq__(self, other): 

14 return self._value == other._value 

15 

16 @staticmethod 

17 def bitsizeof(_bitposition): 

18 return 31 # to make an unaligned type 

19 

20 def write(self, writer): 

21 writer.write_bits(self._value, self.bitsizeof(0)) 

22 

23 zserio_object = ZserioObject(0xABCD) 

24 service_data = ObjectServiceData(zserio_object) 

25 self.assertEqual(zserio_object, service_data.zserio_object) 

26 self.assertEqual(bytes([0x00, 0x01, 0x57, 0x9A]), service_data.byte_array) 

27 

28 def test_raw_service_data(self): 

29 data = [0x00, 0x01, 0x57, 0x9A] 

30 service_data = RawServiceData(bytes(data)) 

31 self.assertIsNone(service_data.zserio_object) 

32 self.assertEqual(bytes(data), service_data.byte_array) 

33 

34 def test_service_data(self): 

35 service_data = ServiceData() 

36 with self.assertRaises(NotImplementedError): 

37 service_data.zserio_object() 

38 with self.assertRaises(NotImplementedError): 

39 service_data.byte_array() 

40 

41 def test_service_interface(self): 

42 service_interface = ServiceInterface() 

43 with self.assertRaises(NotImplementedError): 

44 service_interface.call_method("method", bytes(), None) 

45 with self.assertRaises(NotImplementedError): 

46 service_interface.service_full_name() 

47 with self.assertRaises(NotImplementedError): 

48 service_interface.method_names() 

49 

50 def test_service_client_interface(self): 

51 service_client_interface = ServiceClientInterface() 

52 with self.assertRaises(NotImplementedError): 

53 service_client_interface.call_method("method", ObjectServiceData(None), None)