From be9a2d778f87875e96396829a06ed8c61b5175e3 Mon Sep 17 00:00:00 2001 From: Dustin Black Date: Fri, 15 Dec 2023 12:17:17 +0100 Subject: [PATCH] add tests for conversion functions --- tests/unit/test_arcaflow_plugin_opensearch.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/unit/test_arcaflow_plugin_opensearch.py b/tests/unit/test_arcaflow_plugin_opensearch.py index 20531d2..5bc21f9 100644 --- a/tests/unit/test_arcaflow_plugin_opensearch.py +++ b/tests/unit/test_arcaflow_plugin_opensearch.py @@ -33,6 +33,45 @@ def test_serialization(): " 'mapper_parsing_exception','failed to parse')" ) ) + + def test_convert_to_homogeneous_list(self): + test_cases = [ + ["a", "b", "c"], # all str + ["a", "b", 1], # One final int to convert to str + [1.0, 1, "1"], # str at end, so upconvert all to str + ["1", 1, 1.0], + ["1", 1, 1], + [1, 1, "1"], + [1, 1, 1], + [1.0, 1, 1], + [1, 1, 1.0], + ] + # Ensure they're all homogeneous + for test_case in test_cases: + validate_list_items_homogeous_type( + self, opensearch_plugin.convert_to_homogenous_list(test_case) + ) + # Ensure the type matches + self.assertEqual( + int, type(opensearch_plugin.convert_to_homogenous_list([1, 1, 1])[0]) + ) + self.assertEqual( + float, + type(opensearch_plugin.convert_to_homogenous_list([1, 1, 1.0])[0]), + ) + self.assertEqual( + str, + type(opensearch_plugin.convert_to_homogenous_list([1, 1.0, "1.0"])[0]), + ) + + +def validate_list_items_homogeous_type(t, input_list): + if len(input_list) == 0: + return # no problem with an empty list + expected_type = type(input_list[0]) + for item in input_list: + t.assertEqual(type(item), expected_type) + if __name__ == "__main__":