-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output empty <label/>
instead of omitting it.
#543
Conversation
- as per pyxform/XLSForm#439, should always output a label node even if there is no label specified. - pyxform had a warning for no label but this is removed since there is no requirement for a label. - add tests to verify that a label is output and no warning raised - fix existing tests that either expected a warning or no label
From @MartijnR at #439 (comment):
The PR description doesn't address this that I can see -- will Validate still throw an error if there's an empty label and no hint? That would be the desired behavior. |
I've come back to try this, and I do confirm that there is still a pyxform error thrown if neither label nor hint is present which is what we want. 👍 I went straight to tests to try to see if that was covered and didn't see it because the forms aren't inline. Also, I now see that |
- some clients hide the guidance hint by default, in which case the user would see nothing / a small (i) symbol if a question had only a guidance hint without any label (or media) or hint - update test_guidance_hint.py tests accordingly - change newly added test from ss_structure to md-style - removed e2e tests and associated files; more or less the same as the test immediately above in test_sheet_columns.py
Codecov Report
@@ Coverage Diff @@
## master #543 +/- ##
==========================================
- Coverage 83.88% 83.85% -0.04%
==========================================
Files 25 25
Lines 3736 3747 +11
Branches 872 875 +3
==========================================
+ Hits 3134 3142 +8
- Misses 455 457 +2
- Partials 147 148 +1
Continue to review full report at Codecov.
|
if ( | ||
constants.LABEL not in row | ||
and row.get(constants.MEDIA) is None | ||
and question_type not in aliases.label_optional_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there tests for this case and the two below? (I'm pretty sure there are but would be good to confirm that you identified them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- label check block applies to questions and other item types such as groups and repeats, so may be valid in other scenarios - for example this block is referenced in XLSForm#542 - will require further changes to exclude question items from the check since that is the intent in XLSForm#439
- as noted in the comment, the check doesn't apply to questions anymore since PR XLSForm#543 makes pyxform always emit a label, and the only case that is not permissible is a guidance_hint with no label or hint. - nesting this check inside the "control group" processing branch seems the only neat+easy way about this, since: - the context is a loop from which the various branches continue, so it can't check at the end, - each branch parses / determines the actual item type which is not apparent in the raw "type" data from the row dict, and - after the loop context exits, the data is in an array with nested dicts so it's no longer possible to determine the sheet row number for the error message to be as useful to users. - refactored an old test which covers a lot of question types, into the tests_v1 / md style since this test is affected by the changes and having md style is more transparent - added some tests to verify the assumption that for the label check, it's not going to encounter a None or empty value for "control_type".
Hi @lognaturel, resolving this turned out to be not as simple as restoring the check code block. When it was restored, a couple of tests needed to be updated. In particular there is an old-style test with a large "warnings.xls" fixture, which is now refactored into markdown. This should make it clearer when the label warning will and will not be raised. From here, #542 could add in the new condition to exclude warnings for field-list groups, and add the new tests. More context / info in the 3e4a84e commit message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
- as noted in the comment, the check doesn't apply to questions anymore since PR XLSForm#543 makes pyxform always emit a label, and the only case that is not permissible is a guidance_hint with no label or hint. - nesting this check inside the "control group" processing branch seems the only neat+easy way about this, since: - the context is a loop from which the various branches continue, so it can't check at the end, - each branch parses / determines the actual item type which is not apparent in the raw "type" data from the row dict, and - after the loop context exits, the data is in an array with nested dicts so it's no longer possible to determine the sheet row number for the error message to be as useful to users. - refactored an old test which covers a lot of question types, into the tests_v1 / md style since this test is affected by the changes and having md style is more transparent - added some tests to verify the assumption that for the label check, it's not going to encounter a None or empty value for "control_type".
- as noted in the comment, the check doesn't apply to questions anymore since PR XLSForm#543 makes pyxform always emit a label, and the only case that is not permissible is a guidance_hint with no label or hint. - nesting this check inside the "control group" processing branch seems the only neat+easy way about this, since: - the context is a loop from which the various branches continue, so it can't check at the end, - each branch parses / determines the actual item type which is not apparent in the raw "type" data from the row dict, and - after the loop context exits, the data is in an array with nested dicts so it's no longer possible to determine the sheet row number for the error message to be as useful to users. - refactored an old test which covers a lot of question types, into the tests_v1 / md style since this test is affected by the changes and having md style is more transparent - added some tests to verify the assumption that for the label check, it's not going to encounter a None or empty value for "control_type".
- as noted in the comment, the check doesn't apply to questions anymore since PR XLSForm#543 makes pyxform always emit a label, and the only case that is not permissible is a guidance_hint with no label or hint. - nesting this check inside the "control group" processing branch seems the only neat+easy way about this, since: - the context is a loop from which the various branches continue, so it can't check at the end, - each branch parses / determines the actual item type which is not apparent in the raw "type" data from the row dict, and - after the loop context exits, the data is in an array with nested dicts so it's no longer possible to determine the sheet row number for the error message to be as useful to users. - refactored an old test which covers a lot of question types, into the tests_v1 / md style since this test is affected by the changes and having md style is more transparent - added some tests to verify the assumption that for the label check, it's not going to encounter a None or empty value for "control_type".
<label/>
instead of omitting it. #439Closes #439
Why is this the best possible solution? Were any other approaches considered?
As discussed in the issue ticket, the XForms spec requires a label node. It would not be feasible to change the spec, so this solution brings pyxform output in to line with the spec.
What are the regression risks?
It's possible that existing users expect there to be a warning if no label is supplied but a hint is supplied. So the regression risk would be in other apps that use pyxform. In this case the other app could add a check for empty labels.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
The xlsform.org site says that the survey sheet label is mandatory. However, the update here is specific to pyxform behaviour. It would not be accurate to say that the label is not mandatory, because it is. It's just that for pyxform, in the absence of a label it will emit one in order to comply with the spec.
Before submitting this PR, please make sure you have:
tests_v1
nosetests
and verified all tests passblack pyxform
to format code