KeaTestElements
This section aims to explain the design and implementation of KeaTestElements, the runtime data management class in Kea.
Functional Design and Implementation
KeaTestElements is a data structure that stores user-defined properties at runtime in Kea, corresponding one-to-one with the user-inherited and customized keaTest. During the startup of kea, keaTestElements will read each user-defined keaTest and reorganize it into a data structure convenient for kea to read. For specific conversion processes, refer to the chapter on decorators: Transformation from User-defined KeaTest to Runtime KeaTestElements.
The data structure of KeaTestElements is illustrated as follows:
KeaTestElements Data Structure
Here, keaTest_name is a string used to store the class name of the user-defined keaTest. Rules is a list used to store Rule objects. Initializers is a list used to store initialization function objects, Initializer. MainPaths is a list used to store main path objects, MainPath.
The data structure and definitions of Rule, MainPath, and Initializer objects can be found in the chapter on ‘Decorators.’
The pseudocode for defining the member methods of KeaTestElements is as follows:
class KeaTestElements:
def load_rules(keaTest)
def load_initializers(keaTest)
def load_mainPaths(keaTest)
load_rules receives a user-defined keaTest object, reads the rules within it, and stores all rules from a keaTest into the rules list. load_initializers receives a user-defined keaTest object, reads the initialization function objects, Initializer, and stores them in the initializers list. load_mainPaths receives a user-defined keaTest object, reads the main path objects, mainPath, and stores them in the mainPaths list.
Specifically, the execution steps of the three load methods are similar and can be described as follows:
1. 传入一个keaTest对象。
2. 在传入的keaTest对象中查找含有相对应MARKER标记的函数对象。
3. 将其相应的数据结构(Rule, Initializer和MainPath)以列表的方式组织存储为成员变量。
The member methods of KeaTestElements read data from KeaTest and convert it into a data structure that is convenient for Kea to use.
The specific implementations of the three member methods are as follows:
load_rules
- Parameters:
keaTest:KeaTest: A user-defined property keaTest object
- Returns:
None
def load_rules(self, keaTest:"KeaTest"):
for _, v in inspect.getmembers(keaTest):
rule = getattr(v, RULE_MARKER, None)
if rule is not None:
self.rules.append(rule)
load_initializers
- Parameters:
keaTest:KeaTest: A user-defined property keaTest object
- Returns:
None
def load_initializers(self, keaTest:"KeaTest"):
for _, v in inspect.getmembers(keaTest):
initializer = getattr(v, INITIALIZER_MARKER, None)
if initializer is not None:
self.initializers.append(initializer)
load_mainPaths
- Parameters:
keaTest:KeaTest: A user-defined property keaTest object
- Returns:
None
def load_mainPaths(self, keaTest:"KeaTest"):
for _, v in inspect.getmembers(keaTest):
mainPath = getattr(v, MAINPATH_MARKER, None)
if mainPath is not None:
self.mainPaths.append(mainPath)