Coverage for test/d7a/alp/operations/test_responses.py: 92%

25 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 D7A ALP responses 

22 

23import unittest 

24 

25from d7a.alp.operations.responses import ReturnFileData 

26from d7a.alp.operands.file import Data 

27 

28class TestReturnFileData(unittest.TestCase): 

29 def test_constructor_and_op_code(self): 

30 data = Data([0x01, 0x02, 0x03, 0x04]) 

31 rfd = ReturnFileData(operand=data) 

32 self.assertEqual(rfd.op, 32) 

33 self.assertIs(rfd.operand, data) 

34 self.assertEqual(rfd.operand.length.value, 4) 

35 

36 def test_byte_generation(self): 

37 data = Data([0x01, 0x02, 0x03, 0x04]) 

38 rfd = ReturnFileData(operand=data) 

39 bytes = bytearray(rfd) 

40 self.assertEqual(len(bytes), 7) 

41 self.assertEqual(bytes[0], int('00000000', 2)) # offset 

42 self.assertEqual(bytes[1], int('00000000', 2)) # offset 

43 self.assertEqual(bytes[2], int('00000100', 2)) # length = 4 

44 self.assertEqual(bytes[3], int('00000001', 2)) 

45 self.assertEqual(bytes[4], int('00000010', 2)) 

46 self.assertEqual(bytes[5], int('00000011', 2)) 

47 self.assertEqual(bytes[6], int('00000100', 2)) 

48 

49if __name__ == '__main__': 

50 suite = unittest.TestLoader().loadTestsFromTestCase(TestNoOperation) 

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