From 1faa80659d44ec034a25859be5d090d55b5aabcf Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sat, 16 Jul 2022 20:01:46 -0300 Subject: [PATCH] Fix Unit Test Python script error if a file is missing --- Scripts/UnitTesting/RunUnitTests.py | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Scripts/UnitTesting/RunUnitTests.py b/Scripts/UnitTesting/RunUnitTests.py index 9a5753e0325..9b28be9decb 100644 --- a/Scripts/UnitTesting/RunUnitTests.py +++ b/Scripts/UnitTesting/RunUnitTests.py @@ -74,21 +74,25 @@ def compareResults( oldFolder, newFolder ): global g_hasDifferentFiles - cmpResult = filecmp.dircmp( oldFolder, newFolder ) - if len( cmpResult.left_only ) > 0: + try: + cmpResult = filecmp.dircmp( oldFolder, newFolder ) + if len( cmpResult.left_only ) > 0: + g_hasDifferentFiles = True + print( 'WARNING: these files were not generated by this unit test but should have been:' ) + print( str( cmpResult.left_only ) ) + if len( cmpResult.right_only ) > 0: + g_hasDifferentFiles = True + print( 'WARNING: these files were not in the original cmp folder:' ) + print( str( cmpResult.right_only ) ) + + if len( cmpResult.diff_files ) == 0: + print( 'All files equal' ) + else: + g_hasDifferentFiles = True + print( 'ERROR: Different files: ' + str( cmpResult.diff_files ) ) + except FileNotFoundError as err: g_hasDifferentFiles = True - print( 'WARNING: these files were not generated by this unit test but should have been:' ) - print( str( cmpResult.left_only ) ) - if len( cmpResult.right_only ) > 0: - g_hasDifferentFiles = True - print( 'WARNING: these files were not in the original cmp folder:' ) - print( str( cmpResult.right_only ) ) - - if len( cmpResult.diff_files ) == 0: - print( 'All files equal' ) - else: - g_hasDifferentFiles = True - print( 'ERROR: Different files: ' + str( cmpResult.diff_files ) ) + print( 'ERROR: {0}'.format( err ) ) def runUnitTest( exeName, jsonName ): exeFullpath = os.path.abspath( os.path.join( g_exeFolder, exeName ) ) @@ -126,4 +130,4 @@ def runUnitTest( exeName, jsonName ): else: print( 'All files in all tests were equal' ) else: - print( 'No comparison was made as the script was run in generation mode' ) \ No newline at end of file + print( 'No comparison was made as the script was run in generation mode' )