lint_project_xml_test.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. """Unit tests for lint_project_xml.py."""
  18. import unittest
  19. from xml.dom import minidom
  20. import lint_project_xml
  21. class CheckBaselineForDisallowedIssuesTest(unittest.TestCase):
  22. """Unit tests for check_baseline_for_disallowed_issues function."""
  23. baseline_xml = minidom.parseString(
  24. '<?xml version="1.0" encoding="utf-8"?>\n'
  25. '<issues format="5" by="lint 4.1.0" client="cli" variant="all" version="4.1.0">\n'
  26. ' <issue id="foo" message="foo is evil" errorLine1="foo()">\n'
  27. ' <location file="a/b/c.java" line="3" column="10"/>\n'
  28. ' </issue>\n'
  29. ' <issue id="bar" message="bar is known to be evil" errorLine1="bar()">\n'
  30. ' <location file="a/b/c.java" line="5" column="12"/>\n'
  31. ' </issue>\n'
  32. ' <issue id="baz" message="baz may be evil" errorLine1="a = baz()">\n'
  33. ' <location file="a/b/c.java" line="10" column="10"/>\n'
  34. ' </issue>\n'
  35. ' <issue id="foo" message="foo is evil" errorLine1="b = foo()">\n'
  36. ' <location file="a/d/e.java" line="100" column="4"/>\n'
  37. ' </issue>\n'
  38. '</issues>\n')
  39. def test_check_baseline_for_disallowed_issues(self):
  40. disallowed_issues = lint_project_xml.check_baseline_for_disallowed_issues(self.baseline_xml, ["foo", "bar", "qux"])
  41. self.assertEqual({"foo", "bar"}, disallowed_issues)
  42. if __name__ == '__main__':
  43. unittest.main(verbosity=2)