API Reference
This document provides details about the API of the markdown_to_testcase package.
TestCaseParser
The TestCaseParser class is responsible for parsing markdown files and extracting test cases.
from markdown_to_testcase.parser import TestCaseParser
parser = TestCaseParser(verbose=True)
test_cases = parser.parse_file("path/to/markdown_file.md")
markdown_to_testcase.parser.TestCaseParser
Parser for extracting test cases from markdown files.
Source code in markdown_to_testcase/parser.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
__init__(verbose=False, check_yaml_lint=False)
Initialize the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to output detailed error messages and suggestions. |
False
|
check_yaml_lint
|
bool
|
Whether to run yamllint on YAML content before parsing. |
False
|
Source code in markdown_to_testcase/parser.py
parse_content(content, source_path='')
Parse markdown content and extract test cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Markdown content as string. |
required |
source_path
|
str
|
Source file path (for logging purposes). |
''
|
Returns:
| Type | Description |
|---|---|
Dict[str, List[Dict[str, Any]]]
|
Dictionary with test case file names as keys and lists of test case dictionaries as values. |
Source code in markdown_to_testcase/parser.py
parse_file(file_path)
Parse a markdown file and extract test cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the markdown file. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, List[Dict[str, Any]]]
|
Dictionary with test case file names as keys and lists of test case dictionaries as values. |
Source code in markdown_to_testcase/parser.py
parse_yaml_file(file_path)
Parse a YAML file containing test cases directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the YAML file. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, List[Dict[str, Any]]]
|
Dictionary with test case file names as keys and lists of test case dictionaries as values. |
Source code in markdown_to_testcase/parser.py
run_yamllint(yaml_content, file_name, _source_path)
Run yamllint on the YAML content and return any errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_content
|
str
|
YAML content as string. |
required |
file_name
|
str
|
Name of the file for logging purposes. |
required |
source_path
|
Source file path for logging purposes. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List of yamllint error messages. |
Source code in markdown_to_testcase/parser.py
TestCaseConverter
The TestCaseConverter class converts test cases to CSV and Excel formats.
from markdown_to_testcase.converter import TestCaseConverter
converter = TestCaseConverter(output_dir="output")
csv_files = converter.convert_to_csv(test_cases)
excel_file = converter.convert_to_excel(test_cases)
markdown_to_testcase.converter.TestCaseConverter
Converter for transforming test cases to various formats.
Source code in markdown_to_testcase/converter.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
__init__(output_dir='output')
Initialize the converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory to store output files. |
'output'
|
convert_to_csv(test_cases, force=False)
Convert test cases to CSV files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_cases
|
Dict[str, List[Dict[str, Any]]]
|
Dictionary with test case file names as keys and lists of test case dictionaries as values. |
required |
force
|
bool
|
Whether to overwrite existing files without asking. |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of paths to the created CSV files. |
Source code in markdown_to_testcase/converter.py
convert_to_excel(test_cases, force=False)
Convert test cases to an Excel file with multiple sheets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_cases
|
Dict[str, List[Dict[str, Any]]]
|
Dictionary with test case file names as keys and lists of test case dictionaries as values. |
required |
force
|
bool
|
Whether to overwrite existing files without asking. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Path to the created Excel file, or None if no file was created. |