@@ -305,6 +305,21 @@ def test_format_output_json(self):
305305 ret = formatting .format_output ('test' , 'json' )
306306 self .assertEqual ('"test"' , ret )
307307
308+ def test_format_output_jsonraw (self ):
309+ t = formatting .Table (['nothing' ])
310+ t .align ['nothing' ] = 'c'
311+ t .add_row (['testdata' ])
312+ t .add_row ([formatting .blank ()])
313+ t .sortby = 'nothing'
314+ ret = formatting .format_output (t , 'jsonraw' )
315+ # This uses json.dumps due to slight changes in the output between
316+ # py3.3 and py3.4
317+ expected = json .dumps ([{'nothing' : 'testdata' }, {'nothing' : None }])
318+ self .assertEqual (expected , ret )
319+
320+ ret = formatting .format_output ('test' , 'json' )
321+ self .assertEqual ('"test"' , ret )
322+
308323 def test_format_output_json_keyvaluetable (self ):
309324 t = formatting .KeyValueTable (['key' , 'value' ])
310325 t .add_row (['nothing' , formatting .blank ()])
@@ -314,6 +329,21 @@ def test_format_output_json_keyvaluetable(self):
314329 "nothing": null
315330}''' , ret )
316331
332+ def test_format_output_jsonraw_keyvaluetable (self ):
333+ t = formatting .KeyValueTable (['key' , 'value' ])
334+ t .add_row (['nothing' , formatting .blank ()])
335+ t .sortby = 'nothing'
336+ ret = formatting .format_output (t , 'jsonraw' )
337+ self .assertEqual ('''{"nothing": null}''' , ret )
338+
339+ def test_format_output_json_string (self ):
340+ ret = formatting .format_output ("test" , 'json' )
341+ self .assertEqual ('"test"' , ret )
342+
343+ def test_format_output_jsonraw_string (self ):
344+ ret = formatting .format_output ("test" , 'jsonraw' )
345+ self .assertEqual ('"test"' , ret )
346+
317347 def test_format_output_formatted_item (self ):
318348 item = formatting .FormattedItem ('test' , 'test_formatted' )
319349 ret = formatting .format_output (item , 'table' )
@@ -379,6 +409,16 @@ def test_format_output_unicode(self):
379409 t = formatting .format_output (item , 'raw' )
380410 self .assertEqual ('raw ☃' , t )
381411
412+ def test_format_output_table_invalid_sort (self ):
413+ t = formatting .Table (['nothing' ])
414+ t .align ['nothing' ] = 'c'
415+ t .add_row (['testdata' ])
416+ t .sortby = 'DOES NOT EXIST'
417+ self .assertRaises (
418+ exceptions .CLIHalt ,
419+ formatting .format_output , t , 'table' ,
420+ )
421+
382422
383423class TestTemplateArgs (testing .TestCase ):
384424
0 commit comments