|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright © 2022, 2023, 2025 Pavel Tisnovsky |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +"""Scenario list generator.""" |
| 18 | + |
| 19 | +# Usage |
| 20 | +# python gen_scenario_list.py > docs/scenarios_list.md |
| 21 | + |
| 22 | +import os |
| 23 | + |
| 24 | +# URL prefix to create links to feature files |
| 25 | +FEATURES_URL_PREFIX = "https://github.com/lightspeed-core/lightspeed-stack/blob/main/tests/e2e/features" # noqa E501 |
| 26 | + |
| 27 | +# list of prefixes for scenarios or scenario outlines |
| 28 | +PREFIXES = ("Scenario: ", "Scenario Outline: ") |
| 29 | + |
| 30 | +# sub-directory where feature files are stored |
| 31 | +FEATURE_DIRECTORY = "features" |
| 32 | + |
| 33 | +# generate page header |
| 34 | +print("---") |
| 35 | +print("layout: page") |
| 36 | +print("nav_order: 3") |
| 37 | +print("---") |
| 38 | +print() |
| 39 | +print("# List of scenarios") |
| 40 | +print() |
| 41 | + |
| 42 | +# generage list of scenarios |
| 43 | +directory = FEATURE_DIRECTORY |
| 44 | +# files within one subdirectory needs to be sorted so the |
| 45 | +# resulting scenario list will have stable structure across versions |
| 46 | +files = sorted(os.listdir(directory)) |
| 47 | +for filename in files: |
| 48 | + # grep all .feature files |
| 49 | + if filename.endswith(".feature"): |
| 50 | + # feature file header |
| 51 | + print("## [`{}`]({}/{})\n".format(filename, FEATURES_URL_PREFIX, filename)) |
| 52 | + with open(os.path.join(directory, filename), "r") as fin: |
| 53 | + for line in fin.readlines(): |
| 54 | + line = line.strip() |
| 55 | + # process all scenarios and scenario outlines |
| 56 | + for prefix in PREFIXES: |
| 57 | + if line.startswith(prefix): |
| 58 | + line = line[len(prefix) :] |
| 59 | + print(f"* {line}") |
| 60 | + # vertical space between subsections in generated file |
| 61 | + print() |
0 commit comments