6.6. aas.compliance_tool.state_manager - Store LogRecords in a Compliance Check of the Compliance Tool

This module defines a ComplianceToolStateManager to store logging.LogRecords for single steps in a compliance check of the compliance tool

class basyx.aas.compliance_tool.state_manager.ComplianceToolStateManager

A ComplianceToolStateManager is used to create a report of a compliance check, divided into single Steps with status and log. The manager provides methods to:

  • Add a new step

  • Set the step status

  • Set the step status from log

  • Add logs to a step by hand

  • Add logs to a step from a data checker

  • Be used as a logging.Handler which adds logs to the current step

Example of a ComplianceTest for a schema check:

  • Step 1: Open file

  • Step 2: Read file and check if it is conform to the json syntax

  • Step 3: Validate file against official json schema

Variables

steps – List of Steps

add_log_record(record: logging.LogRecord) None

Adds a logging.LogRecord to the log list of the actual Step

Parameters

recordlogging.LogRecord which should be added to the current Step

add_log_records_from_data_checker(data_checker: basyx.aas.examples.data._helper.DataChecker) None

Sets the status of the current Step and convert the checks to logging.LogRecords and adds these to the current Step

Step: FAILED if the DataChecker consist at least one failed check otherwise SUCCESS

Parameters

data_checkerDataChecker which checks should be added to the current Step

add_step(name: str) None

Adding a new Step to the manager with a given name, status = NOT_EXECUTED and an empty list of records

Parameters

name – Name of the Step

emit(record: logging.LogRecord)

logging.Handler function for adding logging.LogRecords from a logger to the current Step

Parameters

recordlogging.LogRecord which should be added

format_state_manager(verbose_level: int = 0) str

Creates a report with all executed steps: Containing the status, the step name and the logging.LogRecords if wanted

Parameters

verbose_level

Decision which kind of LogRecords should be in the string

  • 0: No LogRecords

  • 1: Only LogRecords with log level >= logging.WARNING

  • 2: All LogRecords

Returns

formatted report

format_step(index: int, verbose_level: int = 0) str

Creates a string for the step containing the status, the step name and the logging.LogRecords if wanted

Parameters
  • index – Step index in the step list of the manager

  • verbose_level

    Decision which kind of LogRecords should be in the string

    • 0: No LogRecords

    • 1: Only LogRecords with log level >= logging.WARNING

    • 2: All LogRecords

Returns

formatted string of the step

get_error_logs_from_step(index: int) List[logging.LogRecord]

Returns a list of logging.LogRecords of a step where the log level is logging.ERROR or logging.WARNING

Parameters

index – Step index in the Step list of the manager

Returns

List of LogRecords with log level logging.ERROR or logging.WARNING

set_step_status(status: basyx.aas.compliance_tool.state_manager.Status) None

Sets the status of the current step

Parameters

status – status which should be set

set_step_status_from_log() None

Sets the status of the current step based on the log entries

property status: basyx.aas.compliance_tool.state_manager.Status

Determine the status of all steps in following way: 1. If there is at least one step with status = NOT_EXECUTED than NOT_EXECUTED will be returned 2. If there is at least one step with status = FAILED than FAILED will be returned 3. Else status SUCCESS will be returned

Returns

status of the manager

class basyx.aas.compliance_tool.state_manager.Status(value)

Possible Status States:

Variables
  • SUCCESS

  • SUCCESS_WITH_WARNINGS

  • FAILED

  • NOT_EXECUTED

class basyx.aas.compliance_tool.state_manager.Step(name: str, status: basyx.aas.compliance_tool.state_manager.Status, log_list: List[logging.LogRecord])

A step represents a single test stage in a test protocol of a ComplianceToolStateManager

Variables
  • name – Name of the step

  • ~.status – Status of the step from type Status

  • log_list – List of logging.LogRecords which belong to this step