forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_examples.py
More file actions
executable file
·49 lines (36 loc) · 974 Bytes
/
extract_examples.py
File metadata and controls
executable file
·49 lines (36 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
#!/usr/bin/env python
"""Script to extract examples from library docs to ease testing them.
Usage: extract_examples.py path_to_lib
"""
import os.path
import sys
def extract_tests(path):
initialize(path)
read_tests(path)
def initialize(path):
lib = os.path.splitext(os.path.basename(path))[0]
print("""\
*** Settings ***
Library %s
*** Test Cases ***\
""" % lib)
def read_tests(path):
test = '????'
for line in open(path):
line = line.strip()
if line.startswith('='):
test = line.strip('= ')
if line.startswith('def'):
test = line[4:].split('(')[0]
if line.startswith('|') and line.endswith('|') and len(line) > 1:
if test:
print('\n', test)
test = None
print('| ' + line)
if __name__ == '__main__':
try:
path = sys.argv[1]
except IndexError:
print(__doc__)
else:
extract_tests(path)