@@ -64,23 +64,32 @@ def fake_request(*args, **kwargs):
6464 return bz
6565
6666
67- def diff_compare (inputdata , filename ):
67+ def diff_compare (inputdata , filename , expect_out = None ):
6868 """Compare passed string output to contents of filename"""
69- filename = tests_path (filename )
70-
71- actual_out = inputdata
72- if isinstance (inputdata , dict ):
73- actual_out = pprint .pformat (inputdata , width = 81 )
74- if not actual_out .endswith ("\n " ):
75- actual_out += "\n "
76-
77- if not os .path .exists (filename ) or tests .CLICONFIG .REGENERATE_OUTPUT :
78- open (filename , "w" ).write (actual_out )
79- expect_out = open (filename ).read ()
69+ def _process (data ):
70+ if isinstance (data , tuple ) and len (data ) == 1 :
71+ data = data [0 ]
72+ if isinstance (data , (dict , tuple )):
73+ out = pprint .pformat (data , width = 81 )
74+ else :
75+ out = str (data )
76+ if not out .endswith ("\n " ):
77+ out += "\n "
78+ return out
79+
80+ actual_out = _process (inputdata )
81+
82+ if filename :
83+ filename = tests_path (filename )
84+ if not os .path .exists (filename ) or tests .CLICONFIG .REGENERATE_OUTPUT :
85+ open (filename , "w" ).write (actual_out )
86+ expect_out = open (filename ).read ()
87+ else :
88+ expect_out = _process (expect_out )
8089
8190 diff = "" .join (difflib .unified_diff (expect_out .splitlines (1 ),
8291 actual_out .splitlines (1 ),
83- fromfile = filename or '' ,
92+ fromfile = filename or "Manual input" ,
8493 tofile = "Generated Output" ))
8594 if diff :
8695 raise AssertionError ("Conversion outputs did not match.\n %s" % diff )
0 commit comments