From dc4bd10808c8db81d0a2c2ea356f46ea51e1b494 Mon Sep 17 00:00:00 2001 From: mulhern Date: Wed, 20 Nov 2024 14:24:36 -0500 Subject: [PATCH] Add __str__ implementation to Diffs In order to make them more easily read by humans than they are currently. Signed-off-by: mulhern --- .github/workflows/main.yml | 1 + .github/workflows/weekly.yml | 1 + scripts/monitor_dbus_signals.py | 78 +++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f36e85..b16f2c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,7 @@ jobs: # MANDATORY CHECKS USING CURRENT DEVELOPMENT INTERPRETER - dependencies: > pylint + python3-deepdiff python3-dbus python3-dbus-python-client-gen python3-justbytes diff --git a/.github/workflows/weekly.yml b/.github/workflows/weekly.yml index f9f9b3a..8c51c37 100644 --- a/.github/workflows/weekly.yml +++ b/.github/workflows/weekly.yml @@ -17,6 +17,7 @@ jobs: # PYTHON CHECKS ON NEXT FEDORA PYTHON AND PYTHON TOOLS VERSION - dependencies: > pylint + python3-deepdiff python3-dbus python3-dbus-python-client-gen python3-gobject diff --git a/scripts/monitor_dbus_signals.py b/scripts/monitor_dbus_signals.py index 289fad8..eef977d 100755 --- a/scripts/monitor_dbus_signals.py +++ b/scripts/monitor_dbus_signals.py @@ -51,6 +51,7 @@ # isort: THIRDPARTY import dbus import dbus.mainloop.glib + from deepdiff.diff import DeepDiff from gi.repository import GLib # isort: FIRSTPARTY @@ -451,6 +452,13 @@ def __repr__(self): f"{self.key!r}, {self.new_value!r})" ) + def __str__(self): + return ( + f"Added Property:{os.linesep} {self.object_path}{os.linesep}" + f" {self.interface_name}{os.linesep} {self.key}{os.linesep}" + f" {self.new_value}" + ) + class RemovedProperty(Diff): # pylint: disable=too-few-public-methods """ Property appears in recorded result but not in new result. @@ -468,6 +476,13 @@ def __repr__(self): f"{self.key!r}, {self.old_value!r})" ) + def __str__(self): + return ( + f"Removed Property:{os.linesep} {self.object_path}{os.linesep}" + f" {self.interface_name}{os.linesep} {self.key}{os.linesep}" + f" {self.old_value}" + ) + class DifferentProperty(Diff): # pylint: disable=too-few-public-methods """ Difference between two properties. @@ -488,6 +503,18 @@ def __repr__(self): f"{self.key!r}, {self.old_value!r}, {self.new_value!r})" ) + def __str__(self): + diffs = os.linesep.join( + f" {line}" + for line in DeepDiff(self.old_value, self.new_value).pretty() + ) + return ( + f"Different Property:{os.linesep}" + f" {self.object_path}{os.linesep} {self.key}{os.linesep}" + f" {self.old_value!r}{os.linesep}" + f" {self.new_value!r}{os.linesep}{diffs}" + ) + class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods """ Represents a case where the property should have been invalidated but @@ -510,6 +537,14 @@ def __repr__(self): f"{self.new_value!r})" ) + def __str__(self): + return ( + f"Not Invalidated Property:{os.linesep}" + f" {self.object_path}{os.linesep}" + f" {self.interface_name}{os.linesep} {self.key}{os.linesep}" + f" {self.new_value!r}" + ) + class ChangedProperty(Diff): # pylint: disable=too-few-public-methods """ Represents a case where the property should have been constant but @@ -532,6 +567,18 @@ def __repr__(self): f"{self.new_value!r})" ) + def __str__(self): + diffs = os.linesep.join( + f" {line}" + for line in DeepDiff(self.old_value, self.new_value).pretty() + ) + return ( + f"Changed Property:{os.linesep} {self.object_path}{os.linesep}" + f" {self.interface_name}{os.linesep} {self.key}{os.linesep}" + f" {self.old_value}{os.linesep} {self.new_value}{os.linesep}" + f"{diffs}" + ) + class RemovedObjectPath(Diff): # pylint: disable=too-few-public-methods """ Object path appears in recorded result but not in new result. @@ -544,6 +591,12 @@ def __init__(self, object_path, old_value): def __repr__(self): return f"RemovedObjectPath({self.object_path!r}, {self.old_value!r})" + def __str__(self): + return ( + f"Removed Object Path:{os.linesep}" + f"{self.object_path}{os.linesep} {self.old_value}" + ) + class AddedInterface(Diff): # pylint: disable=too-few-public-methods """ Interface appears in new result but not in recorded result. @@ -560,6 +613,12 @@ def __repr__(self): f"{self.new_value!r})" ) + def __str__(self): + return ( + f"Added Interface:{os.linesep} {self.object_path}{os.linesep}" + f" {self.interface_name}{os.linesep} {self.new_value}" + ) + class AddedObjectPath(Diff): # pylint: disable=too-few-public-methods """ Object path appears in new result but not in recorded result. @@ -572,6 +631,12 @@ def __init__(self, object_path, new_value): def __repr__(self): return f"AddedObjectPath({self.object_path!r}, {self.new_value!r})" + def __str__(self): + return ( + f"Added Object Path:{os.linesep}" + f" {self.object_path}{os.linesep} {self.new_value}" + ) + class RemovedInterface(Diff): # pylint: disable=too-few-public-methods """ Interface appears in recorded result but not in new result. @@ -588,6 +653,13 @@ def __repr__(self): f"{self.old_value!r})" ) + def __str__(self): + return ( + f"Removed Interface:{os.linesep}" + f" {self.object_path}{os.linesep}" + f" {self.interface_name}{os.linesep} {self.old_value}" + ) + class MissingInterface(Diff): # pylint: disable=too-few-public-methods """ Attempted to update a property on this interface, but the interface @@ -601,6 +673,12 @@ def __init__(self, object_path, interface_name): def __repr__(self): return f"MissingInterface({self.object_path!r}, {self.interface_name!r}" + def __str__(self): + return ( + f"Missing Interface:{os.linesep}" + f" {self.object_path}{os.linesep} {self.interface_name}" + ) + def _check_props(object_path, ifn, old_props, new_props): """ Find differences between two sets of properties.