summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2020-11-04 14:38:54 +0000
committerStephen Finucane <sfinucan@redhat.com>2020-11-04 15:17:41 +0000
commit997e05fce6cf2267099f3d5f91116ba491495d7e (patch)
tree585008c777125505a93c97dabdcc2d50057f5890
parentdef32ec54cbec667bb5733b14c8404c72d3547d0 (diff)
downloadcliff-997e05fce6cf2267099f3d5f91116ba491495d7e.tar.gz
columns: Make 'FormattableColumn' comparable
Currently, comparing instances of this fails: >>> from cliff.columns import FormattableColumn >>> class Test(FormattableColumn): ... def human_readable(self): ... return str(self._data) ... >>> data = {'x': 'y'} >>> x = Test(data) >>> y = Test(data) >>> x == y False Clearly it should not. Resolve this by implementing a custom comparison. Change-Id: I4b96475ca6a689f4055dc5ea34b82b3867a65555 Signed-off-by: Stephen Finucane <sfinucan@redhat.com> Story: #2008320 Task: #41218
-rw-r--r--cliff/columns.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/cliff/columns.py b/cliff/columns.py
index abf1c4f..3b3c2bc 100644
--- a/cliff/columns.py
+++ b/cliff/columns.py
@@ -24,10 +24,14 @@ class FormattableColumn(object):
def __init__(self, value):
self._value = value
+ def __eq__(self, other):
+ return (
+ self.__class__ == other.__class__ and self._value == other._value
+ )
+
@abc.abstractmethod
def human_readable(self):
- """Return a basic human readable version of the data.
- """
+ """Return a basic human readable version of the data."""
def machine_readable(self):
"""Return a raw data structure using only Python built-in types.
@@ -35,6 +39,5 @@ class FormattableColumn(object):
It must be possible to serialize the return value directly
using a formatter like JSON, and it will be up to the
formatter plugin to decide how to make that transformation.
-
"""
return self._value