Skip to content
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

Test debug output doesn't match what's actually compared when attributes have explicit namespaces #414

Open
lognaturel opened this issue Jan 8, 2020 · 3 comments

Comments

@lognaturel
Copy link
Contributor

lognaturel commented Jan 8, 2020

pyxform v0.15.1, Python 3.7.2

The test_integer_max_pixels test looks for <bind nodeset="/data/my_image" type="binary" orx:max-pixels="640"/>. If this is changed to e.g. <qqqqind nodeset="/data/my_image" type="binary" orx:max-pixels="640"/> and the debug=True flag is added, the test fails as expected but the debug output shows <bind nodeset="/data/my_image" orx:max-pixels="640" type="binary"/>. Note that the attribute order is different.

If I modify the test to check for <bind nodeset="/data/my_image" orx:max-pixels="640" type="binary"/>, the test fails.

To reproduce, use nosetests pyxform.tests_v1.test_max_pixels.MaxPixelsTest

When I convert the form directly, I get <bind nodeset="/data/my_image" orx:max-pixels="640" type="binary"/>. This means the tests are not verifying the actual output, at least for some Python versions. I got the same output with Python v2.7.

@lognaturel
Copy link
Contributor Author

lognaturel commented Jan 8, 2020

I'm pretty sure this is because assertPyxformXform uses ETree.fromstring and that xml.etree.ElementTree represents attributes as {namespace}name. For the test described, that means the three attributes are represented as nodeset, {https://openrosa.org/xforms}max-pixels, type. That sorts to [nodeset, type, {https://openrosa.org/xforms}max-pixels] which explains the order expected by the tests.

On the other hand, the Survey._to_pretty/ugly_xml methods use xml.dom.minidom which I believe pre-Python 3.8 sorts attribute names using the attribute namespace prefixes.

@lognaturel lognaturel changed the title Test debug output doesn't match what's actually compared Test debug output doesn't match what's actually compared when attributes have explicit namespaces Jan 8, 2020
@yanokwa
Copy link
Contributor

yanokwa commented Jan 8, 2020

Closed by #415.

@yanokwa yanokwa closed this as completed Jan 8, 2020
@lognaturel
Copy link
Contributor Author

No, unfortunately #415 does not close this. I'm not really sure whether we want to do anything about it. We could replace all minidom usage with etree, I think, but that would be a big lift. assertPyxformXform uses etree because it needs more granular control over the XML, I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants