Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __str__ implementation to Diffs #291

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
81 changes: 80 additions & 1 deletion 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,19 @@ def __repr__(self):
f"{self.key!r}, {self.old_value!r}, {self.new_value!r})"
)

def __str__(self):
return (
f"Different Property:{os.linesep}"
f" {self.object_path}{os.linesep} {self.key}{os.linesep}"
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()
.split(os.linesep)
)

class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods
"""
Represents a case where the property should have been invalidated but
Expand All @@ -510,6 +538,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
Expand All @@ -532,6 +568,18 @@ def __repr__(self):
f"{self.new_value!r})"
)

def __str__(self):
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}"
) + os.linesep.join(
f" {line}"
for line in DeepDiff(self.old_value, self.new_value)
.pretty()
.split(os.linesep)
)

class RemovedObjectPath(Diff): # pylint: disable=too-few-public-methods
"""
Object path appears in recorded result but not in new result.
Expand All @@ -544,6 +592,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 +614,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 +632,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 +654,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 +674,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 Expand Up @@ -741,5 +820,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)