@@ -181,9 +181,8 @@ impl Python3Plugin {
181181 /// Parse test result file
182182 fn parse_and_verify_test_result (
183183 test_results_json : & Path ,
184- logs : HashMap < String , String > ,
185184 hmac_data : Option < ( String , String ) > ,
186- ) -> Result < RunResult , PythonError > {
185+ ) -> Result < ( RunStatus , Vec < TestResult > ) , PythonError > {
187186 let results = file_util:: read_file_to_string ( & test_results_json) ?;
188187
189188 // verify test results
@@ -213,7 +212,7 @@ impl Python3Plugin {
213212 . into_iter ( )
214213 . map ( |r| r. into_test_result ( & failed_points) )
215214 . collect ( ) ;
216- Ok ( RunResult :: new ( status, test_results, logs ) )
215+ Ok ( ( status, test_results) )
217216 }
218217}
219218
@@ -234,9 +233,9 @@ impl LanguagePlugin for Python3Plugin {
234233 file_util:: remove_file ( & available_points_json) ?;
235234 }
236235
237- let run_result =
238- Self :: run_tmc_command ( exercise_directory, & [ "available_points" ] , None , None ) ;
239- if let Err ( error ) = run_result {
236+ if let Err ( error ) =
237+ Self :: run_tmc_command ( exercise_directory, & [ "available_points" ] , None , None )
238+ {
240239 log:: error!( "Failed to scan exercise. {}" , error) ;
241240 }
242241
@@ -280,15 +279,12 @@ impl LanguagePlugin for Python3Plugin {
280279
281280 match output {
282281 Ok ( output) => {
283- let mut logs = HashMap :: new ( ) ;
284- logs. insert (
285- "stdout" . to_string ( ) ,
286- String :: from_utf8_lossy ( & output. stdout ) . into_owned ( ) ,
287- ) ;
288- logs. insert (
289- "stderr" . to_string ( ) ,
290- String :: from_utf8_lossy ( & output. stderr ) . into_owned ( ) ,
291- ) ;
282+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
283+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
284+ log:: trace!( "stdout: {}" , stdout) ;
285+ log:: debug!( "stderr: {}" , stderr) ;
286+
287+ // TODO: is it OK to not check output.status.success()?
292288
293289 let hmac_data = if let Some ( random_string) = random_string {
294290 let hmac_result_path = exercise_directory. join ( ".tmc_test_results.hmac.sha256" ) ;
@@ -298,27 +294,37 @@ impl LanguagePlugin for Python3Plugin {
298294 None
299295 } ;
300296
301- let parse_res =
302- Self :: parse_and_verify_test_result ( & test_results_json, logs, hmac_data) ;
303- // remove file regardless of parse success
304- if test_results_json. exists ( ) {
305- file_util:: remove_file ( & test_results_json) ?;
297+ if !test_results_json. exists ( ) {
298+ return Err ( PythonError :: MissingTestResults {
299+ path : test_results_json,
300+ stdout : stdout. into_owned ( ) ,
301+ stderr : stderr. into_owned ( ) ,
302+ }
303+ . into ( ) ) ;
306304 }
307-
308- let mut run_result = parse_res?;
305+ let ( status, mut test_results) =
306+ Self :: parse_and_verify_test_result ( & test_results_json, hmac_data) ?;
307+ file_util:: remove_file ( & test_results_json) ?;
309308
310309 // remove points associated with any failed tests
311310 let mut failed_points = HashSet :: new ( ) ;
312- for test_result in & run_result . test_results {
311+ for test_result in & test_results {
313312 if !test_result. successful {
314313 failed_points. extend ( test_result. points . iter ( ) . cloned ( ) ) ;
315314 }
316315 }
317- for test_result in & mut run_result . test_results {
316+ for test_result in & mut test_results {
318317 test_result. points . retain ( |p| !failed_points. contains ( p) ) ;
319318 }
320319
321- Ok ( run_result)
320+ let mut logs = HashMap :: new ( ) ;
321+ logs. insert ( "stdout" . to_string ( ) , stdout. into_owned ( ) ) ;
322+ logs. insert ( "stderr" . to_string ( ) , stderr. into_owned ( ) ) ;
323+ Ok ( RunResult {
324+ status,
325+ test_results,
326+ logs,
327+ } )
322328 }
323329 Err ( PythonError :: Tmc ( TmcError :: Command ( CommandError :: TimeOut {
324330 stdout,
@@ -899,7 +905,6 @@ class TestClass(unittest.TestCase):
899905 "b379817c66cc7b1610d03ac263f02fa11f7b0153e6aeff3262ecc0598bf0be21" . to_string ( ) ;
900906 Python3Plugin :: parse_and_verify_test_result (
901907 temp. path ( ) ,
902- HashMap :: new ( ) ,
903908 Some ( ( hmac_secret, test_runner_hmac) ) ,
904909 )
905910 . unwrap ( ) ;
@@ -917,7 +922,6 @@ class TestClass(unittest.TestCase):
917922 "b379817c66cc7b1610d03ac263f02fa11f7b0153e6aeff3262ecc0598bf0be22" . to_string ( ) ;
918923 let res = Python3Plugin :: parse_and_verify_test_result (
919924 temp. path ( ) ,
920- HashMap :: new ( ) ,
921925 Some ( ( hmac_secret, test_runner_hmac) ) ,
922926 ) ;
923927 assert ! ( res. is_err( ) ) ;
0 commit comments