1#!/usr/bin/env python3
2#
3# Copyright (C) 2021 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18"""Unit tests for lint_project_xml.py."""
19
20import unittest
21from xml.dom import minidom
22
23import lint_project_xml
24
25
26class CheckBaselineForDisallowedIssuesTest(unittest.TestCase):
27  """Unit tests for check_baseline_for_disallowed_issues function."""
28
29  baseline_xml = minidom.parseString(
30      '<?xml version="1.0" encoding="utf-8"?>\n'
31      '<issues format="5" by="lint 4.1.0" client="cli" variant="all" version="4.1.0">\n'
32      '    <issue id="foo" message="foo is evil" errorLine1="foo()">\n'
33      '        <location file="a/b/c.java" line="3" column="10"/>\n'
34      '    </issue>\n'
35      '    <issue id="bar" message="bar is known to be evil" errorLine1="bar()">\n'
36      '        <location file="a/b/c.java" line="5" column="12"/>\n'
37      '    </issue>\n'
38      '    <issue id="baz" message="baz may be evil" errorLine1="a = baz()">\n'
39      '        <location file="a/b/c.java" line="10" column="10"/>\n'
40      '    </issue>\n'
41      '    <issue id="foo" message="foo is evil" errorLine1="b = foo()">\n'
42      '        <location file="a/d/e.java" line="100" column="4"/>\n'
43      '    </issue>\n'
44      '</issues>\n')
45
46  def test_check_baseline_for_disallowed_issues(self):
47    disallowed_issues = lint_project_xml.check_baseline_for_disallowed_issues(self.baseline_xml, ["foo", "bar", "qux"])
48    self.assertEqual({"foo", "bar"}, disallowed_issues)
49
50
51if __name__ == '__main__':
52  unittest.main(verbosity=2)
53