#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Basic classes for test execution
"""
from .checks import ValueChecker
from .utils import OfflineFileEvaluator
from .reporting import Reporter
import uuid
[docs]class TestCriteria:
"""Class to hold criteria for a test to evaluate test value against
"""
def __init__(self, testfunctionname = "Undefined", configvalues = None):
self.configvalues = configvalues
self.function = testfunctionname
[docs] def check(self, value, valuetype = "Undefined"):
# get testfunction
if self.function == "Undefined":
return "configerror", ValueError("Testfunction name must be set.")
elif self.function == "inrange":
if valuetype == "int":
self.function = ValueChecker.inrange
else:
return "configerror", ValueError("Testfunction inrange expects values of type 'int', not "+valuetype)
else:
return "configerror", ValueError("Testfunction name unknown: "+self.function)
returntype, returnvalue = self.function(value, self.configvalues)
return returntype, returnvalue
[docs]class KM3Test:
"""Class to perform single test
Parameters:
- uuid: uuid, automatic identifier
- status: str, status toggle for outcome of test: undefined, open, passed, invalid, failed
- result: dict, holds outcome of the test
"""
def __init__(self):
self.uuid = uuid.uuid4()
self.config = {"checkconfig": None,
"checkfunction": None,
"objectvalues": None,
"objecttype": None,
"objectfilepath": None}
self.status = "undefined"
self.result = {"outcometype": "undefined",
"valuetype": "undefined",
"values": None,
"outcome": None}
[docs] def set_config(self, configdict):
for key in ["checkconfig", "checkfunction", "objecttype", "objectvalues"]:
if not key in configdict:
self.status = "invalid"
errormessage = "Passed configuration with missing key "+key
self.result["outcome"] = ValueError(errormessage)
print (errormessage)
return
self.config = configdict
self.status = "open"
[docs] def get_status(self):
return "Test "+self.status
[docs] def get_result(self):
return self.result