Skip to content

Commit

Permalink
Add __str__ implementation to Diffs
Browse files Browse the repository at this point in the history
In order to make them more easily read by humans than they are
currently.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Nov 20, 2024
1 parent e30395c commit dc4bd10
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
# MANDATORY CHECKS USING CURRENT DEVELOPMENT INTERPRETER
- dependencies: >
pylint
python3-deepdiff
python3-dbus
python3-dbus-python-client-gen
python3-justbytes
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions scripts/monitor_dbus_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
# isort: THIRDPARTY
import dbus
import dbus.mainloop.glib
from deepdiff.diff import DeepDiff
from gi.repository import GLib

# isort: FIRSTPARTY
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit dc4bd10

Please sign in to comment.