15
15
# See the License for the specific language governing permissions and
16
16
# limitations under the License.
17
17
#
18
+ import logging
18
19
import importlib
19
20
import os
21
+ import sys
20
22
from pathlib import Path
21
23
22
24
import click
@@ -35,11 +37,42 @@ def indent_multiline(multiline: str, num_spaces: int) -> str:
35
37
@click .argument ('classname' , type = str )
36
38
@click .argument ('test' , type = str )
37
39
def main (filename , classname , test ):
38
- module = importlib .import_module (Path (os .path .basename (filename )).stem )
39
- test_class = getattr (module , classname )
40
+ '''
41
+ This script generates the Test Procedure table for the test plans document
42
+ from the python script steps. In order to use this generator, the test
43
+ automation script conform to the following requirements:
44
+ - automated in python
45
+ - test implements the steps_ function to provide steps information to the TH
46
+ - TestStep list returned from the steps_ function includes both description
47
+ and expectation fields
48
+ - test does not gate any steps on PICS (top level PICS ok)
49
+
50
+
51
+ Usage: test_plan_table_generator.py filename classname test
52
+
53
+ filename - name of the file where the test is automated
54
+ classname - name of the MatterBaseTest class
55
+ test - name of the test to generate the table for (include the test_ portion)
56
+ '''
57
+ try :
58
+ module = importlib .import_module (Path (os .path .basename (filename )).stem )
59
+ except ModuleNotFoundError as e :
60
+ logging .error (f'Unable to load python module from { filename } . Please ensure this is a valid python file path' )
61
+ return - 1
62
+
63
+ try :
64
+ test_class = getattr (module , classname )
65
+ except AttributeError as e :
66
+ logging .error (f'Unable to load the test class { classname } . Please ensure this class is implemented in { filename } ' )
67
+ return - 1
68
+
40
69
config = generate_mobly_test_config (MatterTestConfig ())
41
70
test_instance = test_class (config )
42
- steps = test_instance .get_test_steps (test )
71
+ steps = test_instance .get_defined_test_steps (test )
72
+ if not steps :
73
+ logging .error (f'Unable to find steps for test { test } . Please ensure the steps_ function is implemented' )
74
+ return - 1
75
+
43
76
indent = 6
44
77
header_num = f'{ "**#**" :<{indent }} '
45
78
header_num_step = f'|{ header_num } |*TestStep* '
@@ -59,4 +92,4 @@ def main(filename, classname, test):
59
92
60
93
61
94
if __name__ == "__main__" :
62
- main ()
95
+ sys . exit ( main () )
0 commit comments