Coverage for test/d7a/system_files/test_vid.py: 100%
24 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« 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
21from bitstring import ConstBitStream
23from d7a.system_files.vid import VidFile
25class TestVidFile(unittest.TestCase):
27 def test_default_constructor(self):
28 c = VidFile()
29 self.assertEqual(c.vid, 0xFFFF)
30 self.assertEqual(c.control, 0)
33 def test_parsing(self):
34 file_contents = [
35 0x05, 0x03, # VID
36 0x65, # Control
37 ]
39 config = VidFile.parse(ConstBitStream(bytes=file_contents))
40 self.assertEqual(config.vid, 0x0503)
41 self.assertEqual(config.control, 0x65)
43 def test_byte_generation(self):
44 bytes = bytearray(VidFile())
45 self.assertEqual(len(bytes), 3)
46 self.assertEqual(bytes[0], 0xFF)
47 self.assertEqual(bytes[1], 0xFF)
48 self.assertEqual(bytes[2], 0)
50 bytes = bytearray(VidFile(vid=0x4536, control=0x12))
51 self.assertEqual(len(bytes), 3)
52 self.assertEqual(bytes[0], 0x45)
53 self.assertEqual(bytes[1], 0x36)
54 self.assertEqual(bytes[2], 0x12)