test_regexes.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. from base_test import DakTestCase
  3. from daklib import regexes
  4. class re_single_line_field(DakTestCase):
  5. MATCH = regexes.re_single_line_field.match
  6. def testSimple(self):
  7. self.assertEqual(self.MATCH('Foo: bar').groups(), ('Foo', 'bar'))
  8. def testLeadingWhitespace(self):
  9. self.assertEqual(self.MATCH(' Foo: bar'), None)
  10. def testTrailingWhitespace(self):
  11. self.assertEqual(self.MATCH('Foo: bar \n').groups(), ('Foo', 'bar '))
  12. def testMiddleWhitespace(self):
  13. self.assertEqual(self.MATCH('Foo: bar').groups(), ('Foo', 'bar'))
  14. self.assertEqual(self.MATCH('Foo : bar').groups(), ('Foo', 'bar'))
  15. self.assertEqual(self.MATCH('Foo \n:\n bar').groups(), ('Foo', 'bar'))
  16. self.assertEqual(self.MATCH('Foo:bar').groups(), ('Foo', 'bar'))
  17. def testColons(self):
  18. self.assertEqual(self.MATCH('Foo: :').groups(), ('Foo', ':'))
  19. self.assertEqual(self.MATCH('Foo: ::').groups(), ('Foo', '::'))
  20. self.assertEqual(self.MATCH(': ::').groups(), ('', '::'))
  21. self.assertEqual(self.MATCH('Foo::bar').groups(), ('Foo', ':bar'))
  22. self.assertEqual(self.MATCH('Foo: :bar').groups(), ('Foo', ':bar'))
  23. class re_parse_lintian(DakTestCase):
  24. MATCH = regexes.re_parse_lintian.match
  25. def testBinary(self):
  26. self.assertEqual(
  27. self.MATCH('W: pkgname: some-tag path/to/file').groupdict(),
  28. {
  29. 'level': 'W',
  30. 'package': 'pkgname',
  31. 'tag': 'some-tag',
  32. 'description': 'path/to/file',
  33. }
  34. )
  35. def testBinaryNoDescription(self):
  36. self.assertEqual(
  37. self.MATCH('W: pkgname: some-tag').groupdict(),
  38. {
  39. 'level': 'W',
  40. 'package': 'pkgname',
  41. 'tag': 'some-tag',
  42. 'description': '',
  43. }
  44. )
  45. def testSource(self):
  46. self.assertEqual(
  47. self.MATCH('W: pkgname source: some-tag').groupdict(),
  48. {
  49. 'level': 'W',
  50. 'package': 'pkgname source',
  51. 'tag': 'some-tag',
  52. 'description': '',
  53. }
  54. )
  55. def testSourceNoDescription(self):
  56. self.assertEqual(
  57. self.MATCH('W: pkgname source: some-tag path/to/file').groupdict(),
  58. {
  59. 'level': 'W',
  60. 'package': 'pkgname source',
  61. 'tag': 'some-tag',
  62. 'description': 'path/to/file',
  63. }
  64. )
  65. if __name__ == '__main__':
  66. unittest.main()