1# Copyright 2023 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 15import pkgutil 16import unittest 17import xml.etree.ElementTree 18 19class TestLinterReports(unittest.TestCase): 20 """Integration tests for the linters used by @EnforcePermission.""" 21 22 def _read_report(self, pkg_path): 23 report = pkgutil.get_data(pkg_path, "lint/lint-report.xml").decode() 24 issues = xml.etree.ElementTree.fromstring(report) 25 self.assertEqual(issues.tag, "issues") 26 return issues 27 28 def test_no_aidl(self): 29 issues = self._read_report("no_aidl") 30 self.assertEqual(len(issues), 1) 31 32 issue = issues[0] 33 self.assertEqual(issue.attrib["id"], "MisusingEnforcePermissionAnnotation") 34 self.assertEqual(issue.attrib["severity"], "Error") 35 36 def test_missing_annotation(self): 37 issues = self._read_report("missing_annotation") 38 self.assertEqual(len(issues), 1) 39 40 issue = issues[0] 41 self.assertEqual(issue.attrib["id"], "MissingEnforcePermissionAnnotation") 42 self.assertEqual(issue.attrib["severity"], "Error") 43 44 45if __name__ == '__main__': 46 unittest.main(verbosity=2) 47