Skip to content

Commit

Permalink
Merge pull request #304 from kobotoolbox/303-handle-multiple-spaces-w…
Browse files Browse the repository at this point in the history
…ith-or-other

Handle multiple spaces in or_other
  • Loading branch information
noliveleger authored Oct 5, 2022
2 parents 482172c + faa5f53 commit abcdced
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/formpack/utils/expand_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ def _mark_special(**kwargs: str) -> None:
def _expand_type_to_dict(type_str: str) -> Dict[str, Union[str, bool]]:
SELECT_PATTERN = r'^({select_type})\s+(\S+)$'
out = {}
match = re.search('( or.other)$', type_str)
match = re.search('\s+(or.other)$', type_str)
if match:
type_str = type_str.replace(match.groups()[0], '')
type_str = type_str.replace(match.groups()[0], '').strip()
out[OR_OTHER_COLUMN] = True
match = re.search('select_(one|multiple)(_or_other)', type_str)
if match:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_expand_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

def test_expand_selects_with_or_other():
assert _expand_type_to_dict('select_one xx or other').get(_OR_OTHER) == True
assert _expand_type_to_dict('select_one xx or_other').get(_OR_OTHER) == True
assert _expand_type_to_dict('select_one_or_other xx').get(_OR_OTHER) == True
assert (
_expand_type_to_dict('select_multiple_or_other xx').get(_OR_OTHER)
Expand Down Expand Up @@ -56,6 +57,14 @@ def test_expand_select_one_or_other():
assert s1['survey'][0]['select_from_list_name'] == 'dogs'


def test_expand_select_one_or_other_with_spaces():
s1 = {'survey': [{'type': 'select_one dogs or_other'}]}
expand_content(s1, in_place=True)
assert s1['survey'][0]['type'] == 'select_one'
assert s1['survey'][0]['select_from_list_name'] == 'dogs'
assert s1['survey'][0][_OR_OTHER] == True


def test_expand_select_multiple():
s1 = {'survey': [{'type': 'select_multiple dogs'}]}
expand_content(s1, in_place=True)
Expand Down

0 comments on commit abcdced

Please sign in to comment.