Skip to content

Commit

Permalink
dev: make pyxformtestcase use keywords to avoid typos (#677)
Browse files Browse the repository at this point in the history
- also removed any test calls that use the default keyword value, if it
  seemed like that was not intentional. For example debug=False.
  • Loading branch information
lindsay-stevens authored Jan 17, 2024
1 parent f8d9330 commit 9ba1367
Show file tree
Hide file tree
Showing 24 changed files with 255 additions and 274 deletions.
3 changes: 2 additions & 1 deletion tests/builder_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def setUp(self):
self.survey_out_dict, utils.path_to_text_fixture("how_old_are_you.json")
)

def test_create_from_file_object(self):
@staticmethod
def test_create_from_file_object():
path = utils.path_to_text_fixture("yes_or_no_question.xls")
with open(path, "rb") as f:
create_survey_from_xls(f)
Expand Down
431 changes: 230 additions & 201 deletions tests/pyxform_test_case.py

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions tests/test_choices_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def test_choices_without_labels__for_dynamic_selects__allowed_by_pyxform(self):
| | choices | 1 | |
| | choices | 2 | |
""",
run_odk_validate=False,
xml__xpath_match=[
xpq.body_select1_itemset("a"),
"""
Expand Down Expand Up @@ -120,18 +119,18 @@ def test_choices_extra_columns_output_order_matches_xlsform(self):
"""
self.assertPyxformXform(
md=md,
xml__xpath_contains=[
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:instance[@id='choices']/x:root/x:item[
./x:name[position() = 1 and text() = '1']
and ./x:geometry[position() = 2]
./x:name = ./x:*[position() = 1 and text() = '1']
and ./x:geometry = ./x:*[position() = 2 and text() = '46.5841618 7.0801379 0 0']
]
"""
""",
"""
/h:html/h:head/x:model/x:instance[@id='choices']/x:root/x:item[
./x:name[position() = 1 and text() = '2']
and ./x:geometry[position() = 2]
./x:name = ./x:*[position() = 1 and text() = '2']
and ./x:geometry = ./x:*[position() = 2 and text() = '35.8805082 76.515057 0 0']
]
"""
""",
],
)
2 changes: 0 additions & 2 deletions tests/test_entities_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ def test_saveto_in_group__works(self):
| | dataset | label | | |
| | trees | ${size}| | |
""",
errored=False,
)

def test_list_name_alias_to_dataset(self):
Expand Down Expand Up @@ -404,7 +403,6 @@ def test_entities_columns__all_expected(self):
| | dataset | label | update_if | create_if | entity_id |
| | trees | a | id != '' | id = '' | ${a} |
""",
errored=False,
warnings_count=0,
)

Expand Down
1 change: 0 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,4 @@ def test_field_name_may_match_form_name(self):
| | date | date | Observation date |
| | text | activity | Describe activity |
""",
errored=False,
)
1 change: 0 additions & 1 deletion tests/test_form_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_default_to_data_when_no_name(self):
| | id_string | name |
| | some-id | data |
""",
kwargs={},
autoname=False,
)

Expand Down
2 changes: 0 additions & 2 deletions tests/test_pyxformtestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_vanilla_survey(self):
"""
self.assertPyxformXform(
ss_structure={"survey": [{"type": "note", "name": "n1", "label": "Note 1"}]},
errored=False,
)


Expand All @@ -63,7 +62,6 @@ def test_formid_is_not_none(self):
| | type | name | label |
| | note | q | Q |
""",
{},
autoname=True,
)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_randomize_itemsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_randomized_external_xml_instance(self):
def test_randomized_select_one_bad_param(self):
self.assertPyxformXform(
name="data",
errored="true",
errored=True,
md="""
| survey | | | | |
| | type | name | label | parameters |
Expand All @@ -152,7 +152,7 @@ def test_randomized_select_one_bad_param(self):
def test_randomized_select_one_bad_randomize(self):
self.assertPyxformXform(
name="data",
errored="true",
errored=True,
md="""
| survey | | | | |
| | type | name | label | parameters |
Expand All @@ -171,7 +171,7 @@ def test_randomized_select_one_bad_randomize(self):
def test_randomized_select_one_bad_seed(self):
self.assertPyxformXform(
name="data",
errored="true",
errored=True,
md="""
| survey | | | | |
| | type | name | label | parameters |
Expand All @@ -190,7 +190,7 @@ def test_randomized_select_one_bad_seed(self):
def test_randomized_select_one_seed_without_randomize(self):
self.assertPyxformXform(
name="data",
errored="true",
errored=True,
md="""
| survey | | | | |
| | type | name | label | parameters |
Expand Down
2 changes: 0 additions & 2 deletions tests/test_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ def test_choice_from_previous_repeat_answers_with_choice_filter(self):
'<itemset nodeset="/data/rep[starts-with( ./name , &quot;b&quot;)]">',
'<itemset nodeset="/data/rep[ ./demographics/age &gt; 18]">',
],
run_odk_validate=False,
)

