Rules checker#
Rule checker is a tool that allows to check rules on a Scade One project. Using this tool, users can check their models
using predefined rules, but also create their own rules extending the base class Rule implementing
the logic for checking certain conditions in a Scade One project.
The following diagram shows the key classes and relationships.
An example of how to define a rule using the base class Rule is provided in the
Rules checker example section.
API reference for these classes is provided below.
- class ansys.scadeone.core.svc.metrics_rules.rules.RuleStatus(*values)#
Bases:
EnumPossible status values for a rule check
- OK = 1#
The rule check succeeded.
- FAILED = 2#
The rule check failed.
- ERROR = 3#
An error occurred during the rule check.
- NA = 4#
The rule does not apply to the checked object.
- class ansys.scadeone.core.svc.metrics_rules.rules.RuleSeverity(*values)#
Bases:
EnumPossible severity values
- MANDATORY = 1#
The rule is mandatory. If it fails, the model is not compliant with the rule set.
- REQUIRED = 2#
The rule is recommended. If it fails, the model is compliant with the rule set, but it is recommended to fix it.
- ADVISORY = 3#
The rule is advisory. If it fails, the model is compliant with the rule set, but it is recommended to fix it if possible.
- class ansys.scadeone.core.svc.metrics_rules.rules.RuleResult(status: RuleStatus, message: str | None = None)#
Bases:
objectRepresents the result of a rule check.
- Attributes:
- status
RuleStatus The status of the rule check (OK, FAILED, ERROR, NA).
- message
str An message describing the result. By default, the message is set to an empty string.
- status
- class ansys.scadeone.core.svc.metrics_rules.rules.Rule(id: str, label: str, category: str, severity: RuleSeverity, types: list[Type[SwanItem]] | None = None, description: str = '', parameters: str = '')#
Bases:
Check,ABCThe Rule class is a representation of a Rule of the Scade One Rules Checker. A derived class adds a new Rule to the tool.
- on_start(model: Model) RuleResult#
Called before any call to on_check or before_checking_subtree is done. Not called if no item matches the rule.
- Parameters:
- model: Model
The model on which rules are checked
- Returns:
RuleResultRuleStatus.OK, or RuleStatus.ERROR if an error occurred, leading the whole Rules Checker computation to fail.
- before_checking_subtree(item: SwanItem) RuleResult#
Called after ‘on_start’ and before ‘on_check’. First ‘before_checking_subtree’ is called for that item, then recursively for each item it contains. Finally on_check is called on the item to return the rule check result. There is no default implementation provided but implementers must return either Rule.OK, or Rule.ERROR if an error occurred, leading the whole Rules checker computation to fail.
- Parameters:
- item: SwanItem
The Swan item on which the rule is applicable or a direct or indirect sub-element it contains
- Returns:
RuleResultRuleStatus.OK, or RuleStatus.ERROR if an error occurred, leading the whole Rules checker computation to fail.
- Raises:
NotImplementedErrorIf the method is not redefined by the derived class.
- on_check(item: SwanItem) RuleResult#
Checks whether the rule succeeds. Returns RuleStatus.OK if the rule succeeds, Rule.FAILED if the rule fails,
- Parameters:
- item: SwanItem
The Swan item on which the rule is checked
- Returns:
RuleResultRuleStatus.OK if the rule succeeds, RuleStatus.FAILED if the rule fails, RuleStatus.NO_RULE if the rule does not apply to the item, and Rule.ERROR if an error occurred, leading the whole Rules checker computation to fail.
- after_checking_subtree(item: SwanItem) RuleResult#
Called after ‘on_check’ (independently of its result) and before ‘on_stop’. This method is called from the item and recursively called for all sub-elements it contains directly or indirectly. There is no default implementation provided but implementers are invited to return Rule.OK, or Rule.ERROR if an error occurred, leading the whole Rules checker computation to fail.
- Parameters:
- item: SwanItem
The Swan item on which the rule has been applied or a direct or indirect sub-element it contains
- Returns:
RuleResultRuleStatus.OK, or RuleStatus.ERROR if an error occurred, leading the whole Rules checker computation to fail.
- Raises:
NotImplementedErrorIf the method is not redefined by the derived class.
- on_stop() RuleResult#
Called once all checks have been done. Not called if no item matches the rule.
- Returns:
RuleResultRuleStatus.OK, or RuleStatus.ERROR if an error occurred, leading the whole Rules checker computation to fail.