Skip to content

Commit

Permalink
Merge pull request #42 from AdityaSavara/colored-statements-for-pass-…
Browse files Browse the repository at this point in the history
…and-fail

Colored statements for pass and fail
  • Loading branch information
AdityaSavara authored Jun 29, 2021
2 parents 3e195bc + 2dbb355 commit 957c3da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 20 additions & 3 deletions UnitTesterSG/UnitTesterSGFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
import pickle
import os
import sys
try:
import colorama
colorama.init() #This is required otherwise colors don't appear correctly in the terminal when somebody is using a windows OS.
coloramaPresent = True
except:
coloramaPresent = False


'''This is a helper function for 'reloading' modules
It deletes variables in them, which importlib reload does not do.
Expand Down Expand Up @@ -186,9 +193,19 @@ def check_results(calculated_resultObj,calculated_resultStr='',prefix='',suffix=
if customCompare(expected_resultObj_unpacked,calculated_resultObj_unpacked, relativeTolerance=relativeTolerance, absoluteTolerance=absoluteTolerance, softStringCompare=softStringCompare) == True:
print('Expected result and calculated_result MATCH.')
objectMatch = True
#printing pass/fail, with color if available.
if coloramaPresent == True:
print(colorama.Fore.GREEN + '\n***********UNIT TEST PASSED**********\n' + colorama.Fore.RESET)
else:
print('\n***********UNIT TEST PASSED**********\n')
else: #implies that customCompare returned false.
print("Expected result and calculated_result DO NOT MATCH (or is nested and/or contains an unsupported datatype).")
objectMatch = False
#printing pass/fail, with color if available.
if coloramaPresent == True:
print(colorama.Fore.RED + '\n***********UNIT TEST FAILED**********\n' + colorama.Fore.RESET)
else:
print('\n***********UNIT TEST FAILED**********\n')
if expected_resultStr_read==calculated_resultStr_read:
print('Expected result string and calculated_result string MATCH')
stringMatch = True
Expand All @@ -201,21 +218,21 @@ def check_results(calculated_resultObj,calculated_resultStr='',prefix='',suffix=
if (interactiveTesting==True and objectMatch == False): #we only consider printing the string if the objectMatch is false.
if expected_resultStr_read!=calculated_resultStr_read: #We give the option the user to print out the strings if the string comparison failed.
printStringsChoice=str(input('Expected result string does not match calculated_result string. Would you like to print them here now to inspect (Y or N)?'))
if str(printStringsChoice) == 'Y':
if str(printStringsChoice).lower() == 'y' or str(printStringsChoice).lower() == 'yes':
print('Expected result string (top) DOES NOT MATCH calculated_result string (bottom)')
print(expected_resultStr_read)
print(calculated_resultStr_read)
if (objectMatch == False): #if either object or string comparison failed, we consider overwriting old files.
#the if statement is to prevent pytest from needing user input. Perhaps should be changed to "interactiveTesting = True" rather than allowOverwrite = True.
if allowOverwrite==True and interactiveTesting==True:
overwritechoice=str(input('Overwrite (or create) the expected result object and string files from the calculated results provided (Y or N)? '))
if str(overwritechoice)=='Y':
if str(overwritechoice)=='Y' or str(overwritechoice)=='y' or str(overwritechoice).lower()=='yes':
#pickling the calculated result into the expected result file
with open(expected_result_file,'wb') as expected_resultObj:
pickle.dump(calculated_resultObj_unpacked,expected_resultObj)
with open(expected_resultStr_file,'w') as expected_resultStr:
expected_resultStr.write(calculated_resultStr_read)
elif str(overwritechoice)=='N':
elif str(overwritechoice)=='N' or str(overwritechoice)=='n' or str(overwritechoice).lower()=='no':
pass
else:
print("Error: Only Y or N allowed. Please run program again.")
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
EMAIL = '[email protected]'
AUTHOR = 'Aditya Savara'
REQUIRES_PYTHON = '>=3.0.0'
VERSION = '5.4.1'
VERSION = '5.4.2'
LICENSE = 'BSD-3-Clause'

# What packages are required for this module to be executed?
Expand All @@ -29,9 +29,8 @@
# 'requests', 'maya', 'records', #numpy...
]

# What packages are optional?
EXTRAS = {
# 'uncertainties': ['uncertainties'], #pymc...
'COMPLETE': ['colorama', 'pytest'] #This is a list.
}

#To make sure the license etc. is included, I added the DATA_FILES object based on https://stackoverflow.com/questions/9977889/how-to-include-license-file-in-setup-py-script
Expand Down

0 comments on commit 957c3da

Please sign in to comment.