def test_choice_from_previous_repeat_answers_in_child_repeat(self):
Expand Down Expand Up @@ -997,7 +996,6 @@ def test_repeat_count_item_with_same_suffix_as_repeat_is_ok(self):
"""
self.assertPyxformXform(
md=md,
debug=True,
xml__xpath_match=[
# repeat references existing count element directly.
"""
Expand Down
3 changes: 0 additions & 3 deletions tests/test_secondary_instance_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def test_select_with_choice_filter_and_translations_generates_single_translation
name="data",
id_string="some-id",
md=xform_md,
errored=False,
debug=False,
itext__contains=[
'<text id="list-0">',
'<text id="list-1">',
Expand Down Expand Up @@ -171,7 +169,6 @@ def test_select_with_dynamic_option_label__and_choice_filter__and_no_translation
self.assertPyxformXform(
name="data",
md=xform_md,
debug=False,
itext__contains=[
'<text id="choices-0">',
'<value> One - <output value=" /data/txt "/>',
Expand Down
5 changes: 0 additions & 5 deletions tests/test_settings_auto_send_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_settings_auto_send_true(self):
| | auto_send | | |
| | true | | |
""",
debug=False,
xml__contains=['<submission orx:auto-send="true"/>'],
)

Expand All @@ -34,7 +33,6 @@ def test_settings_auto_delete_true(self):
| | auto_delete | | |
| | true | | |
""",
debug=False,
xml__contains=['<submission orx:auto-delete="true"/>'],
)

Expand All @@ -50,7 +48,6 @@ def test_settings_auto_send_delete_false(self):
| | auto_delete | auto_send | |
| | false | false | |
""",
debug=False,
xml__contains=['<submission orx:auto-delete="false" orx:auto-send="false"/>'],
)

Expand All @@ -72,7 +69,6 @@ def test_settings_without_submission_url_does_not_generate_method_attribute(self
| | bRHBG7TQm+Afnx0s5E2bGIT5jB5cj9YaX6BqZSeodpafQjpXEJg6uufxF1Ni3Btv | | |
| | 4wIDAQAB | | |
""",
debug=False,
xml__contains=[
'<submission base64RsaPublicKey="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwOHPJWD9zc8JPBZj/UtC" orx:auto-send="false"/>'
],
Expand All @@ -90,7 +86,6 @@ def test_settings_with_submission_url_generates_method_attribute(self):
| | submission_url | auto_send | |
| | https://odk.ona.io/random_person/submission | false | |
""",
debug=False,
xml__contains=[
'<submission action="https://odk.ona.io/random_person/submission" method="post" orx:auto-send="false"/>'
],
Expand Down
8 changes: 2 additions & 6 deletions tests/test_sheet_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def test_missing_name_but_has_alias_of_name(self):
self.assertPyxformXform(
name="invalidcols",
ss_structure={"survey": [{"value": "q1", "type": "text", "label": "label"}]},
errored=False,
)

def test_label_or_hint__must_be_provided(self):
Expand Down Expand Up @@ -101,8 +100,6 @@ def test_column_case(self):
| | integer | age | the age |
| | text | gender | the gender |
""",
errored=False,
debug=False,
)


Expand All @@ -111,7 +108,8 @@ class InvalidChoiceSheetColumnsTests(PyxformTestCase):
Invalid choice sheet column tests
"""

def _simple_choice_ss(self, choice_sheet=None):
@staticmethod
def _simple_choice_ss(choice_sheet=None):
"""
Return simple choices sheet
"""
Expand Down Expand Up @@ -142,7 +140,6 @@ def test_valid_choices_sheet_passes(self):
{"list_name": "l1", "name": "c2", "label": "choice 2"},
]
),
errored=False,
)

def test_invalid_choices_sheet_fails(self):
Expand Down Expand Up @@ -175,7 +172,6 @@ def test_missing_list_name(self):
{"bad_column": "l1", "name": "l1c1", "label": "choice 2"},
]
),
debug=False,
errored=True,
# some basic keywords that should be in the error:
error__contains=["choices", "name", "list_name"],
Expand Down
1 change: 0 additions & 1 deletion tests/test_table_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ def test_table_list(self):
name="table-list-appearance-mod",
md=MD,
xml__contains=[XML_CONTAINS],
debug=False,
)
1 change: 0 additions & 1 deletion tests/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ def test_translation_detection__survey_columns_present_with_media(self):
"""
self.assertPyxformXform(
md=md,
debug=True,
xml__xpath_match=[
xpq.body_select1_itemset("f"),
xpq.body_label_inline("select1", "f", "f"),
Expand Down
1 change: 0 additions & 1 deletion tests/test_typed_calculates.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,5 @@ def test_calculate_without_calculation_with_dynamic_default(self):
| | type | name | label | calculation | default |
| | calculate | a | | | random() |
""",
errored=False,
instance__contains=["<a/>"],
)
3 changes: 0 additions & 3 deletions tests/test_unicode_rtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_unicode_snowman(self):
| | type | name | label |
| | text | snowman | ☃ |
""",
errored=False,
xml__contains=["<label>☃</label>"],
)

Expand Down Expand Up @@ -49,8 +48,6 @@ def test_smart_quotes(self):
],
"settings": [{"version": "q(‘-’)p"}],
},
errored=False,
validate=False,
name="quoth",
xml__contains=[
"'single-quoted",
Expand Down
5 changes: 0 additions & 5 deletions tests/test_upload_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_image_question(self):
| | type | name | label |
| | image | photo | Take a photo: |
""",
errored=False,
xml__contains=[
'<bind nodeset="/data/photo" type="binary"/>',
'<upload mediatype="image/*" ref="/data/photo">',
Expand All @@ -30,7 +29,6 @@ def test_audio_question(self):
| | type | name | label |
| | audio | recording1 | Record a sound: |
""",
errored=False,
xml__contains=[
'<bind nodeset="/data/recording1" type="binary"/>',
'<upload mediatype="audio/*" ref="/data/recording1">',
Expand All @@ -47,7 +45,6 @@ def test_file_question(self):
| | type | name | label |
| | file | file1 | Upload a file: |
""",
errored=False,
xml__contains=[
'<bind nodeset="/data/file1" type="binary"/>',
'<upload mediatype="application/*" ref="/data/file1">',
Expand All @@ -64,7 +61,6 @@ def test_file_question_restrict_filetype(self):
| | type | name | label | body::accept |
| | file | upload_a_pdf | Upload a PDF: | application/pdf |
""",
errored=False,
xml__contains=['<upload accept="application/pdf"'],
)

Expand All @@ -78,6 +74,5 @@ def test_image_question_custom_col_calc(self):
| | text | text1 | Text | |
| | image | image1 | Take a Photo: | watermark=${watermark_phrase} |
""", # noqa
errored=False,
xml__contains=["watermark= /data/watermark_phrase "],
)
2 changes: 1 addition & 1 deletion tests/test_whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_values_without_whitespaces_are_processed_successfully(self):
"""
self.assertPyxformXform(
md=md,
xml__xpath_contains=[
xml__xpath_match=[
"""
/h:html/h:head/x:model/x:submission[
@action='https://odk.ona.io/random_person/submission'
Expand Down
6 changes: 1 addition & 5 deletions tests/test_xform2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def test_convert_toJSON_multi_language(self):
| | fruits | 3 | Apple | Pomme |
"""

survey = self.md_to_pyxform_survey(
md_raw=md,
kwargs={"id_string": "id", "name": "multi-language", "title": "some-title"},
autoname=False,
)
survey = self.md_to_pyxform_survey(md_raw=md)
expected = survey.to_xml()
generated_json = survey.to_json()

Expand Down
Loading

0 comments on commit 9ba1367

Please sign in to comment.