Skip to content

Commit

Permalink
formatting and improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
RuthShryock committed Oct 9, 2024
1 parent 8770059 commit 053647e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
5 changes: 2 additions & 3 deletions pyxform/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def validate(self):
trigger_cleaned = self.trigger.strip("${}")
if not self.get_root().question_exists(trigger_cleaned):
raise PyXFormError(
f"Trigger '{trigger_cleaned}' for background-geopoint question '{self.name}' "
"does not correspond to an existing question."
f"background-geopoint question '{self.name}' must have a trigger corresponding to an existing question."
)

def xml_instance(self, **kwargs):
Expand All @@ -65,7 +64,7 @@ def xml_control(self):
if self.type == "background-geopoint":
if "calculate" in self.bind:
raise PyXFormError(
f"'{self.name}' is triggered by a geopoint action, so the calculation must be null."
f"'{self.name}' is triggered by a geopoint action, please remove the calculation from this question."
)

nested_setvalues = self.get_root().get_trigger_values_for_question_name(
Expand Down
46 changes: 23 additions & 23 deletions tests/test_background_geopoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def test_background_geopoint(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | label | trigger |
| | integer | temp | Enter the current temperature | |
| | background-geopoint| temp_geo | | ${temp} |
| | note | show_temp_geo | location: ${temp_geo} | |
| survey | | | |
| | type | name | label | trigger |
| | integer | temp | Enter the current temperature | |
| | background-geopoint| temp_geo | | ${temp} |
| | note | show_temp_geo | location: ${temp_geo} | |
""",
xml__contains=[
'<bind nodeset="/data/temp_geo" type="geopoint"/>',
'<odk:setgeopoint event="xforms-value-changed" ref="/data/temp_geo"/>',
xml__xpath_match=[
'/h:html/h:head/x:model/x:bind[@nodeset="/data/temp_geo" and @type="geopoint"]',
'/h:html/h:body//odk:setgeopoint[@event="xforms-value-changed" and @ref="/data/temp_geo"]',
],
)

Expand All @@ -25,11 +25,11 @@ def test_background_geopoint_missing_trigger(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | label | trigger |
| | integer | temp | Enter the current temperature | |
| | background-geopoint| temp_geo | | |
| | note | show_temp_geo | location: ${temp_geo} | |
| survey | | | |
| | type | name | label | trigger |
| | integer | temp | Enter the current temperature | |
| | background-geopoint| temp_geo | | |
| | note | show_temp_geo | location: ${temp_geo} | |
""",
errored=True,
error__contains=[
Expand All @@ -41,11 +41,11 @@ def test_invalid_trigger_background_geopoint(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | label | trigger |
| | integer | temp | Enter the current temperature | |
| | background-geopoint| temp_geo | | ${invalid_trigger} |
| | note | show_temp_geo | location: ${temp_geo} | |
| survey | | | |
| | type | name | label | trigger |
| | integer | temp | Enter the current temperature | |
| | background-geopoint| temp_geo | | ${invalid_trigger} |
| | note | show_temp_geo | location: ${temp_geo} | |
""",
errored=True,
error__contains=[
Expand All @@ -58,11 +58,11 @@ def test_background_geopoint_requires_null_calculation(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | | |
| | type | name | label | trigger | calculation |
| | integer | temp | Enter the current temperature | | |
| | background-geopoint| temp_geo | | ${temp} | 5 * temp |
| | note | show_temp_geo | location: ${temp_geo} | | |
| survey | | | | |
| | type | name | label | trigger | calculation |
| | integer | temp | Enter the current temperature | | |
| | background-geopoint| temp_geo | | ${temp} | 5 * temp |
| | note | show_temp_geo | location: ${temp_geo} | | |
""",
errored=True,
error__contains=[
Expand Down

0 comments on commit 053647e

Please sign in to comment.