Skip to content

Add t1_name/t2_name to rename t1/t2 labels in tree view repr - #618

Open
ChrisJr404 wants to merge 1 commit into
qlustered:devfrom
ChrisJr404:feat-t1-t2-names
Open

Add t1_name/t2_name to rename t1/t2 labels in tree view repr#618
ChrisJr404 wants to merge 1 commit into
qlustered:devfrom
ChrisJr404:feat-t1-t2-names

Conversation

@ChrisJr404

Copy link
Copy Markdown

This adds t1_name and t2_name parameters to DeepDiff so the t1/t2 labels in the tree view's string representation can be renamed, as suggested in #531.

Right now the DiffLevel repr hardcodes those labels:

>>> DeepDiff({'status': 'UP'}, {'status': 'DOWN'}, view='tree')
{'values_changed': [<root['status'] t1:"UP", t2:"DOWN">]}

With the new parameters you can give the two objects meaningful names:

>>> DeepDiff({'status': 'UP'}, {'status': 'DOWN'}, view='tree',
...          t1_name='before', t2_name='after')
{'values_changed': [<root['status'] before:"UP", after:"DOWN">]}

Notes on the implementation:

  • The labels default to "t1"/"t2", so existing output is completely unchanged.
  • They only affect the repr of tree view levels. The text view result and the comparison itself are untouched.
  • The names are stored on the root DiffLevel and propagate to child levels through the existing create_deeper/copy machinery (same path verbose_level already uses), so nested nodes render with the custom labels too.
  • Externally-supplied _parameters dicts that predate this change (and therefore don't include the keys) fall back to the defaults, so nothing breaks there.

Added tests in tests/test_model.py covering the custom labels, propagation to nested levels, the unchanged defaults, and that the text view is unaffected. Also updated the tree view docs, the parameter reference, CHANGELOG.md, and AUTHORS.md.

Closes #531

The DiffLevel string representation hardcodes the t1 and t2 labels,
e.g. <root['a'] t1:1, t2:2>. These parameters let callers rename them to
something meaningful such as before/after, which is clearer when the
two compared objects have distinct roles.

The labels default to t1/t2 so existing output is unchanged, and they
only affect the tree view repr, not the text view or the comparison.

Closes qlustered#531
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

Successfully merging this pull request may close these issues.

1 participant