test_srcformats.py 3.4 KB

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