From dc7066dc4084a76c7d651d9f35d4491e9d7cdd50 Mon Sep 17 00:00:00 2001 From: qth2hi Date: Thu, 3 Aug 2023 14:44:19 +0200 Subject: [PATCH 1/2] Introduced VERSION, VERSION_DATE and THISSCRIPTFULLNAME for component_test.py Values are written to console and to logfile --- test/component_test.py | 22 ++++++++++++++++------ test/libs/CConfig.py | 20 +++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/test/component_test.py b/test/component_test.py index e3857383..9ac09148 100644 --- a/test/component_test.py +++ b/test/component_test.py @@ -22,7 +22,8 @@ # # -------------------------------------------------------------------------------------------------------------- # -# 02.08.2023 +VERSION = "0.1.0" +VERSION_DATE = "03.08.2023" # # -------------------------------------------------------------------------------------------------------------- #TM*** @@ -199,14 +200,19 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): print() sys.exit(ERROR) -# -------------------------------------------------------------------------------------------------------------- -# some special functions -# (with premature end of execution = no test execution) -# -------------------------------------------------------------------------------------------------------------- +# update version and date of this app +oConfig.Set("VERSION", VERSION) +oConfig.Set("VERSION_DATE", VERSION_DATE) +THISSCRIPTNAME = oConfig.Get('THISSCRIPTNAME') +THISSCRIPTFULLNAME = f"{THISSCRIPTNAME} v. {VERSION} / {VERSION_DATE}" +oConfig.Set("THISSCRIPTFULLNAME", THISSCRIPTFULLNAME) + +# dump configuration values to screen +listConfigLines = oConfig.DumpConfig() CONFIGDUMP = oConfig.Get('CONFIGDUMP') if CONFIGDUMP is True: - # currently config is already dumped in constructor of CConfig; => nothing more to do here + # if that's all, we have nothing more to do sys.exit(SUCCESS) # -------------------------------------------------------------------------------------------------------------- @@ -257,6 +263,10 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): # -- start logging oSelfTestLogFile = CFile(SELFTESTLOGFILE) +NOW = time.strftime('%d.%m.%Y - %H:%M:%S') +oSelfTestLogFile.Write(f"{THISSCRIPTNAME} started at: {NOW}\n") +oSelfTestLogFile.Write(listConfigLines) # from DumpConfig() called above +oSelfTestLogFile.Write() print("Executing test cases") print() diff --git a/test/libs/CConfig.py b/test/libs/CConfig.py index 916d1430..def107b0 100644 --- a/test/libs/CConfig.py +++ b/test/libs/CConfig.py @@ -20,7 +20,7 @@ # # XC-CT/ECA3-Queckenstedt # -# 18.07.2023 +# 03.08.2023 # # -------------------------------------------------------------------------------------------------------------- @@ -137,7 +137,7 @@ def __init__(self, sCalledBy=None): self.__dictConfig['SELFTESTLOGFILE'] = SELFTESTLOGFILE # dump of basic configuration parameters to console - self.DumpConfig() + # self.DumpConfig() # done in main script now! # eof def __init__(self, sCalledBy=None): @@ -146,12 +146,16 @@ def __init__(self, sCalledBy=None): def DumpConfig(self): """Prints all configuration values to console.""" + listFormattedOutputLines = [] # -- printing configuration to console print() # PrettyPrint(self.__dictConfig, sPrefix="Config") for key, value in self.__dictConfig.items(): - print(key.rjust(30, ' ') + " : " + str(value)) + sLine = key.rjust(30, ' ') + " : " + str(value) + print(sLine) + listFormattedOutputLines.append(sLine) print() + return listFormattedOutputLines # eof def DumpConfig(self): # -------------------------------------------------------------------------------------------------------------- @@ -187,6 +191,16 @@ def Get(self, sName=None): # -------------------------------------------------------------------------------------------------------------- #TM*** + def Set(self, sName=None, sValue=None): + """Sets a new configuration parameter.""" + sName = f"{sName}" + sValue = f"{sValue}" + self.__dictConfig[sName] = sValue + # eof def Set(self, sName=None, sValue=None): + + # -------------------------------------------------------------------------------------------------------------- + #TM*** + # eof class CConfig(): # ************************************************************************************************************** From dc18f521582a84c6837132b29708877c205c779d Mon Sep 17 00:00:00 2001 From: qth2hi Date: Thu, 3 Aug 2023 17:40:33 +0200 Subject: [PATCH 2/2] SuT version added; code maintenance --- test/component_test.py | 128 +++++++++++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/test/component_test.py b/test/component_test.py index 9ac09148..e3902cc7 100644 --- a/test/component_test.py +++ b/test/component_test.py @@ -189,7 +189,7 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): # -------------------------------------------------------------------------------------------------------------- # [TESTCONFIG] -# -- initialize configuration +# -- initialize and dump test configuration oConfig = None try: @@ -207,6 +207,18 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): THISSCRIPTFULLNAME = f"{THISSCRIPTNAME} v. {VERSION} / {VERSION_DATE}" oConfig.Set("THISSCRIPTFULLNAME", THISSCRIPTFULLNAME) +# add information about system under test +try: + # not yet implemented officially + oJsonPreprocessor = CJsonPreprocessor() + sut_version = oJsonPreprocessor.get_version() + sut_version_date = oJsonPreprocessor.get_version_date() + del oJsonPreprocessor + SUT_FULL_NAME = f"JsonPreprocessor v. {sut_version} / {sut_version_date}" + oConfig.Set("SUT_FULL_NAME", SUT_FULL_NAME) +except: + pass + # dump configuration values to screen listConfigLines = oConfig.DumpConfig() @@ -215,39 +227,13 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): # if that's all, we have nothing more to do sys.exit(SUCCESS) -# -------------------------------------------------------------------------------------------------------------- -# [CODEDUMP] - -CODEDUMP = oConfig.Get('CODEDUMP') -if CODEDUMP is True: - oCodeGenerator = None - try: - oCodeGenerator = CGenCode(oConfig) - except Exception as ex: - print() - printerror(CString.FormatResult("(main)", None, str(ex))) - print() - sys.exit(ERROR) - bSuccess, sResult = oCodeGenerator.GenCode() - if bSuccess is not True: - print() - printerror(CString.FormatResult("(main)", bSuccess, sResult)) - print() - sys.exit(ERROR) - - print(COLBG + f"{sResult}\n") - - # after code dump nothing more to do here - sys.exit(SUCCESS) - - -# ************************************************************************************************************** -# [EXECUTION] -# ************************************************************************************************************** +# -------------------------------------------------------------------------------------------------------------- +# [PRELIMINARIES] +# -------------------------------------------------------------------------------------------------------------- #TM*** -# -- get some configuration values required for execution +# -- access to configuration THISSCRIPT = oConfig.Get('THISSCRIPT') THISSCRIPTNAME = oConfig.Get('THISSCRIPTNAME') @@ -268,12 +254,11 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): oSelfTestLogFile.Write(listConfigLines) # from DumpConfig() called above oSelfTestLogFile.Write() -print("Executing test cases") -print() +# -- prepare TESTIDs -nNrOfUsecases = 0 +# ('listofdictUsecases' is imported directly from test/testconfig/TestConfig.py) -# 'listofdictUsecases' is imported directly from test/testconfig/TestConfig.py +TESTID = oConfig.Get('TESTID') if TESTID is not None: listTESTIDs = TESTID.split(';') @@ -287,7 +272,13 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): if len(listofdictUsecasesSubset) == 0: bSuccess = False sResult = f"Test ID '{TESTID}' not defined" - printerror(CString.FormatResult(THISSCRIPTNAME, bSuccess, sResult)) + sResult = CString.FormatResult(THISSCRIPTNAME, bSuccess, sResult) + print() + printerror(sResult) + print() + printerror(sResult) + oSelfTestLogFile.Write(sResult, 1) + del oSelfTestLogFile sys.exit(ERROR) del listofdictUsecases listofdictUsecases = listofdictUsecasesSubset @@ -310,11 +301,61 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): if len(listDuplicates) > 0: sDuplicates = "[" + ", ".join(listDuplicates) + "]" bSuccess = False - sResult = f"Duplicate test IDs found: {sDuplicates}\nTest IDs are used to identify and select test cases. They have to be unique" - printerror(CString.FormatResult(THISSCRIPTNAME, bSuccess, sResult)) + sResult = f"Duplicate test IDs found in test configuration: {sDuplicates}\nTest IDs are used to identify and select test cases. They have to be unique" + sResult = CString.FormatResult(THISSCRIPTNAME, bSuccess, sResult) + print() + printerror(sResult) + print() + oSelfTestLogFile.Write(sResult, 1) + del oSelfTestLogFile sys.exit(ERROR) + +# -------------------------------------------------------------------------------------------------------------- +# [CODEDUMP] +# special function (with premature end of execution = no test execution) +# -------------------------------------------------------------------------------------------------------------- +#TM*** + +CODEDUMP = oConfig.Get('CODEDUMP') +if CODEDUMP is True: + oCodeGenerator = None + try: + oCodeGenerator = CGenCode(oConfig) + except Exception as ex: + bSuccess = None + sResult = str(ex) + sResult = CString.FormatResult(THISSCRIPTNAME, bSuccess, sResult) + print() + printerror(sResult) + print() + oSelfTestLogFile.Write(sResult, 1) + del oSelfTestLogFile + sys.exit(ERROR) + + bSuccess, sResult = oCodeGenerator.GenCode() + if bSuccess is not True: + sResult = CString.FormatResult(THISSCRIPTNAME, bSuccess, sResult) + print() + printerror(sResult) + print() + oSelfTestLogFile.Write(sResult, 1) + del oSelfTestLogFile + sys.exit(ERROR) + + print(COLBG + f"{sResult}\n") + + # after code dump nothing more to do here + sys.exit(SUCCESS) + + # -------------------------------------------------------------------------------------------------------------- +# [EXECUTION] +# -------------------------------------------------------------------------------------------------------------- +#TM*** + +print("Executing test cases") +print() nNrOfUsecases = len(listofdictUsecases) @@ -347,11 +388,12 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): for dictUsecase in listofdictUsecases: # debug - # PrettyPrint(dictUsecase) + # PrettyPrint(dictUsecase, sPrefix="dictUsecase") + # print() nCntUsecases = nCntUsecases + 1 - # required ones + # get required parameters TESTID = dictUsecase['TESTID'] DESCRIPTION = dictUsecase['DESCRIPTION'] EXPECTATION = dictUsecase['EXPECTATION'] @@ -364,7 +406,7 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): # TODO: make this depend on test case; in some BADCASE test cases this might not be wanted: JSONFILE = CString.NormalizePath(JSONFILE, sReferencePathAbs=TESTCONFIGPATH) - # optional ones + # get optional parameters HINT = None if "HINT" in dictUsecase: HINT = dictUsecase['HINT'] @@ -372,7 +414,7 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): if "COMMENT" in dictUsecase: COMMENT = dictUsecase['COMMENT'] - # derived ones + # get derived parameters TESTFULLNAME = f"{TESTID}-({SECTION})-[{SUBSECTION}]" TESTLOGFILE_TXT = f"{TESTLOGFILESFOLDER}/{TESTFULLNAME}.log" @@ -503,7 +545,7 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None): # paranoia check if ( (nCntPassedUsecases + nCntFailedUsecases + nCntUnknownUsecases != nCntUsecases) or (nNrOfUsecases != nCntUsecases) ): print() - sOut = CString.FormatResult(THISSCRIPTNAME, bSuccess=False, sResult="Internal counter mismatch") + sOut = CString.FormatResult(THISSCRIPTNAME, bSuccess=None, sResult="Internal counter mismatch") printerror(sOut) oSelfTestLogFile.Write(sOut) sOut = f"Defined : {nNrOfUsecases}"