Skip to content

Commit 18aae7b

Browse files
committedApr 25, 2024·
Add documnetation and better error reporting.
1 parent 3b86616 commit 18aae7b

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed
 

‎src/python_testing/matter_testing_support.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,10 @@ def get_test_steps(self, test: str) -> list[TestStep]:
684684
in order using self.step(number), where number is the test_plan_number
685685
from each TestStep.
686686
'''
687-
steps = self._get_defined_test_steps(test)
687+
steps = self.get_defined_test_steps(test)
688688
return [TestStep(1, "Run entire test")] if steps is None else steps
689689

690-
def _get_defined_test_steps(self, test: str) -> list[TestStep]:
690+
def get_defined_test_steps(self, test: str) -> list[TestStep]:
691691
steps_name = 'steps_' + test[5:]
692692
try:
693693
fn = getattr(self, steps_name)

‎src/python_testing/test_plan_table_generator.py

+37-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
import logging
1819
import importlib
1920
import os
21+
import sys
2022
from pathlib import Path
2123

2224
import click
@@ -35,11 +37,42 @@ def indent_multiline(multiline: str, num_spaces: int) -> str:
3537
@click.argument('classname', type=str)
3638
@click.argument('test', type=str)
3739
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+
4069
config = generate_mobly_test_config(MatterTestConfig())
4170
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+
4376
indent = 6
4477
header_num = f'{"**#**":<{indent}}'
4578
header_num_step = f'|{header_num} |*TestStep* '
@@ -59,4 +92,4 @@ def main(filename, classname, test):
5992

6093

6194
if __name__ == "__main__":
62-
main()
95+
sys.exit(main())

0 commit comments

Comments
 (0)
Please sign in to comment.