test_utils.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #! /usr/bin/env python
  2. #
  3. # Copyright (C) 2017, Niels Thykier <niels@thykier.net>
  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. import apt_pkg
  19. import unittest
  20. from base_test import DakTestCase
  21. from daklib.utils import (is_in_debug_section,
  22. parse_built_using,
  23. extract_component_from_section,
  24. ArchKey)
  25. apt_pkg.init()
  26. class UtilsTest(DakTestCase):
  27. def test_utils_ArchKey(self):
  28. source = ArchKey('source')
  29. arch1 = ArchKey('amd64')
  30. arch2 = ArchKey('i386')
  31. assert source.__eq__(source)
  32. assert not source.__lt__(source)
  33. assert arch1.__eq__(arch1)
  34. assert not arch1.__lt__(arch1)
  35. assert not source.__eq__(arch1)
  36. assert not arch1.__eq__(source)
  37. assert source.__lt__(arch1)
  38. assert not arch1.__lt__(source)
  39. assert not arch1.__eq__(arch2)
  40. assert not arch2.__eq__(arch1)
  41. assert arch1.__lt__(arch2)
  42. assert not arch2.__lt__(arch1)
  43. def test_is_in_debug_section(self):
  44. data = [
  45. (
  46. {
  47. 'Section': 'debug',
  48. 'Auto-Built-Package': 'debug-symbols',
  49. },
  50. True,
  51. ),
  52. (
  53. {
  54. 'Section': 'non-free/debug',
  55. 'Auto-Built-Package': 'debug-symbols',
  56. },
  57. True
  58. ),
  59. (
  60. {
  61. 'Section': 'debug',
  62. 'Auto-Built-Package': 'other',
  63. },
  64. False
  65. ),
  66. (
  67. {
  68. 'Section': 'non-free/debug',
  69. 'Auto-Built-Package': 'other',
  70. },
  71. False
  72. ),
  73. (
  74. {
  75. 'Section': 'debug',
  76. },
  77. False
  78. ),
  79. (
  80. {
  81. 'Section': 'non-free/debug',
  82. },
  83. False
  84. ),
  85. ]
  86. for ctrl, r in data:
  87. self.assertEqual(is_in_debug_section(ctrl), r)
  88. def test_parse_built_using(self):
  89. field = 'binutils (= 1.0-1), gcc-6 (= 6.3-2)'
  90. expected = [('binutils', '1.0-1'), ('gcc-6', '6.3-2')]
  91. ctrl = {
  92. 'Built-Using': field,
  93. }
  94. self.assertEqual(parse_built_using(ctrl), expected)
  95. self.assertEqual(parse_built_using({}), [])
  96. def test_extract_component_from_section(self):
  97. data = [
  98. # Argument is passed through as first return value. There
  99. # is a comment in docs/TODO.old suggesting that it should
  100. # be changed.
  101. ('utils', ('utils', 'main')),
  102. ('main/utils', ('main/utils', 'main')),
  103. ('non-free/libs', ('non-free/libs', 'non-free')),
  104. ('contrib/net', ('contrib/net', 'contrib')),
  105. ('non-free/two/slashes', ('non-free/two/slashes', 'non-free'))
  106. ]
  107. for v, r in data:
  108. self.assertEqual(extract_component_from_section(v), r)
  109. if __name__ == '__main__':
  110. unittest.main()