Skip to content
Open
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
11 changes: 0 additions & 11 deletions pyxform/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,6 @@
"FALSE": False,
"false()": False,
}
label_optional_types = [
"calculate",
"deviceid",
"end",
"phonenumber",
"simserial",
"start",
"start-geopoint",
"today",
"username",
]
osm = {"osm": constants.OSM_TYPE}
BINDING_CONVERSIONS = {
"yes": "true()",
Expand Down
11 changes: 2 additions & 9 deletions pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,9 @@ def workbook_to_json(
# There isn't an easy and neat place to put this besides here.
# Could potentially be simplified for control item cases.
if (
constants.LABEL not in row
control_type == constants.REPEAT
and constants.LABEL not in row
and row.get(constants.MEDIA) is None
and question_type not in aliases.label_optional_types
and not row.get("bind", {}).get("calculate")
and not row.get("_dynamic_default", False)
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
196 changes: 139 additions & 57 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pyxform.xls2xform import convert

from tests.pyxform_test_case import PyxformTestCase
from tests.xpath_helpers.group import xpg


class TestGroupOutput(PyxformTestCase):
Expand Down Expand Up @@ -113,6 +114,144 @@ def test_table_list_appearance(self):
xml__contains=[xml_contains],
)

def test_group__label__ok(self):
"""Should find a group control with a child `label` element and no warnings."""
md = """
| survey |
| | type | name | label |
| | begin_group | g1 | G1 |
| | text | q1 | Q1 |
| | end_group | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_label_no_translation("/test_name/g1", "G1"),
],
)

def test_group__no_label__ok(self):
"""Should find a group control with no child `label` element and no warnings."""
md = """
| survey |
| | type | name | label |
| | begin_group | g1 | |
| | text | q1 | Q1 |
| | end_group | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_no_label("/test_name/g1"),
],
)

def test_group__label__translated__ok(self):
"""Should find a group control with a child `label` element and no warnings."""
md = """
| survey |
| | type | name | label::English (en) |
| | begin_group | g1 | G1 |
| | text | q1 | Q1 |
| | end_group | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_label_translation("/test_name/g1"),
],
)

def test_group__no_label__translated__ok(self):
"""Should find a group control with no child `label` element and no warnings."""
md = """
| survey |
| | type | name | label::English (en) |
| | begin_group | g1 | |
| | text | q1 | Q1 |
| | end_group | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_no_label("/test_name/g1"),
],
)

def test_group__label__appearance__ok(self):
"""Should find a group control with a child `label` element and no warnings."""
md = """
| survey |
| | type | name | label | appearance |
| | begin_group | g1 | G1 | field-list |
| | text | q1 | Q1 | |
| | end_group | | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_label_no_translation_appearance(
"/test_name/g1", "G1", "field-list"
),
],
)

def test_group__no_label__appearance__ok(self):
"""Should find a group control with no child `label` element and no warnings."""
md = """
| survey |
| | type | name | label | appearance |
| | begin_group | g1 | | field-list |
| | text | q1 | Q1 | |
| | end_group | | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_no_label_appearance("/test_name/g1", "field-list"),
],
)

def test_group__label__translated__appearance__ok(self):
"""Should find a group control with a child `label` element and no warnings."""
md = """
| survey |
| | type | name | label::English (en) | appearance |
| | begin_group | g1 | G1 | field-list |
| | text | q1 | Q1 | |
| | end_group | | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_label_translation_appearance("/test_name/g1", "field-list"),
],
)

def test_group__no_label__translated__appearance__ok(self):
"""Should find a group control with no child `label` element and no warnings."""
md = """
| survey |
| | type | name | label::English (en) | appearance |
| | begin_group | g1 | | field-list |
| | text | q1 | Q1 | |
| | end_group | | | |
"""
self.assertPyxformXform(
md=md,
warnings_count=0,
xml__xpath_match=[
xpg.group_no_label_appearance("/test_name/g1", "field-list"),
],
)


class TestGroupParsing(PyxformTestCase):
def test_names__group_basic_case__ok(self):
Expand Down Expand Up @@ -643,63 +782,6 @@ def test_empty_group__no_question_control__error(self):
],
)

def test_unlabeled_group(self):
self.assertPyxformXform(
md="""
| survey |
| | type | name | label |
| | begin_group | my-group | |
| | text | my-text | my-text |
| | end_group | | |
""",
warnings_count=1,
warnings__contains=["[row : 2] Group has no label"],
)

def test_unlabeled_group_alternate_syntax(self):
self.assertPyxformXform(
md="""
| survey |
| | type | name | label::English (en) |
| | begin group | my-group | |
| | text | my-text | my-text |
| | end group | | |
""",
warnings_count=1,
warnings__contains=["[row : 2] Group has no label"],
)

def test_unlabeled_group_fieldlist(self):
self.assertPyxformXform(
md="""
| survey |
| | type | name | label | appearance |
| | begin_group | my-group | | field-list |
| | text | my-text | my-text | |
| | end_group | | | |
""",
warnings_count=0,
xml__xpath_match=[
"""
/h:html/h:body/x:group[
@ref = '/test_name/my-group' and @appearance='field-list'
]
"""
],
)

def test_unlabeled_group_fieldlist_alternate_syntax(self):
self.assertPyxformXform(
md="""
| survey |
| | type | name | label::English (en) | appearance |
| | begin group | my-group | | field-list |
| | text | my-text | my-text | |
| | end group | | | |
""",
warnings_count=0,
)


class TestGroupInternalRepresentations(TestCase):
maxDiff = None
Expand Down
Loading