Coverage for test/d7a/dll/test_sub_profile.py: 100%

24 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# 

19import unittest 

20 

21from bitstring import ConstBitStream 

22from d7a.dll.sub_profile import SubProfile 

23from d7a.types.ct import CT 

24 

25 

26class TestSubProfile(unittest.TestCase): 

27 

28 def test_default_constructor(self): 

29 sp = SubProfile() 

30 self.assertEqual(sp.subband_bitmap, 0x00) 

31 ct = CT() 

32 self.assertEqual(sp.scan_automation_period.mant, ct.mant) 

33 self.assertEqual(sp.scan_automation_period.exp, ct.exp) 

34 

35 def test_byte_generation(self): 

36 expected = [ 

37 0b10000001, # subband bitmap 

38 0, # scan automation period 

39 ] 

40 

41 sp = SubProfile(subband_bitmap=0b10000001, scan_automation_period=CT(0)) 

42 bytes = bytearray(sp) 

43 for i in range(len(bytes)): 

44 self.assertEqual(expected[i], bytes[i]) 

45 

46 self.assertEqual(len(expected), len(bytes)) 

47 

48 def test_parse(self): 

49 bytes = [ 

50 0b10000001, # subband bitmap 

51 0, # scan automation period 

52 ] 

53 

54 sp = SubProfile.parse(ConstBitStream(bytes=bytes)) 

55 self.assertEqual(sp.subband_bitmap, 0b10000001) 

56 self.assertEqual(sp.scan_automation_period.mant, CT(0).mant) 

57 self.assertEqual(sp.scan_automation_period.exp, CT(0).exp)