test_packagelist.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #! /usr/bin/python
  2. #
  3. # Copyright (C) 2014, Ansgar Burchardt <ansgar@debian.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. from base_test import DakTestCase
  19. import unittest
  20. from daklib.packagelist import PackageList, InvalidSource
  21. class FakeArchitecture(object):
  22. def __init__(self, name):
  23. self.arch_string = name
  24. class FakeSuite(object):
  25. def __init__(self, *architectures):
  26. self.architectures = [ FakeArchitecture(a) for a in architectures ]
  27. source_all = {
  28. 'Package-List': '\n libdune-common-doc deb doc optional arch=all\n',
  29. 'Binary': 'libdune-common-doc\n',
  30. }
  31. source_any = {
  32. 'Package-List': '\n libdune-common-dev deb libdevel optional arch=any\n',
  33. 'Binary': 'libdune-common-dev\n',
  34. }
  35. source_all_any = {
  36. 'Package-List': '\n libdune-common-dev deb libdevel optional arch=any\nlibdune-common-doc deb doc optional arch=all\n',
  37. 'Binary': 'libdune-common-dev, libdune-common-doc\n',
  38. }
  39. source_amd64 = {
  40. 'Package-List': '\n libdune-common-dev deb libdevel optional arch=amd64\n',
  41. 'Binary': 'libdune-common-dev\n',
  42. }
  43. source_linuxany = {
  44. 'Package-List': '\n libdune-common-dev deb libdevel optional arch=linux-any\n',
  45. 'Binary': 'libdune-common-dev\n',
  46. }
  47. source_noarch = {
  48. 'Package-List': '\n libdune-common-dev deb libdevel optional\n',
  49. 'Binary': 'libdune-common-dev\n',
  50. }
  51. source_fallback = {
  52. 'Binary': 'libdune-common-dev\n',
  53. }
  54. class TestPackageList(DakTestCase):
  55. def testArchAll(self):
  56. pl = PackageList(source_all)
  57. self.assertTrue(pl.has_arch_indep_packages())
  58. self.assertFalse(pl.has_arch_dep_packages())
  59. suite_amd64 = FakeSuite('amd64')
  60. p_amd64 = pl.packages_for_suite(suite_amd64)
  61. self.assertEqual(len(p_amd64), 0)
  62. suite_all = FakeSuite('all')
  63. p_all = pl.packages_for_suite(suite_all)
  64. self.assertEqual(len(p_all), 1)
  65. suite_all_amd64 = FakeSuite('amd64', 'all')
  66. p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
  67. self.assertEqual(len(p_all_amd64), 1)
  68. p = p_all[0]
  69. self.assertEqual(p.name, 'libdune-common-doc')
  70. self.assertEqual(p.type, 'deb')
  71. self.assertEqual(p.section, 'doc')
  72. self.assertEqual(p.component, 'main')
  73. self.assertEqual(p.priority, 'optional')
  74. self.assertEqual(p.architectures, ['all'])
  75. def testArchAny(self):
  76. pl = PackageList(source_any)
  77. self.assertFalse(pl.has_arch_indep_packages())
  78. self.assertTrue(pl.has_arch_dep_packages())
  79. suite_amd64 = FakeSuite('amd64')
  80. p_amd64 = pl.packages_for_suite(suite_amd64)
  81. self.assertEqual(len(p_amd64), 1)
  82. suite_all = FakeSuite('all')
  83. p_all = pl.packages_for_suite(suite_all)
  84. self.assertEqual(len(p_all), 0)
  85. suite_all_amd64 = FakeSuite('amd64', 'all')
  86. p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
  87. self.assertEqual(len(p_all_amd64), 1)
  88. def testArchAnyAll(self):
  89. pl = PackageList(source_all_any)
  90. self.assertTrue(pl.has_arch_indep_packages())
  91. self.assertTrue(pl.has_arch_dep_packages())
  92. suite_amd64 = FakeSuite('amd64')
  93. p_amd64 = pl.packages_for_suite(suite_amd64)
  94. self.assertEqual(len(p_amd64), 1)
  95. suite_amd64_i386 = FakeSuite('amd64', 'i386')
  96. p_amd64_i386 = pl.packages_for_suite(suite_amd64_i386)
  97. self.assertEqual(len(p_amd64_i386), 1)
  98. suite_all = FakeSuite('all')
  99. p_all = pl.packages_for_suite(suite_all)
  100. self.assertEqual(len(p_all), 1)
  101. suite_all_amd64 = FakeSuite('amd64', 'all')
  102. p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
  103. self.assertEqual(len(p_all_amd64), 2)
  104. def testArchAmd64(self):
  105. pl = PackageList(source_amd64)
  106. self.assertFalse(pl.has_arch_indep_packages())
  107. self.assertTrue(pl.has_arch_dep_packages())
  108. suite_amd64 = FakeSuite('amd64')
  109. p_amd64 = pl.packages_for_suite(suite_amd64)
  110. self.assertEqual(len(p_amd64), 1)
  111. suite_i386 = FakeSuite('i386')
  112. p_i386 = pl.packages_for_suite(suite_i386)
  113. self.assertEqual(len(p_i386), 0)
  114. def testArchLinuxAny(self):
  115. pl = PackageList(source_linuxany)
  116. self.assertFalse(pl.has_arch_indep_packages())
  117. self.assertTrue(pl.has_arch_dep_packages())
  118. suite_amd64 = FakeSuite('amd64')
  119. p_amd64 = pl.packages_for_suite(suite_amd64)
  120. self.assertEqual(len(p_amd64), 1)
  121. suite_i386 = FakeSuite('i386')
  122. p_i386 = pl.packages_for_suite(suite_i386)
  123. self.assertEqual(len(p_i386), 1)
  124. suite_kfreebsdi386 = FakeSuite('kfreebsd-i386')
  125. p_kfreebsdi386 = pl.packages_for_suite(suite_kfreebsdi386)
  126. self.assertEqual(len(p_kfreebsdi386), 0)
  127. suite_source = FakeSuite('source')
  128. p_source = pl.packages_for_suite(suite_source)
  129. self.assertEqual(len(p_source), 0)
  130. def testNoArch(self):
  131. pl = PackageList(source_noarch)
  132. self.assertIsNone(pl.has_arch_indep_packages())
  133. self.assertIsNone(pl.has_arch_dep_packages())
  134. suite_amd64 = FakeSuite('amd64')
  135. p_amd64 = pl.packages_for_suite(suite_amd64)
  136. self.assertEqual(len(p_amd64), 1)
  137. def testFallback(self):
  138. pl = PackageList(source_fallback)
  139. self.assertIsNone(pl.has_arch_indep_packages())
  140. self.assertIsNone(pl.has_arch_dep_packages())
  141. suite_amd64 = FakeSuite('amd64')
  142. p_amd64 = pl.packages_for_suite(suite_amd64)
  143. self.assertEqual(len(p_amd64), 1)
  144. if __name__ == '__main__':
  145. unittest.main()