Tekvel Magic
Loading...
Searching...
No Matches
TestEngine Class Reference

Test scenario controller singleton class. More...

Public Member Functions

def __init__ (self, test_result_id=None)
 
def get_system_info (self)
 Returns system info. More...
 
def get_application_info (self)
 Returns application info. More...
 
def get_test_environment (self)
 Returns test environment info including application info and system info. More...
 
def log_test_environment (self)
 Writes full test environment data to the test log. More...
 
def log (self, str text)
 Writes a message to the log. More...
 
def bulk_log (self, list log_list)
 Writes a list of messages to the log. More...
 
def log_validation_errors (self, scl_validation_result)
 Writes SclValidationResult errors to log. More...
 
def log_result_messages (self, TestResult test_result)
 Writes messages from TestResult objects to the log. More...
 
def log_result_errors (self, test_result)
 Writes errors from TestResult objects to the log. More...
 
def set_result (self, result, str text="")
 Sets overall test result. More...
 
bool result_not_set (self)
 Shows if the test result has already been set. More...
 
def get_artifact (self, str artifact_id)
 Retreives artifact associated with running test case. More...
 
def save_artifact (self, artifact_id, save_path)
 Saves artifact with specified artifact_id to the file specified by file_path. More...
 
def save_file (self, bytes binary_data, str save_path)
 Saves binary data to the file specified by file_path. More...
 

Detailed Description

Test scenario controller singleton class.

This class provides interaction with Magic's test engine. Particularly this class provides loggin of test environment data, loogging of messages, setting the results of the test, etc. The class is initialized with the same name inside the test scenario context and requires no additional initialization.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  test_result_id = None 
)

Member Function Documentation

◆ bulk_log()

def bulk_log (   self,
list  log_list 
)

Writes a list of messages to the log.

Parameters
log_listList of strings to be written to the log

Function is used to write a list of messages to the log.

list_of_messages = ["Message 1", "Message 2"]
TestEngine.bulk_log(list_of_messages)

This function is highly recommended for use with list of multiple messages insted of writing log messages inside a loop with log() function as it offers much higher performance. For logging only one message you can still use log() function.

◆ get_application_info()

def get_application_info (   self)

Returns application info.

Returns
Dictionary containing system information of the following form:
{"app_name": "magic", "app_version": "1.7.0", "db_schema_version": "0.3.7"}

◆ get_artifact()

def get_artifact (   self,
str  artifact_id 
)

Retreives artifact associated with running test case.

Parameters
artifact_idartifact identifier within the scope of the test.
Returns
str A string containing the artifact, specified by the artifact_id parameter

Artifacts are typically huge parts of string-type data associated with the test. Typically artifacts are used to store SCL-files assiciated with specific tests, which allows not to have them directly described as string inside the test scenario as well as to ship them together with test procedures without the need to deal with filesystem referemces, etc. Artifacts can also be used to store string-type test report tempates, huge regular expressions, etc.

The artifact_id parameter shall be unique within the scope of specific test. When returned the artifact can either be used direcly or used as an input to other API-functions.

IED_NAME_TEMPLATE = TestEngine.get_artifact("IED_NAME_RE")

◆ get_system_info()

def get_system_info (   self)

Returns system info.

Returns
Dictionary containing system information of the following form:
{"architechture":"64 bit", "desktop_environment":"", "endianness":1, "free_memory":"-1", "host_name":"TKVL-CDU-NB-017", "os_desc":"macOS Version 12.0.1 (Build 21A559)", "os_version":"Macintosh", "user_id":"aao", "user_name":"John Doe"}

◆ get_test_environment()

def get_test_environment (   self)

Returns test environment info including application info and system info.

United data collected by get_system_info() and get_application_info() into single dict for convinient use.

Returns
Dictionary containing system and app information of the following form:
{
"application_info":
{
"app_name": "magic",
"app_version": "1.7.0",
"db_schema_version": "0.3.7"
},
"system_info": {"architechture":"64 bit", "desktop_environment":"", "endianness":1, "free_memory":"-1", "host_name":"TKVL-CDU-NB-017", "os_desc":"macOS Version 12.0.1 (Build 21A559)", "os_version":"Macintosh", "user_id":"aao", "user_name":"John Doe"}
}

◆ log()

def log (   self,
str  text 
)

Writes a message to the log.

Parameters
textText message to be written to the log

Function is used to write single message to the log.

TestEngine.log("Some message to be written to the log")

