test_parse_changes.py 2.6 KB

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