test_pipeline_utils.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import pytest
  7. import functools
  8. import ly_test_tools.o3de.pipeline_utils as pipeline_utils
  9. pytestmark = pytest.mark.SUITE_smoke
  10. def lists_are_equal(first_list, second_list):
  11. first_list.sort()
  12. second_list.sort()
  13. return functools.reduce(lambda x, y : x and y, map(lambda p, q: p == q, first_list, second_list))
  14. class TestPipelineUtils(object):
  15. def test_ListDiff_EmptyLists_ReturnsEmptyLists(self):
  16. first_list = []
  17. second_list = []
  18. diff_first, diff_second = pipeline_utils.get_differences_between_lists(first_list, second_list)
  19. assert len(diff_first) == 0
  20. assert len(diff_first) == len(diff_second)
  21. def test_ListDiff_SecondListNotEmpty_ReturnsContentsOfFirstList(self):
  22. first_list = ["SomeEntry"]
  23. second_list = []
  24. diff_first, diff_second = pipeline_utils.get_differences_between_lists(first_list, second_list)
  25. assert len(diff_first) == 1
  26. assert len(diff_second) == 0
  27. assert lists_are_equal(diff_first, first_list)
  28. def test_ListDiff_IdenticalListsSameOrder_ReturnsEmptyLists(self):
  29. first_list = ["SomeEntry", "AnotherEntry"]
  30. second_list = ["SomeEntry", "AnotherEntry"]
  31. diff_first, diff_second = pipeline_utils.get_differences_between_lists(first_list, second_list)
  32. assert len(diff_first) == 0
  33. assert len(diff_first) == len(diff_second)
  34. def test_ListDiff_IdenticalListsDifferentOrder_ReturnsEmptyLists(self):
  35. first_list = ["OutOfOrderEntry", "SomeEntry", "AnotherEntry"]
  36. second_list = ["SomeEntry", "AnotherEntry", "OutOfOrderEntry"]
  37. diff_first, diff_second = pipeline_utils.get_differences_between_lists(first_list, second_list)
  38. assert len(diff_first) == 0
  39. assert len(diff_first) == len(diff_second)
  40. def test_ListDiff_DifferentLists_ReturnsDifferences(self):
  41. first_list = [ "ListOneUniqueEntry", "OutOfOrderEntry", "SomeEntry", "AnotherEntry"]
  42. second_list = ["SomeEntry", "AnotherEntry", "ListTwoUniqueEntry", "OutOfOrderEntry", "SecondUniqueEntry"]
  43. diff_first, diff_second = pipeline_utils.get_differences_between_lists(first_list, second_list)
  44. assert lists_are_equal(diff_first, ["ListOneUniqueEntry"])
  45. assert lists_are_equal(diff_second, ["ListTwoUniqueEntry", "SecondUniqueEntry"])
  46. def test_ListCompare_EmptyLists_ReturnsTrue(self):
  47. first_list = []
  48. second_list = []
  49. assert pipeline_utils.compare_lists(first_list, second_list) == True
  50. def test_ListCompare_SecondListNotEmpty_ReturnsFalse(self):
  51. first_list = ["SomeEntry"]
  52. second_list = []
  53. assert pipeline_utils.compare_lists(first_list, second_list) == False
  54. def test_ListCompare_IdenticalListsSameOrder_ReturnsTrue(self):
  55. first_list = ["SomeEntry", "AnotherEntry"]
  56. second_list = ["SomeEntry", "AnotherEntry"]
  57. assert pipeline_utils.compare_lists(first_list, second_list) == True
  58. def test_ListCompare_IdenticalListsDifferentOrder_ReturnsTrue(self):
  59. first_list = ["OutOfOrderEntry", "SomeEntry", "AnotherEntry"]
  60. second_list = ["SomeEntry", "AnotherEntry", "OutOfOrderEntry"]
  61. assert pipeline_utils.compare_lists(first_list, second_list) == True
  62. def test_ListCompare_DifferentLists_ReturnsFalse(self):
  63. first_list = [ "ListOneUniqueEntry", "OutOfOrderEntry", "SomeEntry", "AnotherEntry"]
  64. second_list = ["SomeEntry", "AnotherEntry", "ListTwoUniqueEntry", "OutOfOrderEntry", "SecondUniqueEntry"]
  65. assert pipeline_utils.compare_lists(first_list, second_list) == False