Add 'SizeColumn' formatter
Present file sizes in human readable format. Change-Id: I7e4a013cba7f91e38ba496d3ba7c4a67c4cd81c5 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>changes/74/862174/2
parent
4bb2e57358
commit
6152b686b7
|
@ -58,3 +58,10 @@ class ListDictColumn(columns.FormattableColumn):
|
|||
|
||||
def machine_readable(self):
|
||||
return [dict(x) for x in self._value or []]
|
||||
|
||||
|
||||
class SizeColumn(columns.FormattableColumn):
|
||||
"""Format column for file size content"""
|
||||
|
||||
def human_readable(self):
|
||||
return utils.format_size(self._value)
|
||||
|
|
|
@ -109,3 +109,12 @@ class TestListDictColumn(utils.TestCase):
|
|||
self.assertEqual(type(col.machine_readable()), list)
|
||||
for x in col.machine_readable():
|
||||
self.assertEqual(type(x), dict)
|
||||
|
||||
|
||||
class TestSizeColumn(utils.TestCase):
|
||||
|
||||
def test_size_column(self):
|
||||
content = 1576395005
|
||||
col = format_columns.SizeColumn(content)
|
||||
self.assertEqual(content, col.machine_readable())
|
||||
self.assertEqual('1.6G', col.human_readable())
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
A new column formatter, ``SizeFormatter``, is available. This can be used
|
||||
to format file sizes in human readable format.
|
Loading…
Reference in New Issue