Skip to content

Commit

Permalink
Update combine param function and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinp0 committed Nov 24, 2023
1 parent c6f46f1 commit 5512880
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arc/job/adapters/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ def combine_parameters(input_dict: dict, terms: list) -> Tuple[dict, List]:

for key, value in input_dict_copy.items():
if isinstance(value, str):
for term in terms:
# Sort terms by length in descending order to handle overlapping terms
for term in sorted(terms, key=len, reverse=True):
matches = re.findall(term, value)
for match in matches:
if match:
Expand Down
24 changes: 24 additions & 0 deletions arc/job/adapters/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ def test_combine_parameters_no_match(self):
self.assertEqual(modified_dict, expected_dict)
self.assertEqual(parameters, expected_parameters)

def test_combine_parameters_multiple_occurrences(self):
"""Test the combine_parameters function with multiple occurrences of the same term."""
input_dict = {'param1': 'value1 term1 value2 term1', 'param2': 'another term2 value term2'}
terms = ['term1', 'term2']
expected_dict = {'param1': 'value1 value2 ', 'param2': 'another value '}
expected_parameters = ['term1', 'term2']

modified_dict, parameters = common.combine_parameters(input_dict, terms)

self.assertEqual(modified_dict, expected_dict)
self.assertEqual(sorted(parameters), expected_parameters)

def test_combine_parameters_overlapping_terms(self):
"""Test the combine_parameters function with overlapping terms."""
input_dict = {'param1': 'value term1 term123', 'param2': 'another term2 value'}
terms = ['term1', 'term123', 'term2']
expected_dict = {'param1': 'value ', 'param2': 'another value'}
expected_parameters = ['term1', 'term123', 'term2']

modified_dict, parameters = common.combine_parameters(input_dict, terms)

self.assertEqual(modified_dict, expected_dict)
self.assertEqual(sorted(parameters), expected_parameters)

def test_input_dict_strip(self):
"""Test the input_dict_strip() function"""
input_dict = {
Expand Down

0 comments on commit 5512880

Please sign in to comment.