Skip to content

Commit

Permalink
add tests for conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinblack committed Dec 15, 2023
1 parent b45b880 commit be9a2d7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/unit/test_arcaflow_plugin_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit be9a2d7

Please sign in to comment.