test_lintian.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #! /usr/bin/env python3
  2. from base_test import DakTestCase
  3. import unittest
  4. from daklib.lintian import parse_lintian_output, generate_reject_messages
  5. class ParseLintianTestCase(DakTestCase):
  6. def assertParse(self, output, expected):
  7. self.assertEqual(
  8. list(parse_lintian_output(output)),
  9. expected,
  10. )
  11. def testSimple(self):
  12. self.assertParse(
  13. 'W: pkgname: some-tag path/to/file', [{
  14. 'level': 'W',
  15. 'package': 'pkgname',
  16. 'tag': 'some-tag',
  17. 'description': 'path/to/file',
  18. }],
  19. )
  20. self.assertParse('', [])
  21. self.assertParse('\n\n', [])
  22. self.assertParse('dummy error test', [])
  23. def testBinaryNoDescription(self):
  24. self.assertParse(
  25. 'W: pkgname: some-tag', [{
  26. 'level': 'W',
  27. 'package': 'pkgname',
  28. 'tag': 'some-tag',
  29. 'description': '',
  30. }],
  31. )
  32. def testSource(self):
  33. self.assertParse(
  34. 'W: pkgname source: some-tag', [{
  35. 'level': 'W',
  36. 'package': 'pkgname source',
  37. 'tag': 'some-tag',
  38. 'description': '',
  39. }]
  40. )
  41. def testSourceNoDescription(self):
  42. self.assertParse(
  43. 'W: pkgname source: some-tag path/to/file', [{
  44. 'level': 'W',
  45. 'package': 'pkgname source',
  46. 'tag': 'some-tag',
  47. 'description': 'path/to/file',
  48. }]
  49. )
  50. class GenerateRejectMessages(DakTestCase):
  51. def assertNumReject(self, input, defs, num):
  52. msgs = list(generate_reject_messages(input, defs))
  53. self.assertEqual(len(msgs), num)
  54. def testUnknownTag(self):
  55. self.assertNumReject([
  56. {
  57. 'level': 'W',
  58. 'package': 'pkgname',
  59. 'tag': 'unknown-tag',
  60. 'description': '',
  61. }],
  62. {'fatal': ['known-tag'], 'nonfatal': []},
  63. 0,
  64. )
  65. def testFatalTags(self):
  66. self.assertNumReject([
  67. {
  68. 'level': 'W',
  69. 'package': 'pkgname',
  70. 'tag': 'fatal-tag-1',
  71. 'description': '',
  72. },
  73. {
  74. 'level': 'W',
  75. 'package': 'pkgname',
  76. 'tag': 'fatal-tag-2',
  77. 'description': '',
  78. }],
  79. {'fatal': ['fatal-tag-1', 'fatal-tag-2'], 'nonfatal': []},
  80. 2,
  81. )
  82. def testMixture(self):
  83. self.assertNumReject([
  84. {
  85. 'level': 'W',
  86. 'package': 'pkgname',
  87. 'tag': 'fatal-tag',
  88. 'description': '',
  89. },
  90. {
  91. 'level': 'W',
  92. 'package': 'pkgname',
  93. 'tag': 'unknown-tag',
  94. 'description': '',
  95. }],
  96. {'fatal': ['fatal-tag'], 'nonfatal': []},
  97. 1,
  98. )
  99. def testOverridable(self):
  100. self.assertNumReject([
  101. {
  102. 'level': 'W',
  103. 'package': 'pkgname',
  104. 'tag': 'non-fatal-tag',
  105. 'description': '',
  106. }],
  107. {'fatal': [], 'nonfatal': ['non-fatal-tag']},
  108. 1 + 1, # We add an extra 'reject' hint message
  109. )
  110. def testOverrideAllowed(self):
  111. self.assertNumReject([
  112. {
  113. 'level': 'O',
  114. 'package': 'pkgname',
  115. 'tag': 'non-fatal-tag',
  116. 'description': ''
  117. }],
  118. {'fatal': [], 'nonfatal': ['non-fatal-tag']},
  119. 0,
  120. )
  121. def testOverrideNotAllowed(self):
  122. self.assertNumReject([
  123. {
  124. 'level': 'O',
  125. 'package': 'pkgname',
  126. 'tag': 'fatal-tag',
  127. 'description': '',
  128. }],
  129. {'fatal': ['fatal-tag'], 'nonfatal': []},
  130. 1,
  131. )
  132. if __name__ == '__main__':
  133. unittest.main()