Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warning unlabeled group 2 #545

Merged
merged 2 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyxform/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@
"false()": False,
}
label_optional_types = [
"calculate",
"deviceid",
"end",
"phonenumber",
"simserial",
"calculate",
"start",
"end",
"start-geopoint",
"today",
"username",
]
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
109 changes: 109 additions & 0 deletions pyxform/tests_v1/test_fieldlist_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- 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_group_fieldlist_alternate_syntax(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])
2 changes: 1 addition & 1 deletion pyxform/tests_v1/test_xlsform_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_warnings__count(self):
| | integer | a_integer | | integer | | | | |
| | decimal | a_decimal | | decimal | | | | |
| | begin repeat | repeat_test | | | | | | |
| | begin group | group_test | | | field-list | | | |
| | begin group | group_test | | | | | | |
| | text | required_text | required_text | | | | | |
| | select_multiple yes_no | select_multiple_test | select multiple test | | minimal | | | |
| | end group | adsaf | | | | | | |
Expand Down
5 changes: 5 additions & 0 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ def workbook_to_json(
row.get("default")
and default_is_dynamic(row.get("default"), question_type)
)
and not (
control_type is constants.GROUP
and row.get("control", {}).get("appearance")
== constants.FIELD_LIST
)
):
# Row number, name, and type probably enough for user message.
# Also means the error message text is stable for tests.
Expand Down