Skip to content

Commit

Permalink
fix: itext not output when choices list_name contains dash (#680)
Browse files Browse the repository at this point in the history
- in survey.py, _generate_static_instances has a check for multi_lang,
  which involves matching the list_name to the translations dict. That
  split the list_name on the itextId separator (a dash) but a dash can
  also appear in the list_name, so it was broken when a list_name
  contained a dash.
  • Loading branch information
lindsay-stevens authored Jan 9, 2024
1 parent f719550 commit 2797258
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _generate_static_instances(self, list_name, choice_list) -> InstanceInfo:
for items in self._translations.values()
for k, v in items.items()
if v.get(constants.TYPE, "") == constants.CHOICE
and k.split("-")[0] == list_name
and "-".join(k.split("-")[:-1]) == list_name
)
if 0 < len(choices):
multi_language = True
Expand Down
34 changes: 33 additions & 1 deletion tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def test_specify_other__no_translations(self):
)

def test_specify_other__choice_filter(self):
"""Should raise an error since these featuers are unsupported together."""
"""Should raise an error since these features are unsupported together."""
md = """
| survey | | | |
| | type | name | label | choice_filter |
Expand All @@ -1753,3 +1753,35 @@ def test_specify_other__choice_filter(self):
errored=True,
error__contains=["[row : 3] Choice filter not supported with or_other."],
)

def test_choice_name_containing_dash_output_itext(self):
"""Should output itext when list_name contains a dash (itextId separator)."""
md = """
| survey | | | |
| | type | name | label:en | label:fr |
| | select_one with_us | q0 | Q1 EN | Q1 FR |
| | select_one with-dash | q1 | Q2 EN | Q2 FR |
| choices | | | |
| | list name | name | label:en | label:fr |
| | with_us | na | l1a-en | l1a-fr |
| | with_us | nb | l1b-en | l1b-fr |
| | with-dash | na | l2a-en | l2a-fr |
| | with-dash | nb | l2b-en | l2b-fr |
"""
self.assertPyxformXform(
md=md,
xml__xpath_match=[
xpc.model_itext_choice_text_label_by_pos(
"en", "with_us", ("l1a-en", "l1b-en")
),
xpc.model_itext_choice_text_label_by_pos(
"en", "with-dash", ("l2a-en", "l2b-en")
),
xpc.model_itext_choice_text_label_by_pos(
"fr", "with_us", ("l1a-fr", "l1b-fr")
),
xpc.model_itext_choice_text_label_by_pos(
"fr", "with-dash", ("l2a-fr", "l2b-fr")
),
],
)

0 comments on commit 2797258

Please sign in to comment.