tests: fix generated_document tests with py 3.8 (#42359)

This commit is contained in:
Lauréline Guérin 2020-06-18 16:04:49 +02:00
parent f31a57e803
commit 020ec09e9c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
1 changed files with 10 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import zipfile
import base64
from webtest import Upload, Hidden
import mock
import xml.etree.ElementTree as ET
try:
from PIL import Image
@ -64,7 +65,15 @@ def assert_equal_zip(stream1, stream2):
for name in z1.namelist():
if name == 'styles.xml':
continue
t1, t2 = z1.read(name), z2.read(name)
if name in ['content.xml', 'meta.xml']:
t1, t2 = ET.tostring(ET.XML(z1.read(name))), ET.tostring(ET.XML(z2.read(name)))
try:
# >= python 3.8: tostring preserves attribute order; use canonicalize to sort them
t1, t2 = ET.canonicalize(t1), ET.canonicalize(t2)
except AttributeError:
pass
else:
t1, t2 = z1.read(name), z2.read(name)
assert t1 == t2, 'file "%s" differs' % name