Index: tests/test_packagerWebExt.py |
diff --git a/tests/test_packagerWebExt.py b/tests/test_packagerWebExt.py |
index f13ab10ac164a9055d06340d1d9b02c08339b598..bcdf34f591e02c7db018743e6a976ae1ffa2574e 100644 |
--- a/tests/test_packagerWebExt.py |
+++ b/tests/test_packagerWebExt.py |
@@ -240,39 +240,6 @@ def lib_files(tmpdir): |
return files |
-def comparable_xml(xml): |
- """Create a nonambiguous representation of a given XML tree. |
- |
- Note that this function is not safe against ambiguous tags |
- containing differently distributed children, e.g.: |
- |
- '<a><b><c/></b><b><d/></b></a>' |
- vs. |
- '<a><b/><b><c/><d/></b></a>' |
- |
- This is irrelevant for comparing the XML used by the tests of this |
- module. |
- """ |
- def get_leafs_string(tree): |
- """Recursively build a string representing all xml leaf-nodes.""" |
- root_str = '{}|{}|{}'.format(tree.tag, tree.tail, tree.text).strip() |
- result = [] |
- |
- if len(tree) > 0: |
- for subtree in tree: |
- for leaf in get_leafs_string(subtree): |
- result.append('{}__{}'.format(root_str, leaf)) |
- for k, v in tree.attrib.items(): |
- result.append('{}__{}:{}'.format(root_str, k, v)) |
- else: |
- result.append(root_str) |
- return result |
- |
- # XML data itself shall not be sorted, hence we can safely sort |
- # our string representations in order to produce a valid unified diff. |
- return sorted(get_leafs_string(ElementTree.fromstring(xml))) |
- |
- |
def comparable_json(json_string): |
"""Create a nonambiguous representation of a given JSON string.""" |
return json.dumps( |
@@ -280,6 +247,21 @@ def comparable_json(json_string): |
).split('\n') |
+def comparable_xml(xml): |
+ """Create a nonambiguous representation of a given XML tree.""" |
+ def strip(s): |
+ if s is None: |
+ return '' |
+ return s.strip() |
+ |
+ def transform(elt): |
+ subs = sorted(transform(s) for s in elt) |
+ attrs = tuple('{}={}'.format(k, v) for k, v in elt.attrib.items()) |
Vasily Kuznetsov
2017/10/23 12:48:20
Since you're doing a `comparable_json` later, we c
tlucas
2017/10/23 13:21:36
Good point - Done.
|
+ return (elt.tag, strip(elt.tail), strip(elt.text), attrs, subs) |
+ |
+ return comparable_json(json.dumps(transform(ElementTree.fromstring(xml)))) |
Vasily Kuznetsov
2017/10/23 12:48:20
Its kind of a pity that we're doing `json.dumps` h
tlucas
2017/10/23 13:21:36
No, you are right - dumps(loads(dumps())) is defin
|
+ |
+ |
def assert_manifest_content(manifest, expected_path): |
extension = os.path.basename(expected_path).split('.')[-1] |