gfw.common.diff#

General utilities for generating diffs between objects.

Functions

compare_items

Generate a rich diff of two objects' pretty-printed representations.

diff_lines

Generate a line-by-line diff of two strings with rich markup.

render_diff_panel

Render side-by-side panels of diff strings for visual comparison.

diff_lines(a, b)[source]#

Generate a line-by-line diff of two strings with rich markup.

Parameters:
  • a (str) – First multi-line string to compare.

  • b (str) – Second multi-line string to compare.

Returns:

  • a_diff: The first string annotated with diff highlights.

  • b_diff: The second string annotated with diff highlights.

  • changed: True if any differences were found, False otherwise.

Return type:

A tuple of (a_diff, b_diff, changed) where

compare_items(a, b)[source]#

Generate a rich diff of two objects’ pretty-printed representations.

Parameters:
  • a (Any) – First object to compare.

  • b (Any) – Second object to compare.

Returns:

The object returned by diff_lines.

Return type:

Tuple[str, str, bool]

render_diff_panel(left, right, idx)[source]#

Render side-by-side panels of diff strings for visual comparison.

Parameters:
  • left (str) – The left-side diff string (usually actual output).

  • right (str) – The right-side diff string (usually expected output).

  • idx (int) – Index number for labeling the diff panels.

Returns:

A rich Columns object containing two Panels side-by-side.

Return type:

Columns