diff options
-rw-r--r-- | cliff/columns.py | 6 | ||||
-rw-r--r-- | cliff/tests/test_columns.py | 20 |
2 files changed, 23 insertions, 3 deletions
diff --git a/cliff/columns.py b/cliff/columns.py index b9cac5e..3462176 100644 --- a/cliff/columns.py +++ b/cliff/columns.py @@ -31,6 +31,12 @@ class FormattableColumn(object, metaclass=abc.ABCMeta): self.__class__ == other.__class__ and self._value < other._value ) + def __str__(self): + return self.human_readable() + + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.machine_readable()) + @abc.abstractmethod def human_readable(self): """Return a basic human readable version of the data.""" diff --git a/cliff/tests/test_columns.py b/cliff/tests/test_columns.py index 6bce767..364d258 100644 --- a/cliff/tests/test_columns.py +++ b/cliff/tests/test_columns.py @@ -23,17 +23,31 @@ class FauxColumn(columns.FormattableColumn): class TestColumns(unittest.TestCase): - def test_faux_column_machine(self): + def test_machine_readable(self): c = FauxColumn(['list', 'of', 'values']) self.assertEqual(['list', 'of', 'values'], c.machine_readable()) - def test_faux_column_human(self): + def test_human_readable(self): c = FauxColumn(['list', 'of', 'values']) self.assertEqual( - u"I made this string myself: ['list', 'of', 'values']", + "I made this string myself: ['list', 'of', 'values']", c.human_readable(), ) + def test_str(self): + c = FauxColumn(['list', 'of', 'values']) + self.assertEqual( + "I made this string myself: ['list', 'of', 'values']", + str(c), + ) + + def test_repr(self): + c = FauxColumn(['list', 'of', 'values']) + self.assertEqual( + "FauxColumn(['list', 'of', 'values'])", + repr(c), + ) + def test_sorting(self): cols = [ FauxColumn('foo'), |