Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 101 additions & 49 deletions test/component_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#
# --------------------------------------------------------------------------------------------------------------
#
# 02.08.2023
VERSION = "0.1.0"
VERSION_DATE = "03.08.2023"
#
# --------------------------------------------------------------------------------------------------------------
#TM***
Expand Down Expand Up @@ -188,7 +189,7 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None):
# --------------------------------------------------------------------------------------------------------------
# [TESTCONFIG]

# -- initialize configuration
# -- initialize and dump test configuration

oConfig = None
try:
Expand All @@ -199,49 +200,40 @@ def AnalyzeExceptions(EXPECTEDEXCEPTION=None, sException=None):
print()
sys.exit(ERROR)

# --------------------------------------------------------------------------------------------------------------
# some special functions
# (with premature end of execution = no test execution)
# --------------------------------------------------------------------------------------------------------------

CONFIGDUMP = oConfig.Get('CONFIGDUMP')
if CONFIGDUMP is True:
# currently config is already dumped in constructor of CConfig; => nothing more to do here
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)
# 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)

bSuccess, sResult = oCodeGenerator.GenCode()
if bSuccess is not True:
print()
printerror(CString.FormatResult("(main)", bSuccess, sResult))
print()
sys.exit(ERROR)
# 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

print(COLBG + f"{sResult}\n")
# dump configuration values to screen
listConfigLines = oConfig.DumpConfig()

# after code dump nothing more to do here
CONFIGDUMP = oConfig.Get('CONFIGDUMP')
if CONFIGDUMP is True:
# if that's all, we have nothing more to do
sys.exit(SUCCESS)


# **************************************************************************************************************
# [EXECUTION]
# **************************************************************************************************************
# --------------------------------------------------------------------------------------------------------------
# [PRELIMINARIES]
# --------------------------------------------------------------------------------------------------------------
#TM***

# -- get some configuration values required for execution
# -- access to configuration

THISSCRIPT = oConfig.Get('THISSCRIPT')
THISSCRIPTNAME = oConfig.Get('THISSCRIPTNAME')
Expand All @@ -257,13 +249,16 @@ 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()
# -- 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(';')
Expand All @@ -277,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
Expand All @@ -300,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)

Expand Down Expand Up @@ -337,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']
Expand All @@ -354,15 +406,15 @@ 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']
COMMENT = None
if "COMMENT" in dictUsecase:
COMMENT = dictUsecase['COMMENT']

# derived ones
# get derived parameters
TESTFULLNAME = f"{TESTID}-({SECTION})-[{SUBSECTION}]"
TESTLOGFILE_TXT = f"{TESTLOGFILESFOLDER}/{TESTFULLNAME}.log"

Expand Down Expand Up @@ -493,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}"
Expand Down
20 changes: 17 additions & 3 deletions test/libs/CConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# XC-CT/ECA3-Queckenstedt
#
# 18.07.2023
# 03.08.2023
#
# --------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -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):

Expand All @@ -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):

# --------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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():

# **************************************************************************************************************
Expand Down