Note that is not recommended to write multiple messages in a loop using this function. If there is a list of messages to be logged, use bulk_log() function instead.

Parameters
text

◆ log_result_errors()

def log_result_errors (   self,
  test_result 
)

Writes errors from TestResult objects to the log.

Parameters
test_resultTestResult instance, containing test errors

The function is used to write all test errors from TestResult class object to the log.

Note
This function logs errors only from TestResult. Use log_result_messages() function to log messages from TestResult. The function uses bulk_log() function to log multiple errors, so it ensures good performance even in case of thuosands of errors.
See also
TestResult bulk_log() log_result_messages()

◆ log_result_messages()

def log_result_messages (   self,
TestResult  test_result 
)

Writes messages from TestResult objects to the log.

Parameters
test_resultTestResult instance, containing test log messages

The function is used to write all test log messages from TestResult class object to the log.

Note
This function logs messages only from TestResult. Use log_result_errors() function to log errors from TestResult. The function uses bulk_log() function to log multiple messages, so it ensures good performance even in case of thuosands of messages.
See also
TestResult bulk_log() log_result_errors()

◆ log_test_environment()

def log_test_environment (   self)

Writes full test environment data to the test log.

The function calls get_test_environment() function to retreive test environment information and then logs it test log. The function requires no additional parameters.

TestEngine.log_test_environment()

◆ log_validation_errors()

def log_validation_errors (   self,
  scl_validation_result 
)

Writes SclValidationResult errors to log.

Parameters
scl_validation_resultSclValidationResult instance, containing validation errors

The function is used to write all validation errors from SclValidationResult class object to the log. Example usage is shown below

res = scl.validate()
if not res.valid:
TestEngine.log_validation_errors(res)

The function uses bulk_log() function to log multiple messages, so it would provide good performance even if there are thousands of validation erros.

See also
SclValidationResult SCL SCL.validate()

◆ result_not_set()

bool result_not_set (   self)

Shows if the test result has already been set.

This function can be used to avoide multiple test result setting inside long test scenarios with multiple set_result() functions. Thus eash set_result() call shall be preceded with the check that test result has not been set previosly. See code snippet below.

if TestEngine.result_not_set():
TestEngine.set_result(Result.SUCCESS, "The test has been passed successfully.")
else:
pass
See also
set_result() Result

◆ save_artifact()

def save_artifact (   self,
  artifact_id,
  save_path 
)

Saves artifact with specified artifact_id to the file specified by file_path.

Parameters
artifact_idartifact identifier within the scope of the test.
save_pathfilepath (incliding filename) where the specified artifact shall be saved.

The function can be used to save SCL-files associated with specific test case. The function is particularly usefull when some reference files have to be exported from the test procedure.

Use Dialog class funtions to provide user with dialog-windows to select location to store files.

file_path = Dialog.save_scd_file()
TestEngine.save_artifact("tDfe1_SCD", filepath)
See also
Dialog

◆ save_file()

def save_file (   self,
bytes  binary_data,
str  save_path 
)

Saves binary data to the file specified by file_path.

Parameters
binary_databinary data to be written to file.
save_pathfilepath (incliding filename) where the specified data shall be saved.

The function can be used to save binary data obtained during the test.

For string-type data use encoding to obtain the binary representation of the data, eg.

binary_data = string_type_data.encode('utf-8')

Use Dialog class funtions to provide user with dialog-windows to select location to store files.

some_string = "Hello-world"
filepath=Dialog.save_file(title="Save TXT-file", filetypes="TXT-file (*.txt)|*.txt", default_filename="Hello-world.txt")
bin_data = some_string.encode("utf-8")
TestEngine.save_file(bin_data, filepath)
See also
Dialog

◆ set_result()

def set_result (   self,
  result,
str  text = "" 
)

Sets overall test result.

The function sets the test result and displays a dialog message with text. Typically, this function should be called at the very end of the test script. Avoid using this function multiple times in the code to prevent confusion from multiple settings of the result. Example usage is shown below.

Parameters
resultInteger representation of the result as described by Result class.
textThe message to be displayed in the dialog.
Exceptions
None
TestEngine.set_result(Result.SUCCESS, "The test has been passed successfully.")
...
TestEngine.set_result(Result.FAIL, "Test failed. Please check the error log for details.")
...
TestEngine.set_result(Result.INCONCLUSIVE, "The test could not be finished. Manual test is required.")
See also
TestResult Result Dialog