Skip to content
Snippets Groups Projects
Commit 91c62985 authored by Zuul's avatar Zuul Committed by Gerrit Code Review
Browse files

Merge "columns: Useful __str__, __repr__ implementation"

parents d1b46e9f 67217b0e
No related branches found
Tags 4.1.0
No related merge requests found
......@@ -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."""
......
......@@ -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'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment