Coverage for test/d7a/sp/test_qos.py: 91%

23 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-24 08:03 +0200

1# 

2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV. 

3# 

4# This file is part of pyd7a. 

5# See https://github.com/Sub-IoT/pyd7a for further info. 

6# 

7# Licensed under the Apache License, Version 2.0 (the "License"); 

8# you may not use this file except in compliance with the License. 

9# You may obtain a copy of the License at 

10# 

11# http://www.apache.org/licenses/LICENSE-2.0 

12# 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, 

15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

16# See the License for the specific language governing permissions and 

17# limitations under the License. 

18# 

19 

20# author: Christophe VG <contact@christophe.vg> 

21# unit tests for the D7A SP QoS Paramters  

22 

23import unittest 

24 

25from bitstring import ConstBitStream 

26 

27from d7a.sp.qos import QoS, ResponseMode, RetryMode 

28 

29 

30class TestQoS(unittest.TestCase): 

31 def test_default_constructor(self): 

32 qos = QoS() 

33 

34 def test_byte_generation(self): 

35 bytes = bytearray(QoS()) 

36 self.assertEqual(len(bytes), 1) 

37 self.assertEqual(bytes[0], int('00000000', 2)) 

38 

39 bytes = bytearray(QoS( 

40 retry_mod = RetryMode.RETRY_MODE_NO, 

41 resp_mod = ResponseMode.RESP_MODE_ANY, 

42 record=True, 

43 stop_on_err=True, 

44 )) 

45 self.assertEqual(len(bytes), 1) 

46 self.assertEqual(bytes[0], int('11000010', 2)) 

47 

48 def test_parse(self): 

49 bytes = [ 

50 0b11000010 

51 ] 

52 

53 qos = QoS.parse(ConstBitStream(bytes=bytes)) 

54 

55 self.assertEqual(qos.retry_mod, RetryMode.RETRY_MODE_NO) 

56 self.assertEqual(qos.resp_mod, ResponseMode.RESP_MODE_ANY) 

57 self.assertEqual(qos.record, True) 

58 self.assertEqual(qos.stop_on_err, True) 

59 

60if __name__ == '__main__': 

61 suite = unittest.TestLoader().loadTestsFromTestCase(TestQoS) 

62 unittest.TextTestRunner(verbosity=2).run(suite)