2
2
3
3
# GHERKIN PROCESSOR
4
4
5
- A Python package that converts Gherkin scenarios into Python dataclass objects . It offers flexible conversion with strict or relaxed validation of the Gherkin syntax .
5
+ ** Gherkin Processor ** is a Python package that processes Gherkin files into Python * dataclasses * . It provides utilities for validating, processing, and saving Gherkin scenarios in both text and JSON formats .
6
6
7
7
---
8
8
@@ -21,105 +21,80 @@ A Python package that converts Gherkin scenarios into Python dataclass objects.
21
21
22
22
## Features
23
23
24
- - Converts Gherkin scenarios into Python ` dataclasses ` for easy manipulation and analysis.
25
- - Supports strict format validation, ensuring the Gherkin scenarios follow the correct syntax.
26
- - Allows conversion of scenarios even with minor syntax errors, making it more robust.
27
- - Built-in flexibility for customization and extension.
24
+ - Gherkin scenario validation
25
+ - Gherkin scenario syntax issue description
26
+ - Gherkin scenario content processing into Python dataclass
27
+ - Save processed scenarios in text or JSON format
28
+ - Directly load scenarios from file paths
28
29
29
30
## Installation
30
31
31
- ``` shell
32
- # 1. Clone the Github repository
33
- git clone https://github.com/MarkLehoczky/gherkin-processor.git
34
-
35
- # 2. Install package with pip
36
- pip install gherkin-processor
37
- ```
38
-
39
- ## Usage
40
-
41
- ### Script
42
-
43
- ``` python
44
- from dataclasses import asdict
45
- from json import dumps
32
+ You can install the ** Gherkin Processor** package by cloning the repository or downloading from the releases.
46
33
47
- from gherkin_processor.utils import scenario
48
- from gherkin_processor.scenario import Scenario
34
+ ### Clone the Repository
49
35
50
- # Loads a Gherkin scenario from a file and processes it into a python data class.
51
- with open (" scenario.txt" , " r" , encoding = " utf-8" ) as scenario_text_file:
52
- scenario_text: str = scenario_text_file.read()
53
- scenario_instance: Scenario = scenario.process(scenario_text)
36
+ ``` sh
37
+ # 1. Clone the repository
38
+ git clone https://github.com/MarkLehoczky/gherkin-processor.git
54
39
55
- # Prints some of the scenario components to the standard output.
56
- print (" , " .join(scenario_instance.tags))
57
- print (scenario_instance.name)
40
+ # 2. Navigate to the cloned directory
41
+ cd gherkin-processor
58
42
59
- # Converts the scenario into dictionary format, then saves it as a json.
60
- with open (" scenario.json" , " w" ) as scenario_json_file:
61
- scenario_json: dict = asdict(scenario_instance)
62
- scenario_json_file.write(dumps(scenario_json, indent = 4 ))
43
+ # Install the package via 'pip'
44
+ pip install .
63
45
```
64
46
65
- ## Dataclass Structure
47
+ ### Download from Releases
66
48
67
- The resulting Python dataclass structure represents the Gherkin scenario hierarchy. Here's an example of what the structure looks like:
49
+ 1 . Go to the [ Releases] ( https://github.com/MarkLehoczky/gherkin-processor/releases ) page.
50
+ 2 . Download the latest release.
51
+ 3 . Extract the downloaded file.
52
+ 4 . Navigate to the extracted directory.
53
+ 5 . Install the package with the following command:
68
54
69
- ``` python
70
- @dataclass
71
- class Scenario :
72
- tags: List[str ]
73
- name: str
74
- steps: List[Dict[str , Dict[str , List[str ]] | str ]]
75
- template_table: Optional[Dict[str , List[str ]]]
55
+ ``` sh
56
+ pip install .
76
57
```
77
58
78
- * Depending whether a step is followed by docstring or table, the ` steps ` variable's structure may change. *
59
+ ## Usage
79
60
80
- ## Prerequisites
61
+ ### Command Line Interface
81
62
82
- ### Mandatory
63
+ The ** Gherkin Processor ** can be used via the command line interface (CLI).
83
64
84
- - Python 3.10 or newer version
65
+ ``` sh
66
+ gherkin-processor [-h] -i INPUT [-p] [-s] [--save-as-json] [--validate]
67
+ ```
85
68
86
- ### Advised
69
+ #### Options
87
70
88
- #### VSCode extensions
71
+ ``` text
72
+ -h, --help show this help message and exit
73
+ -i INPUT, --input INPUT specify the input Gherkin file location to process
74
+ -p, --print print the processed Gherkin scenario to the standard output
75
+ -s, --save save the processed Gherkin scenario to a file
76
+ --save-as-json save the processed Gherkin scenario to a file in JSON format
77
+ --validate validate the input Gherkin file syntax
78
+ ```
79
+
80
+ See the [ CLI examples] ( examples/cli.ipynb ) for details.
89
81
90
- The following extensions are listed in the ` .vscode/extensions.json ` file.
82
+ ### Python API
91
83
92
- - [ autoDocstring - Python Docstring Generator] ( https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring )
93
- - [ autoflake] ( https://marketplace.visualstudio.com/items?itemName=mikoz.autoflake-extension )
94
- - [ Black Formatter] ( https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter )
95
- - [ Mypy Type Checker] ( https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker )
96
- - [ Pylance] ( https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance )
97
- - [ Pylint] ( https://marketplace.visualstudio.com/items?itemName=ms-python.pylint )
98
- - [ Python] ( https://marketplace.visualstudio.com/items?itemName=ms-python.python )
99
- - [ Python Debugger] ( https://marketplace.visualstudio.com/items?itemName=ms-python.debugpy )
100
- - [ Python Docstring Highlighter] ( https://marketplace.visualstudio.com/items?itemName=rodolphebarbanneau.python-docstring-highlighter )
101
- - [ Python Test Explorer for Visual Studio Code] ( https://marketplace.visualstudio.com/items?itemName=littlefoxteam.vscode-python-test-adapter )
102
- - [ Python Type Hint] ( https://marketplace.visualstudio.com/items?itemName=njqdev.vscode-python-typehint )
84
+ The ** Gherkin Processor** can also be used programmatically in a Python code.
103
85
104
- #### Python packages
86
+ ``` python
87
+ from gherkin_processor.utils import scenario # file
88
+ from gherkin_processor.scenario import Scenario # class
105
89
106
- The following packages are listed in the ` requirements.txt ` file.
107
- To install them simply use the following command:
90
+ # Load and process the scenario from a file
91
+ processed_scenario: Scenario = scenario.load( " path/to/scenario.feature " )
108
92
109
- ``` shell
110
- pip install -r requirements.txt
93
+ # Save the processed scenario to a file
94
+ scenario.save(processed_scenario, " path/to/saved_scenario.feature " )
111
95
```
112
96
113
- - pylint
114
- - mypy
115
- - pyflakes
116
- - radon
117
- - black
118
- - pycodestyle
119
- - pydocstyle
120
- - bandit
121
- - pytest
122
- - pytest-cov
97
+ See the [ API examples] ( examples/api.ipynb ) and [ Data class structure] ( examples/data.ipynb ) for details.
123
98
124
99
## License
125
100
0 commit comments