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

Cannot roundtrip Python 3.9 stdlib xml/dom/minidom.py #196

Open
bnavigator opened this issue Mar 19, 2021 · 0 comments
Open

Cannot roundtrip Python 3.9 stdlib xml/dom/minidom.py #196

bnavigator opened this issue Mar 19, 2021 · 0 comments

Comments

@bnavigator
Copy link

[    2s] + PYTHONPATH=/home/abuild/rpmbuild/BUILDROOT/python-astor-0.8.1-0.x86_64/usr/lib/python3.9/site-packages
[    2s] + PYTHONDONTWRITEBYTECODE=1
[    2s] + pytest-3.9 --ignore=_build.python39 --ignore=_build.python38 -v tests
[    2s] ============================= test session starts ==============================
[    2s] platform linux -- Python 3.9.2, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3.9
[    2s] cachedir: .pytest_cache
[    2s] rootdir: /home/abuild/rpmbuild/BUILD/astor-0.8.1
[    2s] collecting ... collected 55 items
...
[    9s] =================================== FAILURES ===================================
[    9s] ______________________ RtripTestCase.test_convert_stdlib _______________________
[    9s] 
[    9s] self = <tests.test_rtrip.RtripTestCase testMethod=test_convert_stdlib>
[    9s] 
[    9s]     def test_convert_stdlib(self):
[    9s]         srcdir = os.path.dirname(os.__file__)
[    9s]         result = astor.rtrip.convert(srcdir)
[    9s] >       self.assertEqual(result, [])
[    9s] E       AssertionError: Lists differ: ['/usr/lib64/python3.9/xml/dom/minidom.py'] != []
[    9s] E       
[    9s] E       First list contains 1 additional elements.
[    9s] E       First extra element 0:
[    9s] E       '/usr/lib64/python3.9/xml/dom/minidom.py'
[    9s] E       
[    9s] E       - ['/usr/lib64/python3.9/xml/dom/minidom.py']
[    9s] E       + []
[    9s] 
[    9s] tests/test_rtrip.py:24: AssertionError
[    9s] ------------------------------ Captured log call -------------------------------
[    9s] WARNING  root:rtrip.py:112     calculating dump -- bad
[    9s] WARNING  root:rtrip.py:143 
[    9s] Files failed to round-trip to AST:
[    9s] WARNING  root:rtrip.py:145     /usr/lib64/python3.9/xml/dom/minidom.py
[    9s] =========================== short test summary info ============================
[    9s] FAILED tests/test_rtrip.py::RtripTestCase::test_convert_stdlib - AssertionErr...
[    9s] =================== 1 failed, 52 passed, 2 skipped in 7.26s ====================

Maybe related to #181, because

abuild@skylab:~> diff -u /usr/lib64/python3.[89]/xml/dom/minidom.py
...
@@ -1787,12 +1811,17 @@
             raise xml.dom.NotSupportedErr("cannot import document type nodes")
         return _clone_node(node, deep, self)
 
-    def writexml(self, writer, indent="", addindent="", newl="", encoding=None):
-        if encoding is None:
-            writer.write('<?xml version="1.0" ?>'+newl)
-        else:
-            writer.write('<?xml version="1.0" encoding="%s"?>%s' % (
-                encoding, newl))
+    def writexml(self, writer, indent="", addindent="", newl="", encoding=None,
+                 standalone=None):
+        declarations = []
+
+        if encoding:
+            declarations.append(f'encoding="{encoding}"')
+        if standalone is not None:
+            declarations.append(f'standalone="{"yes" if standalone else "no"}"')
+
+        writer.write(f'<?xml version="1.0" {" ".join(declarations)}?>{newl}')
+
         for node in self.childNodes:
             node.writexml(writer, indent, addindent, newl) 
@berkerpeksag berkerpeksag mentioned this issue Jan 1, 2025
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant