Coverage for test/d7a/fs/test_file_permissions.py: 100%
19 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.fs.file_permissions import FilePermissions
26class TestPermission(unittest.TestCase):
28 def test_parsing(self):
29 permission_bytes = [
30 0xFC
31 ]
33 permission = FilePermissions.parse(ConstBitStream(bytes=permission_bytes))
35 self.assertEqual(permission.encrypted, True)
36 self.assertEqual(permission.executable, True)
37 self.assertEqual(permission.user_readable, True)
38 self.assertEqual(permission.user_writable, True)
39 self.assertEqual(permission.user_executable, True)
40 self.assertEqual(permission.guest_readable, True)
41 self.assertEqual(permission.guest_writable, False)
42 self.assertEqual(permission.guest_executable, False)
44 def test_byte_generation(self):
45 p = FilePermissions(encrypted=True, executable=True, user_readable=True, user_writable=True, user_executable=True,
46 guest_readable=True, guest_writable=False, guest_executable=False)
47 bytes = bytearray(p)
48 self.assertEqual(bytes, bytearray([0xFC]))