-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCheckProjectAttributes.py
83 lines (62 loc) · 2.44 KB
/
CheckProjectAttributes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (C) 2023 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
# -*- coding: utf-8 -*-
from typing import List
from .api.AbstractProjectCheck import AbstractProjectCheck
from .helper.CheckType import CheckType
from .helper.CheckAttributes import check_attributes
try:
from tts.core.logging import SPrint, WPrint, EPrint
from tts.core.api.internalApi.Api import Api
api = Api()
except:
from logging import info as SPrint, warning as WPrint, error as EPrint
# keys declared in "parameters" in config.yaml:
# ParameterKeys.REGEX_PATTERN
# ParameterKeys.REGEX_DESCRIPTION
# module type: mandatory
MODULE_TYPE = CheckType.PROJECT.value
class CheckProjectAttributes(AbstractProjectCheck):
"""
Check project Attributes
=========================
Description
-----------
Checks whether all project attributes are set according to YAML config.
Specifics and Results
---------------------
Instructions:
Specify the attributes to be checked in the YAML configuration file according to the following
pattern. Three types of checks are possible
1. Check if a value should exists for a specific attribute or if attributes should be left
empty:
<attribute name>: True, False
2. Check if a selected attribute value is in a list of allowed choices:
<attribute name>:
[<choice one>, <choice two>, ...]
3. Check if an attribute matches a specific pattern
<attribute name>:
"Regex Pattern": <your pattern>
("Regex Description": <description for error print>) optional
Return messages:
- "<attribute name> must not be empty"
- "<attribute name> must not be set
- "<attribute name> no valid option out of: <attributes options>"
- "No field: 'Regex Pattern' was provided!"
- "<Provided pattern> is not a valid pattern!"
- "<Provided pattern> does not match description: 'Regex Description' "
- "<Provided pattern> does not match pattern: 'Regex Pattern'"
"""
def __init__(self, internalApi): # pylint: disable=W0613
"""
Constructor to load the check parameters from config.yaml
"""
super().__init__()
def GetName(self) -> str:
"""
Name to be shown in UI and used in the config.yaml
"""
return type(self).__name__
def check(self, test_item, parameters) -> List:
return check_attributes(test_item, MODULE_TYPE, self.config, parameters)