aos_version_test.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import pytest
  2. import aos_version
  3. from collections import namedtuple
  4. Package = namedtuple('Package', ['name', 'version'])
  5. expected_pkgs = {
  6. "spam": {
  7. "name": "spam",
  8. "version": "3.2.1",
  9. "check_multi": False,
  10. },
  11. "eggs": {
  12. "name": "eggs",
  13. "version": "3.2.1",
  14. "check_multi": False,
  15. },
  16. }
  17. @pytest.mark.parametrize('pkgs,expected_pkgs_dict', [
  18. (
  19. # all found
  20. [Package('spam', '3.2.1'), Package('eggs', '3.2.1')],
  21. expected_pkgs,
  22. ),
  23. (
  24. # found with more specific version
  25. [Package('spam', '3.2.1'), Package('eggs', '3.2.1.5')],
  26. expected_pkgs,
  27. ),
  28. (
  29. [Package('ovs', '2.6'), Package('ovs', '2.4')],
  30. {
  31. "ovs": {
  32. "name": "ovs",
  33. "version": ["2.6", "2.7"],
  34. "check_multi": False,
  35. }
  36. },
  37. ),
  38. (
  39. [Package('ovs', '2.7')],
  40. {
  41. "ovs": {
  42. "name": "ovs",
  43. "version": ["2.6", "2.7"],
  44. "check_multi": False,
  45. }
  46. },
  47. ),
  48. ])
  49. def test_check_precise_version_found(pkgs, expected_pkgs_dict):
  50. aos_version._check_precise_version_found(pkgs, expected_pkgs_dict)
  51. @pytest.mark.parametrize('pkgs,expect_not_found', [
  52. (
  53. [],
  54. {
  55. "spam": {
  56. "name": "spam",
  57. "version": "3.2.1",
  58. "check_multi": False,
  59. },
  60. "eggs": {
  61. "name": "eggs",
  62. "version": "3.2.1",
  63. "check_multi": False,
  64. }
  65. }, # none found
  66. ),
  67. (
  68. [Package('spam', '3.2.1')],
  69. {
  70. "eggs": {
  71. "name": "eggs",
  72. "version": "3.2.1",
  73. "check_multi": False,
  74. }
  75. }, # completely missing
  76. ),
  77. (
  78. [Package('spam', '3.2.1'), Package('eggs', '3.3.2')],
  79. {
  80. "eggs": {
  81. "name": "eggs",
  82. "version": "3.2.1",
  83. "check_multi": False,
  84. }
  85. }, # not the right version
  86. ),
  87. (
  88. [Package('eggs', '1.2.3'), Package('eggs', '3.2.1.5')],
  89. {
  90. "spam": {
  91. "name": "spam",
  92. "version": "3.2.1",
  93. "check_multi": False,
  94. }
  95. }, # eggs found with multiple versions
  96. ),
  97. ])
  98. def test_check_precise_version_found_fail(pkgs, expect_not_found):
  99. with pytest.raises(aos_version.PreciseVersionNotFound) as e:
  100. aos_version._check_precise_version_found(pkgs, expected_pkgs)
  101. assert list(expect_not_found.values()) == e.value.problem_pkgs
  102. @pytest.mark.parametrize('pkgs,expected_pkgs_dict', [
  103. (
  104. [],
  105. expected_pkgs,
  106. ),
  107. (
  108. # more precise but not strictly higher
  109. [Package('spam', '3.2.1.9')],
  110. expected_pkgs,
  111. ),
  112. (
  113. [Package('ovs', '2.7')],
  114. {
  115. "ovs": {
  116. "name": "ovs",
  117. "version": ["2.6", "2.7"],
  118. "check_multi": False,
  119. }
  120. },
  121. ),
  122. ])
  123. def test_check_higher_version_found(pkgs, expected_pkgs_dict):
  124. aos_version._check_higher_version_found(pkgs, expected_pkgs_dict)
  125. @pytest.mark.parametrize('pkgs,expected_pkgs_dict,expect_higher', [
  126. (
  127. [Package('spam', '3.3')],
  128. expected_pkgs,
  129. ['spam-3.3'], # lower precision, but higher
  130. ),
  131. (
  132. [Package('spam', '3.2.1'), Package('eggs', '3.3.2')],
  133. expected_pkgs,
  134. ['eggs-3.3.2'], # one too high
  135. ),
  136. (
  137. [Package('eggs', '1.2.3'), Package('eggs', '3.2.1.5'), Package('eggs', '3.4')],
  138. expected_pkgs,
  139. ['eggs-3.4'], # multiple versions, one is higher
  140. ),
  141. (
  142. [Package('eggs', '3.2.1'), Package('eggs', '3.4'), Package('eggs', '3.3')],
  143. expected_pkgs,
  144. ['eggs-3.4'], # multiple versions, two are higher
  145. ),
  146. (
  147. [Package('ovs', '2.8')],
  148. {
  149. "ovs": {
  150. "name": "ovs",
  151. "version": ["2.6", "2.7"],
  152. "check_multi": False,
  153. }
  154. },
  155. ['ovs-2.8'],
  156. ),
  157. ])
  158. def test_check_higher_version_found_fail(pkgs, expected_pkgs_dict, expect_higher):
  159. with pytest.raises(aos_version.FoundHigherVersion) as e:
  160. aos_version._check_higher_version_found(pkgs, expected_pkgs_dict)
  161. assert set(expect_higher) == set(e.value.problem_pkgs)
  162. @pytest.mark.parametrize('pkgs', [
  163. [],
  164. [Package('spam', '3.2.1')],
  165. [Package('spam', '3.2.1'), Package('eggs', '3.2.2')],
  166. ])
  167. def test_check_multi_minor_release(pkgs):
  168. aos_version._check_multi_minor_release(pkgs, expected_pkgs)
  169. @pytest.mark.parametrize('pkgs,expect_to_flag_pkgs', [
  170. (
  171. [Package('spam', '3.2.1'), Package('spam', '3.3.2')],
  172. ['spam'],
  173. ),
  174. (
  175. [Package('eggs', '1.2.3'), Package('eggs', '3.2.1.5'), Package('eggs', '3.4')],
  176. ['eggs'],
  177. ),
  178. ])
  179. def test_check_multi_minor_release_fail(pkgs, expect_to_flag_pkgs):
  180. with pytest.raises(aos_version.FoundMultiRelease) as e:
  181. aos_version._check_multi_minor_release(pkgs, expected_pkgs)
  182. assert set(expect_to_flag_pkgs) == set(e.value.problem_pkgs)