Skip to content

Commit

Permalink
Merge pull request #535 from lognaturel/empty-label
Browse files Browse the repository at this point in the history
Don't check for dynamic label if there is no label
  • Loading branch information
lognaturel authored May 13, 2021
2 parents d2463fc + b2b9651 commit ae7777c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
74 changes: 74 additions & 0 deletions pyxform/tests_v1/test_choices_sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
from pyxform.tests_v1.pyxform_test_case import PyxformTestCase
from pyxform.utils import unicode


class ChoicesSheetTest(PyxformTestCase):
def test_numeric_choice_names__for_static_selects__allowed(self):
"""
Test numeric choice names for static selects.
"""
self.assertPyxformXform(
md="""
| survey | | | |
| | type | name | label |
| | select_one choices | a | A |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | One |
| | choices | 2 | Two |
""",
xml__contains=["<value>1</value>"],
)

def test_numeric_choice_names__for_dynamic_selects__allowed(self):
"""
Test numeric choice names for dynamic selects.
"""
self.assertPyxformXform(
md="""
| survey | | | | |
| | type | name | label | choice_filter |
| | select_one choices | a | A | true() |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | One |
| | choices | 2 | Two |
""",
xml__contains=['<instance id="choices">', "<item>", "<name>1</name>"],
)

def test_choices_without_labels__for_static_selects__allowed(self):
"""
Test choices without labels for static selects. Validate will NOT fail.
"""
self.assertPyxformXform(
md="""
| survey | | | |
| | type | name | label |
| | select_one choices | a | A |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | |
| | choices | 2 | |
""",
xml__contains=["<value>1</value>"],
)

def test_choices_without_labels__for_dynamic_selects__allowed_by_pyxform(self):
"""
Test choices without labels for dynamic selects. Validate will fail.
"""
self.assertPyxformXform(
md="""
| survey | | | | |
| | type | name | label | choice_filter |
| | select_one choices | a | A | true() |
| choices | | | |
| | list_name | name | label |
| | choices | 1 | |
| | choices | 2 | |
""",
run_odk_validate=False,
xml__contains=['<instance id="choices">', "<item>", "<name>1</name>"],
)
6 changes: 5 additions & 1 deletion pyxform/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ def default_is_dynamic(element_default, element_type=None):
def has_dynamic_label(choice_list, multi_language):
if not multi_language:
for i in range(0, min(2, len(choice_list))):
if re.search(BRACKETED_TAG_REGEX, choice_list[i].get("label")) is not None:
if (
choice_list[i].get("label") is not None
and re.search(BRACKETED_TAG_REGEX, choice_list[i].get("label"))
is not None
):
return True
return False

0 comments on commit ae7777c

Please sign in to comment.