summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVipin Balachandran <vbala@vmware.com>2016-11-18 15:25:45 +0530
committerVipin Balachandran <vbala@vmware.com>2016-11-22 13:25:46 +0530
commit80b28562eddb22c1add9ac950e689ee7bc586d93 (patch)
treec97f444f87778d64e931c5489b52cc8e2bcc17fc
parent7f8dfd65d269c14925734b14dd87fcbacb40d9fa (diff)
downloadosprofiler-80b28562eddb22c1add9ac950e689ee7bc586d93.tar.gz
Pretty print json output
Adding kwarg indent in json.dumps() to pretty print the trace output in json format. Change-Id: Icea772bd18e366ad576de7dbc2afc11b2fb376b9
-rw-r--r--osprofiler/cmd/commands.py3
-rw-r--r--osprofiler/tests/cmd/test_shell.py5
2 files changed, 5 insertions, 3 deletions
diff --git a/osprofiler/cmd/commands.py b/osprofiler/cmd/commands.py
index 99be83e..876493b 100644
--- a/osprofiler/cmd/commands.py
+++ b/osprofiler/cmd/commands.py
@@ -76,7 +76,8 @@ class TraceCommands(BaseCommand):
return obj
if args.use_json:
- output = json.dumps(trace, default=datetime_json_serialize)
+ output = json.dumps(trace, default=datetime_json_serialize,
+ indent=2)
elif args.use_html:
with open(os.path.join(os.path.dirname(__file__),
"template.html")) as html_template:
diff --git a/osprofiler/tests/cmd/test_shell.py b/osprofiler/tests/cmd/test_shell.py
index fa79c27..fc573ed 100644
--- a/osprofiler/tests/cmd/test_shell.py
+++ b/osprofiler/tests/cmd/test_shell.py
@@ -174,7 +174,7 @@ class ShellTestCase(test.TestCase):
mock_get.return_value = notifications
self.run_command("trace show fake_id --json")
- self.assertEqual("%s\n" % json.dumps(notifications),
+ self.assertEqual("%s\n" % json.dumps(notifications, indent=2),
sys.stdout.getvalue())
@mock.patch("sys.stdout", six.StringIO())
@@ -222,4 +222,5 @@ class ShellTestCase(test.TestCase):
self.run_command("trace show fake_id --json --out='/file'")
output = mock_open.return_value.__enter__.return_value
- output.write.assert_called_once_with(json.dumps(notifications))
+ output.write.assert_called_once_with(json.dumps(notifications,
+ indent=2))