Testing
You can provide test data for processor modules using the get_test_data method. If test data is given, the processor module is automatically tested, when executing the test framework.
Each test object (a dictionary) consists of the entries module_config
, input_data
and the expected output_data
.
During the test execution, the processor module is instantiated with the given module_config
and started.
Subsequently, the _run
method is called with the given input_data
.
The data object returned by the _run
method is compared with the expected output_data
.
If the data objects differ, an error is raised.
After the processor module was executed, it is stopped.
Example
@classmethod
def get_test_data(cls) -> list[dict]:
test_1 = {"module_config": cls.Configuration(module_name=os.path.splitext(os.path.basename(__file__))[0],
field_key="test3",
field_value="*"),
"input_data": models.Data(measurement="test",
fields={"test3": 1, "test4": 1.234},
tags={"test1": 1, "test2": 2}),
"output_data": models.Data(measurement="test",
fields={"test3": 1},
tags={"test1": 1, "test2": 2})}
test_2 = {"module_config": cls.Configuration(module_name=os.path.splitext(os.path.basename(__file__))[0],
field_key="test3",
field_value="1"),
"input_data": models.Data(measurement="test",
fields={"test3": 1, "test4": 1.234},
tags={"test1": 1, "test2": 2}),
"output_data": models.Data(measurement="test",
fields={"test3": 1},
tags={"test1": 1, "test2": 2})}
return [test_1, test_2]
Execute tests
-
To execute the tests, go to the test directory by:
cd src/test
-
Execute test by:
python src/test/test.py
Introduction
Template