Skip to content

Commit

Permalink
Do not warn on unlabeled field-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
yanokwa committed Jul 3, 2021
1 parent 71f4157 commit a2beca0
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pyxform/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@
"end",
"today",
]
begin_group = ["begin group", "begin_group"]
begin_repeat = ["begin repeat", "begin_repeat"]
osm = {"osm": constants.OSM_TYPE}
1 change: 1 addition & 0 deletions pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
LIST_NAME = "list name"
CASCADING_SELECT = "cascading_select"
TABLE_LIST = "table-list" # hyphenated because it goes in appearance, and convention for appearance column is dashes # noqa
FIELD_LIST = "field-list"

# The following are the possible sheet names:
SURVEY = "survey"
Expand Down
93 changes: 93 additions & 0 deletions pyxform/tests_v1/test_fieldlist_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
"""
Test field-list labels
"""
from pyxform.tests_v1.pyxform_test_case import PyxformTestCase


class FieldListLabels(PyxformTestCase):
"""Test unlabeled group"""

def test_unlabeled_group(self):
warnings = []

survey = self.md_to_pyxform_survey(
"""
| survey | | | |
| | type | name | label |
| | begin_group | my-group | |
| | text | my-text | my-text |
| | end_group | | |
""",
warnings=warnings,
)

self.assertTrue(len(warnings) == 1)
self.assertTrue("[row : 2] Group has no label" in warnings[0])

def test_unlabeled_group_alternate_syntax(self):
warnings = []

survey = self.md_to_pyxform_survey(
"""
| survey | | | |
| | type | name | label::English (en) |
| | begin group | my-group | |
| | text | my-text | my-text |
| | end group | | |
""",
warnings=warnings,
)

self.assertTrue(len(warnings) == 1)
self.assertTrue("[row : 2] Group has no label" in warnings[0])

def test_unlabeled_group_fieldlist(self):
warnings = []

survey = self.md_to_pyxform_survey(
"""
| survey | | | | |
| | type | name | label | appearance |
| | begin_group | my-group | | field-list |
| | text | my-text | my-text | |
| | end_group | | | |
""",
warnings=warnings,
)

self.assertTrue(len(warnings) == 0)

def test_unlabeled_repeat(self):
warnings = []

survey = self.md_to_pyxform_survey(
"""
| survey | | | |
| | type | name | label |
| | begin_repeat | my-repeat | |
| | text | my-text | my-text |
| | end_repeat | | |
""",
warnings=warnings,
)

self.assertTrue(len(warnings) == 1)
self.assertTrue("[row : 2] Repeat has no label" in warnings[0])

def test_unlabeled_repeat_fieldlist(self):
warnings = []

survey = self.md_to_pyxform_survey(
"""
| survey | | | | |
| | type | name | label | appearance |
| | begin_repeat | my-repeat | | field-list |
| | text | my-text | my-text | |
| | end_repeat | | | |
""",
warnings=warnings,
)

self.assertTrue(len(warnings) == 1)
self.assertTrue("[row : 2] Repeat has no label" in warnings[0])
19 changes: 15 additions & 4 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,18 +882,29 @@ def workbook_to_json(
constants.LABEL not in row
and row.get(constants.MEDIA) is None
and question_type not in aliases.label_optional_types
and not (
question_type in aliases.begin_group
and row.get("control", {}).get("appearance") == constants.FIELD_LIST
)
and not row.get("bind", {}).get("calculate")
and not (
row.get("default")
and default_is_dynamic(row.get("default"), question_type)
)
):
# TODO: Should there be a default label?
# Not sure if we should throw warnings for groups...
# Warnings can be ignored so I'm not too concerned
# about false positives.
if question_type in aliases.begin_group:
element_type = "Group"
elif question_type in aliases.begin_repeat:
element_type = "Repeat"
else:
element_type = "Question"
warnings.append(
row_format_string % row_number + " Question has no label: " + str(row)
row_format_string % row_number
+ " "
+ element_type
+ " has no label:"
+ str(row)
)

# Try to parse question as begin control statement
Expand Down

0 comments on commit a2beca0

Please sign in to comment.