aos_version_test.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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', [
  18. # all found
  19. [Package('spam', '3.2.1'), Package('eggs', '3.2.1')],
  20. # found with more specific version
  21. [Package('spam', '3.2.1'), Package('eggs', '3.2.1.5')],
  22. ])
  23. def test_check_precise_version_found(pkgs):
  24. aos_version._check_precise_version_found(pkgs, expected_pkgs)
  25. @pytest.mark.parametrize('pkgs,expect_not_found', [
  26. (
  27. [],
  28. {
  29. "spam": {
  30. "name": "spam",
  31. "version": "3.2.1",
  32. "check_multi": False,
  33. },
  34. "eggs": {
  35. "name": "eggs",
  36. "version": "3.2.1",
  37. "check_multi": False,
  38. }
  39. }, # none found
  40. ),
  41. (
  42. [Package('spam', '3.2.1')],
  43. {
  44. "eggs": {
  45. "name": "eggs",
  46. "version": "3.2.1",
  47. "check_multi": False,
  48. }
  49. }, # completely missing
  50. ),
  51. (
  52. [Package('spam', '3.2.1'), Package('eggs', '3.3.2')],
  53. {
  54. "eggs": {
  55. "name": "eggs",
  56. "version": "3.2.1",
  57. "check_multi": False,
  58. }
  59. }, # not the right version
  60. ),
  61. (
  62. [Package('eggs', '1.2.3'), Package('eggs', '3.2.1.5')],
  63. {
  64. "spam": {
  65. "name": "spam",
  66. "version": "3.2.1",
  67. "check_multi": False,
  68. }
  69. }, # eggs found with multiple versions
  70. ),
  71. ])
  72. def test_check_precise_version_found_fail(pkgs, expect_not_found):
  73. with pytest.raises(aos_version.PreciseVersionNotFound) as e:
  74. aos_version._check_precise_version_found(pkgs, expected_pkgs)
  75. assert list(expect_not_found.values()) == e.value.problem_pkgs
  76. @pytest.mark.parametrize('pkgs', [
  77. [],
  78. # more precise but not strictly higher
  79. [Package('spam', '3.2.1.9')],
  80. ])
  81. def test_check_higher_version_found(pkgs):
  82. aos_version._check_higher_version_found(pkgs, expected_pkgs)
  83. @pytest.mark.parametrize('pkgs,expect_higher', [
  84. (
  85. [Package('spam', '3.3')],
  86. ['spam-3.3'], # lower precision, but higher
  87. ),
  88. (
  89. [Package('spam', '3.2.1'), Package('eggs', '3.3.2')],
  90. ['eggs-3.3.2'], # one too high
  91. ),
  92. (
  93. [Package('eggs', '1.2.3'), Package('eggs', '3.2.1.5'), Package('eggs', '3.4')],
  94. ['eggs-3.4'], # multiple versions, one is higher
  95. ),
  96. (
  97. [Package('eggs', '3.2.1'), Package('eggs', '3.4'), Package('eggs', '3.3')],
  98. ['eggs-3.4'], # multiple versions, two are higher
  99. ),
  100. ])
  101. def test_check_higher_version_found_fail(pkgs, expect_higher):
  102. with pytest.raises(aos_version.FoundHigherVersion) as e:
  103. aos_version._check_higher_version_found(pkgs, expected_pkgs)
  104. assert set(expect_higher) == set(e.value.problem_pkgs)
  105. @pytest.mark.parametrize('pkgs', [
  106. [],
  107. [Package('spam', '3.2.1')],
  108. [Package('spam', '3.2.1'), Package('eggs', '3.2.2')],
  109. ])
  110. def test_check_multi_minor_release(pkgs):
  111. aos_version._check_multi_minor_release(pkgs, expected_pkgs)
  112. @pytest.mark.parametrize('pkgs,expect_to_flag_pkgs', [
  113. (
  114. [Package('spam', '3.2.1'), Package('spam', '3.3.2')],
  115. ['spam'],
  116. ),
  117. (
  118. [Package('eggs', '1.2.3'), Package('eggs', '3.2.1.5'), Package('eggs', '3.4')],
  119. ['eggs'],
  120. ),
  121. ])
  122. def test_check_multi_minor_release_fail(pkgs, expect_to_flag_pkgs):
  123. with pytest.raises(aos_version.FoundMultiRelease) as e:
  124. aos_version._check_multi_minor_release(pkgs, expected_pkgs)
  125. assert set(expect_to_flag_pkgs) == set(e.value.problem_pkgs)