Skip to content

Commit c8165d6

Browse files
committed
Add __str__ implementation to Diffs
In order to make them more easily read by humans than they are currently. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent e30395c commit c8165d6

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
# MANDATORY CHECKS USING CURRENT DEVELOPMENT INTERPRETER
2828
- dependencies: >
2929
pylint
30+
python3-deepdiff
3031
python3-dbus
3132
python3-dbus-python-client-gen
3233
python3-justbytes

.github/workflows/weekly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
# PYTHON CHECKS ON NEXT FEDORA PYTHON AND PYTHON TOOLS VERSION
1818
- dependencies: >
1919
pylint
20+
python3-deepdiff
2021
python3-dbus
2122
python3-dbus-python-client-gen
2223
python3-gobject

scripts/monitor_dbus_signals.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
# isort: THIRDPARTY
5252
import dbus
5353
import dbus.mainloop.glib
54+
from deepdiff.diff import DeepDiff
5455
from gi.repository import GLib
5556

5657
# isort: FIRSTPARTY
@@ -451,6 +452,13 @@ def __repr__(self):
451452
f"{self.key!r}, {self.new_value!r})"
452453
)
453454

455+
def __str__(self):
456+
return (
457+
f"Added Property:{os.linesep} {self.object_path}{os.linesep}"
458+
f" {self.interface_name}{os.linesep} {self.key}{os.linesep}"
459+
f" {self.new_value}"
460+
)
461+
454462
class RemovedProperty(Diff): # pylint: disable=too-few-public-methods
455463
"""
456464
Property appears in recorded result but not in new result.
@@ -468,6 +476,13 @@ def __repr__(self):
468476
f"{self.key!r}, {self.old_value!r})"
469477
)
470478

479+
def __str__(self):
480+
return (
481+
f"Removed Property:{os.linesep} {self.object_path}{os.linesep}"
482+
f" {self.interface_name}{os.linesep} {self.key}{os.linesep}"
483+
f" {self.old_value}"
484+
)
485+
471486
class DifferentProperty(Diff): # pylint: disable=too-few-public-methods
472487
"""
473488
Difference between two properties.
@@ -488,6 +503,18 @@ def __repr__(self):
488503
f"{self.key!r}, {self.old_value!r}, {self.new_value!r})"
489504
)
490505

506+
def __str__(self):
507+
diffs = os.linesep.join(
508+
f" {line}"
509+
for line in DeepDiff(self.old_value, self.new_value).pretty()
510+
)
511+
return (
512+
f"Different Property:{os.linesep}"
513+
f" {self.object_path}{os.linesep} {self.key}{os.linesep}"
514+
f" {self.old_value!r}{os.linesep}"
515+
f" {self.new_value!r}{os.linesep}{diffs}"
516+
)
517+
491518
class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods
492519
"""
493520
Represents a case where the property should have been invalidated but
@@ -510,6 +537,14 @@ def __repr__(self):
510537
f"{self.new_value!r})"
511538
)
512539

540+
def __str__(self):
541+
return (
542+
f"Not Invalidated Property:{os.linesep}"
543+
f" {self.object_path}{os.linesep}"
544+
f" {self.interface_name}{os.linesep} {self.key}{os.linesep}"
545+
f" {self.new_value}"
546+
)
547+
513548
class ChangedProperty(Diff): # pylint: disable=too-few-public-methods
514549
"""
515550
Represents a case where the property should have been constant but
@@ -532,6 +567,18 @@ def __repr__(self):
532567
f"{self.new_value!r})"
533568
)
534569

570+
def __str__(self):
571+
diffs = os.linesep.join(
572+
f" {line}"
573+
for line in DeepDiff(self.old_value, self.new_value).pretty()
574+
)
575+
return (
576+
f"Changed Property:{os.linesep} {self.object_path}{os.linesep}"
577+
f" {self.interface_name}{os.linesep} {self.key}{os.linesep}"
578+
f" {self.old_value}{os.linesep} {self.new_value}{os.linesep}"
579+
f"{diffs}"
580+
)
581+
535582
class RemovedObjectPath(Diff): # pylint: disable=too-few-public-methods
536583
"""
537584
Object path appears in recorded result but not in new result.
@@ -544,6 +591,12 @@ def __init__(self, object_path, old_value):
544591
def __repr__(self):
545592
return f"RemovedObjectPath({self.object_path!r}, {self.old_value!r})"
546593

594+
def __str__(self):
595+
return (
596+
f"Removed Object Path:{os.linesep}"
597+
f"{self.object_path}{os.linesep} {self.old_value}"
598+
)
599+
547600
class AddedInterface(Diff): # pylint: disable=too-few-public-methods
548601
"""
549602
Interface appears in new result but not in recorded result.
@@ -560,6 +613,12 @@ def __repr__(self):
560613
f"{self.new_value!r})"
561614
)
562615

616+
def __str__(self):
617+
return (
618+
f"Added Interface:{os.linesep} {self.object_path}{os.linesep}"
619+
f" {self.interface_name}{os.linesep} {self.new_value}"
620+
)
621+
563622
class AddedObjectPath(Diff): # pylint: disable=too-few-public-methods
564623
"""
565624
Object path appears in new result but not in recorded result.
@@ -572,6 +631,12 @@ def __init__(self, object_path, new_value):
572631
def __repr__(self):
573632
return f"AddedObjectPath({self.object_path!r}, {self.new_value!r})"
574633

634+
def __str__(self):
635+
return (
636+
f"Added Object Path:{os.linesep}"
637+
f" {self.object_path}{os.linesep} {self.new_value}"
638+
)
639+
575640
class RemovedInterface(Diff): # pylint: disable=too-few-public-methods
576641
"""
577642
Interface appears in recorded result but not in new result.
@@ -588,6 +653,13 @@ def __repr__(self):
588653
f"{self.old_value!r})"
589654
)
590655

656+
def __str__(self):
657+
return (
658+
f"Removed Interface:{os.linesep}"
659+
f" {self.object_path}{os.linesep}"
660+
f" {self.interface_name}{os.linesep} {self.old_value}"
661+
)
662+
591663
class MissingInterface(Diff): # pylint: disable=too-few-public-methods
592664
"""
593665
Attempted to update a property on this interface, but the interface
@@ -601,6 +673,12 @@ def __init__(self, object_path, interface_name):
601673
def __repr__(self):
602674
return f"MissingInterface({self.object_path!r}, {self.interface_name!r}"
603675

676+
def __str__(self):
677+
return (
678+
f"Missing Interface:{os.linesep}"
679+
f" {self.object_path}{os.linesep} {self.interface_name}"
680+
)
681+
604682
def _check_props(object_path, ifn, old_props, new_props):
605683
"""
606684
Find differences between two sets of properties.

0 commit comments

Comments
 (0)