Skip to content

Commit

Permalink
add: add missing test cases, other minor tests improvements
Browse files Browse the repository at this point in the history
- test_xform_conversion.py: remove unnecessary warnings arg
- test_builder.py:
  - remove self.maxDiff=None since this is done at the class level
  - swap AssertEqual arg order since first arg referred to as the
    "expected" value in test failure messages.
- test_choices_sheet.py: remove unnecessary position() assertion
- test_fieldlist_labels.py: add appearance assertion since this does
  not otherwise seem to be tested for groups
- test_fields.py: remove debug setting
- test_groups.py: add test for group relevance (no other tests for this)
- test_image_app_parameter.py: add assertion for appearance, since this
  does not otherwise seem to be tested for questions
- test_survey.py: add test for autoplay setting
- test_translations.py: fix typo in label translation header
  • Loading branch information
lindsay-stevens committed Nov 30, 2024
1 parent 028f26e commit ff99279
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 21 deletions.
14 changes: 5 additions & 9 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def test_create_table_from_dict(self):
},
],
}

self.assertEqual(g.to_json_dict(), expected_dict)
self.assertEqual(expected_dict, g.to_json_dict())

def test_specify_other(self):
survey = utils.create_survey_from_fixture(
Expand Down Expand Up @@ -169,7 +168,6 @@ def test_specify_other(self):
},
],
}
self.maxDiff = None
self.assertEqual(survey.to_json_dict(), expected_dict)

def test_select_one_question_with_identical_choice_name(self):
Expand Down Expand Up @@ -211,8 +209,7 @@ def test_select_one_question_with_identical_choice_name(self):
},
],
}
self.maxDiff = None
self.assertEqual(survey.to_json_dict(), expected_dict)
self.assertEqual(expected_dict, survey.to_json_dict())

def test_loop(self):
survey = utils.create_survey_from_fixture("loop", filetype=FIXTURE_FILETYPE)
Expand Down Expand Up @@ -351,8 +348,7 @@ def test_loop(self):
},
],
}
self.maxDiff = None
self.assertEqual(survey.to_json_dict(), expected_dict)
self.assertEqual(expected_dict, survey.to_json_dict())

def test_sms_columns(self):
survey = utils.create_survey_from_fixture("sms_info", filetype=FIXTURE_FILETYPE)
Expand Down Expand Up @@ -502,7 +498,7 @@ def test_sms_columns(self):
],
},
}
self.assertEqual(survey.to_json_dict(), expected_dict)
self.assertEqual(expected_dict, survey.to_json_dict())

def test_style_column(self):
survey = utils.create_survey_from_fixture(
Expand Down Expand Up @@ -541,7 +537,7 @@ def test_style_column(self):
"title": "My Survey",
"type": "survey",
}
self.assertEqual(survey.to_json_dict(), expected_dict)
self.assertEqual(expected_dict, survey.to_json_dict())

STRIP_NS_FROM_TAG_RE = re.compile(r"\{.+\}")

