From ff992795c21f9fd8ceffd07c1aaa4fb16e52a894 Mon Sep 17 00:00:00 2001 From: lindsay stevens Date: Sat, 30 Nov 2024 19:48:54 +1100 Subject: [PATCH] add: add missing test cases, other minor tests improvements - 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 --- tests/test_builder.py | 14 +++++-------- tests/test_choices_sheet.py | 8 +++---- tests/test_fieldlist_labels.py | 7 +++++++ tests/test_fields.py | 1 - tests/test_groups.py | 21 +++++++++++++++++++ tests/test_image_app_parameter.py | 4 ++-- tests/test_survey.py | 16 ++++++++++++++ tests/test_translations.py | 6 +++--- .../xform_test_case/test_xform_conversion.py | 4 ++-- 9 files changed, 60 insertions(+), 21 deletions(-) diff --git a/tests/test_builder.py b/tests/test_builder.py index 83e10372..ee27322a 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -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( @@ -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): @@ -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) @@ -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) @@ -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( @@ -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"\{.+\}") diff --git a/tests/test_choices_sheet.py b/tests/test_choices_sheet.py index 084b9b56..6ace4832 100644 --- a/tests/test_choices_sheet.py +++ b/tests/test_choices_sheet.py @@ -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'] ] """, ], diff --git a/tests/test_fieldlist_labels.py b/tests/test_fieldlist_labels.py index 469fd3a4..a824791d 100644 --- a/tests/test_fieldlist_labels.py +++ b/tests/test_fieldlist_labels.py @@ -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): diff --git a/tests/test_fields.py b/tests/test_fields.py index 55591535..a3d679aa 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -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): diff --git a/tests/test_groups.py b/tests/test_groups.py index 1d8d6efe..db44fb2b 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -50,3 +50,24 @@ def test_group_intent(self): '' # 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' + ] + """ + ], + ) diff --git a/tests/test_image_app_parameter.py b/tests/test_image_app_parameter.py index 8d65db32..3d8006e4 100644 --- a/tests/test_image_app_parameter.py +++ b/tests/test_image_app_parameter.py @@ -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}']" ], ) @@ -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}']" ], ) diff --git a/tests/test_survey.py b/tests/test_survey.py index cd2bec18..d38f3f82 100644 --- a/tests/test_survey.py +++ b/tests/test_survey.py @@ -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'] + """ + ], + ) diff --git a/tests/test_translations.py b/tests/test_translations.py index 1f891ef3..b644dde6 100644 --- a/tests/test_translations.py +++ b/tests/test_translations.py @@ -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 | diff --git a/tests/xform_test_case/test_xform_conversion.py b/tests/xform_test_case/test_xform_conversion.py index 95a0d9eb..8e67451e 100644 --- a/tests/xform_test_case/test_xform_conversion.py +++ b/tests/xform_test_case/test_xform_conversion.py @@ -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)