Skip to content

Modify tester to standardize document IDs

David Burghoff requested to merge inkscape-burghoff2/extensions:master into master

What does the merge request do?

This merge request modifies the xmldiff function of the tester environment. Prior to looking for diffs, inkex.tester.xmldiff now assigns every node a unique ID corresponding to its location in the document, replacing all instances of the original ID (including in references). The unique ID is a simplified version of its xpath address, an "xpath ID" of the format "xpId/[index0]/[index1]/...". Following this, any attribute/style text that is ID-like and has not already been replaced will also be replaced, with a new ID of the format "[node xpath ID]_[index]."

This is effectively a permanently-applied filter. I am not sure if this is ideal, but I have been using it for several months and it has made testing and debugging considerably easier. It obviates the need for the CompareWithoutIDs filter, but unlike that filter replaces references, not just the original ID. Therefore, it will catch bugs that arise due to references being unlinked from their IDs, which CompareWithoutIDs will miss. Furthermore, it will not falsely report differences between two SVGs that are effectively identical but may have been generated slightly differently (for example, because the order in which two objects were generated changed).

Furthermore, the delta logger has been modified to make delta identification easier in large documents. All attribute and text deltas now include the original ID if possible, and if a node originally had no ID it will include the xpath-ID instead. When an attribute or text difference arises, one can now more easily see the culprit.

I originally implemented this because the text submodule I am working on replaces the get_unique_id function with a version that assigns IDs in numerical order rather than randomly. While this is normally only relevant when the submodule is loaded, the submodule is loaded at the beginning of testing and was causing many Inkex tests to fail due to trivial ID changes. Without the change, 187 tests fail. With the change, they all pass.

Implementation notes

This modifies xmldiff.py to use an lxml parser rather than an xml parser.

An additional unit test was added to test_inkex_tester.py, which tests the xpath_ids function. It compares css.svg with an ID-swapped css_idswap.svg, ensuring that they appear as identical. This was chosen because it includes IDs in their usual location and inside CSS in various formats.

This MR was split from an earlier one with additional discussion and review.

Checklist

  • Add unit tests (if applicable)
  • Changes to inkex/ are well documented
  • Clean merge request history
Edited by David Burghoff

Merge request reports