rpm_version_test.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import pytest
  2. import rpm_version
  3. expected_pkgs = {
  4. "spam": {
  5. "name": "spam",
  6. "version": "3.2.1",
  7. },
  8. "eggs": {
  9. "name": "eggs",
  10. "version": "3.2.1",
  11. },
  12. }
  13. @pytest.mark.parametrize('pkgs, expect_not_found', [
  14. (
  15. {},
  16. ["spam", "eggs"], # none found
  17. ),
  18. (
  19. {"spam": ["3.2.1", "4.5.1"]},
  20. ["eggs"], # completely missing
  21. ),
  22. (
  23. {
  24. "spam": ["3.2.1", "4.5.1"],
  25. "eggs": ["3.2.1"],
  26. },
  27. [], # all found
  28. ),
  29. ])
  30. def test_check_pkg_found(pkgs, expect_not_found):
  31. if expect_not_found:
  32. with pytest.raises(rpm_version.RpmVersionException) as e:
  33. rpm_version._check_pkg_versions(pkgs, expected_pkgs)
  34. assert "not found to be installed" in str(e.value)
  35. assert set(expect_not_found) == set(e.value.problem_pkgs)
  36. else:
  37. rpm_version._check_pkg_versions(pkgs, expected_pkgs)
  38. @pytest.mark.parametrize('pkgs, expect_not_found', [
  39. (
  40. {
  41. 'spam': ['3.2.1'],
  42. 'eggs': ['3.3.2'],
  43. },
  44. {
  45. "eggs": {
  46. "required_versions": ["3.2"],
  47. "found_versions": ["3.3"],
  48. }
  49. }, # not the right version
  50. ),
  51. (
  52. {
  53. 'spam': ['3.1.2', "3.3.2"],
  54. 'eggs': ['3.3.2', "1.2.3"],
  55. },
  56. {
  57. "eggs": {
  58. "required_versions": ["3.2"],
  59. "found_versions": ["3.3", "1.2"],
  60. },
  61. "spam": {
  62. "required_versions": ["3.2"],
  63. "found_versions": ["3.1", "3.3"],
  64. }
  65. }, # not the right version
  66. ),
  67. ])
  68. def test_check_pkg_version_found(pkgs, expect_not_found):
  69. if expect_not_found:
  70. with pytest.raises(rpm_version.RpmVersionException) as e:
  71. rpm_version._check_pkg_versions(pkgs, expected_pkgs)
  72. assert "found to be installed with an incorrect version" in str(e.value)
  73. assert expect_not_found == e.value.problem_pkgs
  74. else:
  75. rpm_version._check_pkg_versions(pkgs, expected_pkgs)