test_srcformats.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env python
  2. from base_test import DakTestCase
  3. from daklib import srcformats
  4. from collections import defaultdict
  5. from daklib.formats import parse_format
  6. from daklib.dak_exceptions import UnknownFormatError
  7. class SourceFormatTestCase(DakTestCase):
  8. def get_rejects(self, has_vars):
  9. has = defaultdict(lambda: 0)
  10. has.update(has_vars)
  11. return list(self.fmt.reject_msgs(has))
  12. def assertAccepted(self, has):
  13. self.assertEqual(self.get_rejects(has), [])
  14. def assertRejected(self, has):
  15. self.assertNotEqual(self.get_rejects(has), [])
  16. class FormatOneTestCase(SourceFormatTestCase):
  17. fmt = srcformats.FormatOne
  18. def testEmpty(self):
  19. self.assertRejected({})
  20. def testNative(self):
  21. self.assertAccepted({'native_tar': 1, 'native_tar_gz': 1})
  22. def testStandard(self):
  23. self.assertAccepted({
  24. 'orig_tar': 1,
  25. 'orig_tar_gz': 1,
  26. 'debian_diff': 1,
  27. })
  28. def testDisallowed(self):
  29. self.assertRejected({
  30. 'native_tar': 1,
  31. 'native_tar_gz': 1,
  32. 'debian_tar': 1,
  33. })
  34. self.assertRejected({
  35. 'orig_tar': 1,
  36. 'orig_tar_gz': 1,
  37. 'debian_diff': 0,
  38. })
  39. self.assertRejected({
  40. 'native_tar': 1,
  41. 'native_tar_gz': 1,
  42. 'more_orig_tar': 1,
  43. })
  44. self.assertRejected({
  45. 'native_tar': 1,
  46. 'native_tar_gz': 1,
  47. 'debian_diff': 1,
  48. })
  49. class FormatTreeTestCase(SourceFormatTestCase):
  50. fmt = srcformats.FormatThree
  51. def testEmpty(self):
  52. self.assertRejected({})
  53. def testSimple(self):
  54. self.assertAccepted({'native_tar': 1})
  55. def testDisallowed(self):
  56. self.assertRejected({'native_tar': 1, 'orig_tar': 1})
  57. self.assertRejected({'native_tar': 1, 'debian_diff': 1})
  58. self.assertRejected({'native_tar': 1, 'debian_tar': 1})
  59. self.assertRejected({'native_tar': 1, 'more_orig_tar': 1})
  60. class FormatTreeQuiltTestCase(SourceFormatTestCase):
  61. fmt = srcformats.FormatThreeQuilt
  62. def testEmpty(self):
  63. self.assertRejected({})
  64. def testSimple(self):
  65. self.assertAccepted({'orig_tar': 1, 'debian_tar': 1})
  66. def testMultipleTarballs(self):
  67. self.assertAccepted({
  68. 'orig_tar': 1,
  69. 'debian_tar': 1,
  70. 'more_orig_tar': 42,
  71. })
  72. def testDisallowed(self):
  73. self.assertRejected({
  74. 'orig_tar': 1,
  75. 'debian_tar': 1,
  76. 'debian_diff': 1
  77. })
  78. self.assertRejected({
  79. 'orig_tar': 1,
  80. 'debian_tar': 1,
  81. 'native_tar': 1,
  82. })
  83. class FormatFromStringTestCase(DakTestCase):
  84. def assertFormat(self, txt, klass):
  85. self.assertEqual(srcformats.get_format_from_string(txt), klass)
  86. def assertInvalid(self, txt):
  87. self.assertRaises(
  88. UnknownFormatError,
  89. lambda: srcformats.get_format_from_string(txt),
  90. )
  91. def testFormats(self):
  92. self.assertFormat('1.0', srcformats.FormatOne)
  93. self.assertFormat('3.0 (native)', srcformats.FormatThree)
  94. self.assertFormat('3.0 (quilt)', srcformats.FormatThreeQuilt)
  95. def testInvalidFormats(self):
  96. self.assertInvalid('')
  97. self.assertInvalid('.')
  98. self.assertInvalid('3.0 (cvs)')
  99. self.assertInvalid(' 1.0 ')
  100. self.assertInvalid('8.4 (hardy)')
  101. if __name__ == '__main__':
  102. unittest.main()