Prints '-' instead of 'None' when data is None
Client prints 'None' when data is None , and client also prints 'None' when data is a string 'None'. But string 'None' is different to None. To clarify the confusion, Client should print '-' instead of 'None' when data is None. Nova Client and Cinder Client has clarified the confusion. Change-Id: I6a8908fcb2df39d7f2c5fc4055cc41779d668d6c
This commit is contained in:
@@ -80,6 +80,8 @@ def format_nested_dict(d, fields, column_names):
|
||||
value = d[field]
|
||||
if not isinstance(value, six.string_types):
|
||||
value = jsonutils.dumps(value, indent=2, ensure_ascii=False)
|
||||
if value is None:
|
||||
value = '-'
|
||||
pt.add_row([field, value.strip('"')])
|
||||
|
||||
return pt.get_string()
|
||||
@@ -129,13 +131,15 @@ def _print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
row = []
|
||||
for field in fields:
|
||||
if field in formatters:
|
||||
row.append(formatters[field](o))
|
||||
data = formatters[field](o)
|
||||
else:
|
||||
if field in mixed_case_fields:
|
||||
field_name = field.replace(' ', '_')
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
if data is None:
|
||||
data = '-'
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
@@ -169,9 +173,12 @@ def print_dict(d, formatters=None):
|
||||
|
||||
for field in d.keys():
|
||||
if field in formatters:
|
||||
pt.add_row([field, formatters[field](d[field])])
|
||||
data = formatters[field](d[field])
|
||||
else:
|
||||
pt.add_row([field, d[field]])
|
||||
data = d[field]
|
||||
if data is None:
|
||||
data = '-'
|
||||
pt.add_row([field, data])
|
||||
|
||||
content = pt.get_string(sortby='Property')
|
||||
if six.PY3:
|
||||
|
@@ -130,7 +130,7 @@ class PrintListTestCase(testtools.TestCase):
|
||||
+-----------+-----------+
|
||||
""", cso.read())
|
||||
|
||||
def test_print_list_with_None_data(self):
|
||||
def test_print_list_with_None_string(self):
|
||||
Row = collections.namedtuple('Row', ['foo', 'bar'])
|
||||
to_print = [Row(foo='fake_foo1', bar='None'),
|
||||
Row(foo='fake_foo2', bar='fake_bar1')]
|
||||
@@ -144,6 +144,22 @@ class PrintListTestCase(testtools.TestCase):
|
||||
| fake_foo1 | None |
|
||||
| fake_foo2 | fake_bar1 |
|
||||
+-----------+-----------+
|
||||
""", cso.read())
|
||||
|
||||
def test_print_list_with_None_data(self):
|
||||
Row = collections.namedtuple('Row', ['foo', 'bar'])
|
||||
to_print = [Row(foo='fake_foo1', bar=None),
|
||||
Row(foo='fake_foo2', bar='fake_bar1')]
|
||||
with CaptureStdout() as cso:
|
||||
utils.print_list(to_print, ['foo', 'bar'])
|
||||
# Output should be sorted by the first key (foo)
|
||||
self.assertEqual("""\
|
||||
+-----------+-----------+
|
||||
| foo | bar |
|
||||
+-----------+-----------+
|
||||
| fake_foo1 | - |
|
||||
| fake_foo2 | fake_bar1 |
|
||||
+-----------+-----------+
|
||||
""", cso.read())
|
||||
|
||||
def test_print_list_with_list_sortby(self):
|
||||
@@ -211,4 +227,20 @@ class PrintDictTestCase(testtools.TestCase):
|
||||
| bar | fake_bar |
|
||||
| foo | fake_foo |
|
||||
+----------+----------+
|
||||
""", cso.read())
|
||||
|
||||
def test_print_dict_with_None_data(self):
|
||||
Row = collections.namedtuple('Row', ['foo', 'bar'])
|
||||
to_print = [Row(foo='fake_foo1', bar=None),
|
||||
Row(foo='fake_foo2', bar='fake_bar1')]
|
||||
with CaptureStdout() as cso:
|
||||
utils.print_list(to_print, ['foo', 'bar'])
|
||||
# Output should be sorted by the first key (foo)
|
||||
self.assertEqual("""\
|
||||
+-----------+-----------+
|
||||
| foo | bar |
|
||||
+-----------+-----------+
|
||||
| fake_foo1 | - |
|
||||
| fake_foo2 | fake_bar1 |
|
||||
+-----------+-----------+
|
||||
""", cso.read())
|
||||
|
Reference in New Issue
Block a user