|
| 1 | +#!/usr/bin/env -S python3 -B |
| 2 | +# |
| 3 | +# Copyright (c) 2024 Project CHIP Authors |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +import click |
| 19 | +import importlib |
| 20 | +import os |
| 21 | +import string |
| 22 | + |
| 23 | +from pathlib import Path |
| 24 | +from matter_testing_support import generate_mobly_test_config, MatterTestConfig |
| 25 | + |
| 26 | + |
| 27 | +def indent_multiline(multiline: str, num_spaces: int) -> str: |
| 28 | + ''' Indents subsequent lines of a multiline string by num_spaces spaces''' |
| 29 | + s = multiline.split('\n') |
| 30 | + s = [(num_spaces * ' ' + line.lstrip()).rstrip() for line in s] |
| 31 | + return '\n'.join(s).lstrip() |
| 32 | + |
| 33 | + |
| 34 | +@click.command() |
| 35 | +@click.argument('filename', type=click.Path(exists=True)) |
| 36 | +@click.argument('classname', type=str) |
| 37 | +@click.argument('test', type=str) |
| 38 | +def main(filename, classname, test): |
| 39 | + module = importlib.import_module(Path(os.path.basename(filename)).stem) |
| 40 | + test_class = getattr(module, classname) |
| 41 | + config = generate_mobly_test_config(MatterTestConfig()) |
| 42 | + test_instance = test_class(config) |
| 43 | + steps = test_instance.get_test_steps(test) |
| 44 | + indent = 6 |
| 45 | + s = ('[cols="5%,45%,45%"]\n' |
| 46 | + '|===\n' |
| 47 | + '|**#** |*Test Step*|*Expected Outcome*\n') |
| 48 | + for step in steps: |
| 49 | + # add 2 to indent for a| and | at start |
| 50 | + s += f'|{step.test_plan_number:<{indent}}a|{indent_multiline(step.description, indent+3)}\n' |
| 51 | + padding = (indent + 1) * ' ' |
| 52 | + s += f'{padding}a|{indent_multiline(step.expectation, indent+3)}\n\n' |
| 53 | + s += '|===\n' |
| 54 | + |
| 55 | + print(s) |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + main() |
0 commit comments