Skip to content

Commit

Permalink
Merge "columns: Useful __str__, __repr__ implementation"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Oct 4, 2022
2 parents d1b46e9 + 67217b0 commit 91c6298
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cliff/columns.py
Expand Up @@ -31,6 +31,12 @@ def __lt__(self, other):
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."""
Expand Down
20 changes: 17 additions & 3 deletions cliff/tests/test_columns.py
Expand Up @@ -23,17 +23,31 @@ def human_readable(self):

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'),
Expand Down

0 comments on commit 91c6298

Please sign in to comment.