test_parse_changes.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #! /usr/bin/env python3
  2. from base_test import DakTestCase, fixture
  3. import unittest
  4. from daklib.gpg import GpgException
  5. from daklib.utils import parse_changes, check_dsc_files, build_file_list
  6. from daklib.dak_exceptions import ParseChangesError
  7. class ParseChangesTestCase(DakTestCase):
  8. def assertParse(self, filename, *args):
  9. return parse_changes(fixture(filename), *args)
  10. class ParseDscTestCase(ParseChangesTestCase):
  11. def test_1(self):
  12. changes = self.assertParse('dsc/1.dsc', -1, 1)
  13. files = build_file_list(changes, True)
  14. rejmsg = check_dsc_files('1.dsc', changes, files.keys())
  15. self.assertEqual(rejmsg, [])
  16. def test_1_ignoreErrors(self):
  17. # Valid .dsc ; ignoring errors
  18. self.assertParse('dsc/1.dsc', -1, True)
  19. def test_2(self):
  20. # Missing blank line before signature body
  21. self.assertParse('dsc/2.dsc', -1, True)
  22. def test_2_ignoreErrors(self):
  23. # Invalid .dsc ; ignoring errors
  24. self.assertParse('dsc/2.dsc', -1, True)
  25. def test_3(self):
  26. # Missing blank line after signature header
  27. self.assertParse('dsc/3.dsc', -1, True)
  28. def test_4(self):
  29. # No blank lines at all
  30. with self.assertRaises(GpgException):
  31. self.assertParse('dsc/4.dsc', -1, True)
  32. def test_5(self):
  33. # Extra blank line before signature body
  34. self.assertParse('dsc/5.dsc', -1, True)
  35. def test_6(self):
  36. # Extra blank line after signature header
  37. self.assertParse('dsc/6.dsc', -1, True)
  38. def test_7(self):
  39. # Blank file is an invalid armored GPG file
  40. with self.assertRaises(GpgException):
  41. self.assertParse('dsc/7.dsc', -1, True)
  42. def test_8(self):
  43. # No armored contents
  44. with self.assertRaisesRegex(ParseChangesError, "Empty changes"):
  45. self.assertParse('dsc/8.dsc', -1, True)
  46. def test_9(self):
  47. changes = self.assertParse('dsc/9.dsc', -1, True)
  48. self.assertTrue(changes['question'] == 'Is this a bug?')
  49. self.assertFalse(changes.get('this'))
  50. def test_10(self):
  51. changes = self.assertParse('dsc/10.dsc', -1, True)
  52. files = build_file_list(changes, True)
  53. rejmsg = check_dsc_files('10.dsc', changes, files.keys())
  54. self.assertEqual(rejmsg, [])
  55. class ParseChangesTestCase(ParseChangesTestCase):
  56. def test_1(self):
  57. # Empty changes
  58. with self.assertRaises(GpgException):
  59. self.assertParse('changes/1.changes', 1)
  60. def test_2(self):
  61. changes = self.assertParse('changes/2.changes', -1)
  62. binaries = changes['binary']
  63. self.assertTrue('krb5-ftpd' in binaries.split())
  64. def test_3(self):
  65. for filename in ('valid', 'bogus-pre', 'bogus-post'):
  66. for strict_whitespace in (-1,):
  67. changes = self.assertParse(
  68. 'changes/%s.changes' % filename,
  69. strict_whitespace,
  70. )
  71. self.assertFalse(changes.get('you'))
  72. if __name__ == '__main__':
  73. unittest.main()