test_packagelist.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #! /usr/bin/env python3
  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
  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. source_profiles = {
  55. 'Package-List':
  56. '\n pkg-a deb misc optional arch=any profile=!stage1'
  57. '\n pkg-b deb misc optional arch=any profile=!stage1,!stage2'
  58. '\n pkg-c deb misc optional arch=any profile=stage1'
  59. '\n pkg-d deb misc optional arch=any profile=stage1,stage2'
  60. '\n pkg-e deb misc optional arch=any profile=stage1+stage2'
  61. '\n pkg-f deb misc optional arch=any profile=!stage1+!stage2'
  62. '\n pkg-g deb misc optional arch=any profile=!stage1+stage2'
  63. '\n pkg-h deb misc optional arch=any profile=stage1+!stage2'
  64. '\n',
  65. 'Binary': 'pkg-a, pkg-b, pkg-c, pkg-d, pkg-e, pkg-f, pkg-g, pkg-h\n',
  66. }
  67. class TestPackageList(DakTestCase):
  68. def testArchAll(self):
  69. pl = PackageList(source_all)
  70. self.assertTrue(pl.has_arch_indep_packages())
  71. self.assertFalse(pl.has_arch_dep_packages())
  72. suite_amd64 = FakeSuite('amd64')
  73. p_amd64 = pl.packages_for_suite(suite_amd64)
  74. self.assertEqual(len(p_amd64), 0)
  75. suite_all = FakeSuite('all')
  76. p_all = pl.packages_for_suite(suite_all)
  77. self.assertEqual(len(p_all), 1)
  78. suite_all_amd64 = FakeSuite('amd64', 'all')
  79. p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
  80. self.assertEqual(len(p_all_amd64), 1)
  81. p = p_all[0]
  82. self.assertEqual(p.name, 'libdune-common-doc')
  83. self.assertEqual(p.type, 'deb')
  84. self.assertEqual(p.section, 'doc')
  85. self.assertEqual(p.component, 'main')
  86. self.assertEqual(p.priority, 'optional')
  87. self.assertEqual(p.architectures, ['all'])
  88. def testArchAny(self):
  89. pl = PackageList(source_any)
  90. self.assertFalse(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_all = FakeSuite('all')
  96. p_all = pl.packages_for_suite(suite_all)
  97. self.assertEqual(len(p_all), 0)
  98. suite_all_amd64 = FakeSuite('amd64', 'all')
  99. p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
  100. self.assertEqual(len(p_all_amd64), 1)
  101. def testArchAnyAll(self):
  102. pl = PackageList(source_all_any)
  103. self.assertTrue(pl.has_arch_indep_packages())
  104. self.assertTrue(pl.has_arch_dep_packages())
  105. suite_amd64 = FakeSuite('amd64')
  106. p_amd64 = pl.packages_for_suite(suite_amd64)
  107. self.assertEqual(len(p_amd64), 1)
  108. suite_amd64_i386 = FakeSuite('amd64', 'i386')
  109. p_amd64_i386 = pl.packages_for_suite(suite_amd64_i386)
  110. self.assertEqual(len(p_amd64_i386), 1)
  111. suite_all = FakeSuite('all')
  112. p_all = pl.packages_for_suite(suite_all)
  113. self.assertEqual(len(p_all), 1)
  114. suite_all_amd64 = FakeSuite('amd64', 'all')
  115. p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
  116. self.assertEqual(len(p_all_amd64), 2)
  117. def testArchAmd64(self):
  118. pl = PackageList(source_amd64)
  119. self.assertFalse(pl.has_arch_indep_packages())
  120. self.assertTrue(pl.has_arch_dep_packages())
  121. suite_amd64 = FakeSuite('amd64')
  122. p_amd64 = pl.packages_for_suite(suite_amd64)
  123. self.assertEqual(len(p_amd64), 1)
  124. suite_i386 = FakeSuite('i386')
  125. p_i386 = pl.packages_for_suite(suite_i386)
  126. self.assertEqual(len(p_i386), 0)
  127. def testArchLinuxAny(self):
  128. pl = PackageList(source_linuxany)
  129. self.assertFalse(pl.has_arch_indep_packages())
  130. self.assertTrue(pl.has_arch_dep_packages())
  131. suite_amd64 = FakeSuite('amd64')
  132. p_amd64 = pl.packages_for_suite(suite_amd64)
  133. self.assertEqual(len(p_amd64), 1)
  134. suite_i386 = FakeSuite('i386')
  135. p_i386 = pl.packages_for_suite(suite_i386)
  136. self.assertEqual(len(p_i386), 1)
  137. suite_kfreebsdi386 = FakeSuite('kfreebsd-i386')
  138. p_kfreebsdi386 = pl.packages_for_suite(suite_kfreebsdi386)
  139. self.assertEqual(len(p_kfreebsdi386), 0)
  140. suite_source = FakeSuite('source')
  141. p_source = pl.packages_for_suite(suite_source)
  142. self.assertEqual(len(p_source), 0)
  143. def testNoArch(self):
  144. pl = PackageList(source_noarch)
  145. self.assertIsNone(pl.has_arch_indep_packages())
  146. self.assertIsNone(pl.has_arch_dep_packages())
  147. suite_amd64 = FakeSuite('amd64')
  148. p_amd64 = pl.packages_for_suite(suite_amd64)
  149. self.assertEqual(len(p_amd64), 1)
  150. def testFallback(self):
  151. pl = PackageList(source_fallback)
  152. self.assertIsNone(pl.has_arch_indep_packages())
  153. self.assertIsNone(pl.has_arch_dep_packages())
  154. suite_amd64 = FakeSuite('amd64')
  155. p_amd64 = pl.packages_for_suite(suite_amd64)
  156. self.assertEqual(len(p_amd64), 1)
  157. def testProfiles(self):
  158. pl = PackageList(source_profiles)
  159. self.assertEqual(len(pl.package_list), 8)
  160. built_in_default_profile = {'pkg-a', 'pkg-b', 'pkg-f', 'pkg-g', 'pkg-h'}
  161. not_built_in_default_profile = {'pkg-c', 'pkg-d', 'pkg-e'}
  162. for entry in pl.package_list:
  163. if entry.built_in_default_profile():
  164. self.assertIn(entry.name, built_in_default_profile)
  165. else:
  166. self.assertIn(entry.name, not_built_in_default_profile)
  167. suite_amd64 = FakeSuite('amd64')
  168. ps_only_default = pl.packages_for_suite(suite_amd64)
  169. ps_all = pl.packages_for_suite(suite_amd64, only_default_profile=False)
  170. self.assertSetEqual({p.name for p in ps_only_default}, built_in_default_profile)
  171. self.assertSetEqual({p.name for p in ps_all}, built_in_default_profile | not_built_in_default_profile)
  172. if __name__ == '__main__':
  173. unittest.main()