Expand Down
8 changes: 4 additions & 4 deletions tests/test_choices_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ def test_choices_extra_columns_output_order_matches_xlsform(self):
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:instance[@id='choices']/x:root/x:item[
./x:name = ./x:*[position() = 1 and text() = '1']
and ./x:geometry = ./x:*[position() = 2 and text() = '46.5841618 7.0801379 0 0']
./x:name = ./x:*[text() = '1']
and ./x:geometry = ./x:*[text() = '46.5841618 7.0801379 0 0']
]
""",
"""
/h:html/h:head/x:model/x:instance[@id='choices']/x:root/x:item[
./x:name = ./x:*[position() = 1 and text() = '2']
and ./x:geometry = ./x:*[position() = 2 and text() = '35.8805082 76.515057 0 0']
./x:name = ./x:*[text() = '2']
and ./x:geometry = ./x:*[text() = '35.8805082 76.515057 0 0']
]
""",
],
Expand Down
7 changes: 7 additions & 0 deletions tests/test_fieldlist_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_unlabeled_group_fieldlist(self):
| | 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):
Expand Down
1 change: 0 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_multiple_duplicate_choices_without_setting(self):
vc.INVALID_DUPLICATE.format(row=3),
vc.INVALID_DUPLICATE.format(row=5),
],
debug=True,
)

def test_duplicate_choices_with_setting_not_set_to_yes(self):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ def test_group_intent(self):
'<group intent="ex:org.redcross.openmapkit.action.QUERY(osm_file= /intent_test/pregrp )" ref="/intent_test/xgrp">' # nopep8
],
)

def test_group_relevant_included_in_bind(self):
"""Should find the group relevance expression in the group binding."""
md = """
| survey |
| | type | name | label | relevant |
| | integer | q1 | Q1 | |
| | begin group | g1 | G1 | ${q1} = 1 |
| | text | q2 | Q2 | |
| | end group | | | |
"""
self.assertPyxformXform(
md=md,
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:bind[
@nodeset = '/test_name/g1' and @relevant=' /test_name/q1 = 1'
]
"""
],
)
4 changes: 2 additions & 2 deletions tests/test_image_app_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_ignoring_invalid_android_package_name_with_not_supported_appearances(
name="data",
md=md.format(case=case),
xml__xpath_match=[
"/h:html/h:body/x:upload[not(@intent) and @mediatype='image/*' and @ref='/data/my_image']"
f"/h:html/h:body/x:upload[not(@intent) and @mediatype='image/*' and @ref='/data/my_image' and @appearance='{case}']"
],
)

Expand All @@ -105,7 +105,7 @@ def test_ignoring_android_package_name_in_image_with_not_supported_appearances(s
name="data",
md=md.format(case=case),
xml__xpath_match=[
"/h:html/h:body/x:upload[not(@intent) and @mediatype='image/*' and @ref='/data/my_image']"
f"/h:html/h:body/x:upload[not(@intent) and @mediatype='image/*' and @ref='/data/my_image' and @appearance='{case}']"
],
)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ def test_many_xpath_references_do_not_hit_64_recursion_limit__many_to_many(self)
n="\n".join(tmpl_n.format(i) for i in range(1, 250)),
),
)

def test_autoplay_attribute_added_to_question_body_control(self):
"""Should add the autoplay attribute when specified for a question."""
md = """
| survey |
| | type | name | label | audio | autoplay |
| | text | feel | Song feel? | amazing.mp3 | audio |
"""
self.assertPyxformXform(
md=md,
xml__xpath_match=[
"""
/h:html/h:body/x:input[@ref='/test_name/feel' and @autoplay='audio']
"""
],
)
6 changes: 3 additions & 3 deletions tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,9 +1711,9 @@ def test_specify_other__with_translations_only__missing_first_translation(self):
"""Should add an "other" choice to the itemset instance and an itext label."""
# xls2json validation would raise an error if a choice has no label at all.
md = """
| survey | | | | | |
| | type | name | label | label::eng | label:fr |
| | select_one c1 or_other | q1 | Question 1 | Question A | QA fr |
| survey | | | | | |
| | type | name | label | label::eng | label::fr |
| | select_one c1 or_other | q1 | Question 1 | Question A | QA fr |
| choices | | | | | |
| | list name | name | label | label::eng | label::fr |
| | c1 | na | la | la-e | la-f |
Expand Down
4 changes: 2 additions & 2 deletions tests/xform_test_case/test_xform_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_conversion_vs_expected(self):
)
xlsform = Path(self.path_to_excel_file)
if set_name:
result = convert(xlsform=xlsform, warnings=[], form_name=xlsform.stem)
result = convert(xlsform=xlsform, form_name=xlsform.stem)
else:
result = convert(xlsform=xlsform, warnings=[])
result = convert(xlsform=xlsform)
with open(expected_output_path, encoding="utf-8") as expected:
self.assertXFormEqual(expected.read(), result.xform)

0 comments on commit ff99279

Please sign in to comment.