From c8165d63ba4c46f4ad8f7681c9a5ca7471a87f59 Mon Sep 17 00:00:00 2001 From: mulhern Date: Wed, 20 Nov 2024 14:24:36 -0500 Subject: [PATCH 1/4] 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..4989f37 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}" + ) + 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. From c8aec8998e131a4a95ddc5a5623407451144eb16 Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 22 Nov 2024 15:21:29 -0500 Subject: [PATCH 2/4] Require string representation Signed-off-by: mulhern --- scripts/monitor_dbus_signals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/monitor_dbus_signals.py b/scripts/monitor_dbus_signals.py index 4989f37..6b8fafc 100755 --- a/scripts/monitor_dbus_signals.py +++ b/scripts/monitor_dbus_signals.py @@ -819,5 +819,5 @@ def _check(): if not result: sys.exit(0) - print(os.linesep.join(sorted(repr(diff) for diff in result))) + print(os.linesep.join(sorted(str(diff) for diff in result))) sys.exit(1) From 93b6bbad81b151c75c57e63efd83f2c583678bbf Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 22 Nov 2024 15:35:03 -0500 Subject: [PATCH 3/4] Few more formatting fixes Signed-off-by: mulhern --- scripts/monitor_dbus_signals.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/monitor_dbus_signals.py b/scripts/monitor_dbus_signals.py index 6b8fafc..8214b95 100755 --- a/scripts/monitor_dbus_signals.py +++ b/scripts/monitor_dbus_signals.py @@ -504,15 +504,14 @@ def __repr__(self): ) 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}" + f" {self.old_value}{os.linesep}" + f" {self.new_value}{os.linesep}" + ) + os.linesep.join( + f" {line}" + for line in DeepDiff(self.old_value, self.new_value).pretty() ) class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods @@ -568,15 +567,13 @@ def __repr__(self): ) 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}" + ) + os.linesep.join( + f" {line}" + for line in DeepDiff(self.old_value, self.new_value).pretty() ) class RemovedObjectPath(Diff): # pylint: disable=too-few-public-methods From 3b899c46dfa5d85a12c5856847df59bd7a7f6cbf Mon Sep 17 00:00:00 2001 From: mulhern Date: Fri, 22 Nov 2024 15:44:21 -0500 Subject: [PATCH 4/4] Split pretty() result on line breaks Signed-off-by: mulhern --- scripts/monitor_dbus_signals.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/monitor_dbus_signals.py b/scripts/monitor_dbus_signals.py index 8214b95..56dd9a8 100755 --- a/scripts/monitor_dbus_signals.py +++ b/scripts/monitor_dbus_signals.py @@ -511,7 +511,9 @@ def __str__(self): f" {self.new_value}{os.linesep}" ) + os.linesep.join( f" {line}" - for line in DeepDiff(self.old_value, self.new_value).pretty() + for line in DeepDiff(self.old_value, self.new_value) + .pretty() + .split(os.linesep) ) class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods @@ -573,7 +575,9 @@ def __str__(self): f" {self.old_value}{os.linesep} {self.new_value}{os.linesep}" ) + os.linesep.join( f" {line}" - for line in DeepDiff(self.old_value, self.new_value).pretty() + for line in DeepDiff(self.old_value, self.new_value) + .pretty() + .split(os.linesep) ) class RemovedObjectPath(Diff): # pylint: disable=too-few-public-methods