66from glob import glob
77
88from pathlib import Path
9- from pprint import pprint
9+ from pprint import pformat , pprint
1010from typing import List , Optional
1111
1212import typer
@@ -88,9 +88,29 @@ def _log_test_summaries(summaries: List[TestSummary], msg: str):
8888 # todo: improve logging of multiple test summaries
8989 ret_code = 0
9090 for summary in summaries :
91- print (f"\n { summary ['name' ]} : { summary ['status' ]} " )
91+ print (f"{ summary ['name' ]} : { summary ['status' ]} " )
9292 if summary ["status" ] != "passed" :
93- pprint (summary )
93+ s = {
94+ k : v
95+ for k , v in summary .items ()
96+ if k not in ("name" , "status" , "bioimageio_spec_version" , "bioimageio_core_version" )
97+ }
98+ tb = s .pop ("traceback" )
99+ if tb :
100+ print ("traceback:" )
101+ print ("" .join (tb ))
102+
103+ def show_part (part , show ):
104+ if show :
105+ line = f"{ part } : "
106+ print (line + pformat (show , width = min (80 , 120 - len (line ))).replace ("\n " , " " * len (line ) + "\n " ))
107+
108+ for part in ["error" , "warnings" , "source_name" ]:
109+ show_part (part , s .pop (part , None ))
110+
111+ for part in sorted (s .keys ()):
112+ show_part (part , s [part ])
113+
94114 ret_code = 1
95115
96116 if ret_code :
@@ -114,27 +134,15 @@ def test_model(
114134 decimal : int = typer .Option (4 , help = "The test precision." ),
115135):
116136 # this is a weird typer bug: default devices are empty tuple although they should be None
117- if len ( devices ) == 0 :
118- devices = None
137+ devices = devices or None
138+
119139 summaries = resource_tests .test_model (
120140 model_rdf ,
121141 weight_format = None if weight_format is None else weight_format .value ,
122142 devices = devices ,
123143 decimal = decimal ,
124144 )
125-
126- if weight_format is None :
127- weight_formats = get_weight_formats ()
128- model_weight_formats = list (load_raw_resource_description (model_rdf ).weights .keys ())
129- for wf in weight_formats :
130- if wf in model_weight_formats :
131- weight_format = wf
132- break
133- weight_format = "unknown" if weight_format is None else weight_format
134-
135- ret_code = _log_test_summaries (
136- summaries , f"\n {{icon}} Model test for { model_rdf } using { weight_format } weight format has {{result}}"
137- )
145+ ret_code = _log_test_summaries (summaries , f"\n {{icon}} Model { model_rdf } {{result}}" )
138146 sys .exit (ret_code )
139147
140148
0 commit comments