• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2025 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Tests for file_utils"""
15
16import file_utils
17import unittest
18
19
20# pylint: disable=missing-docstring
21class FileUtilsTest(unittest.TestCase):
22
23    # tests
24
25    def test_removing_markers(self):
26        lines = [
27            ";;* lms 1 test_sepolicy.cil",
28            "(type foo)",
29            ";;* lmx 1 foo.te",
30            ";;* lme",
31            ";;* lmx 1 bar.te",
32            ";;* lmx 2 bar.te",
33            ";;* lme",
34            ";;* lme",
35            ";;* lmx 3 bar.te",
36            "(allow foo self (file (read)))",
37            "(neverallow foo self (file (write)))",
38            ";;* lme",
39            ";;* lme", # lms 1 test_sepolicy.cil
40        ]
41
42        expected = [
43            ";;* lms 1 test_sepolicy.cil",
44            "(type foo)",
45            ";;* lmx 3 bar.te",
46            "(allow foo self (file (read)))",
47            "(neverallow foo self (file (write)))",
48            ";;* lme",
49            ";;* lme", # lms 1 test_sepolicy.cil
50        ]
51
52        actual = file_utils.remove_redundant_line_markers(lines)
53
54        # Line markers without any statements must be removed
55        self.assertEqual(actual, expected)
56
57
58if __name__ == '__main__':
59    unittest.main(verbosity=2)
60