Skip to content
Snippets Groups Projects
Commit ab5b4c0f authored by Luis Araujo's avatar Luis Araujo
Browse files

Rename some functions with more accurate names


Signed-off-by: default avatarLuis Araujo <luis.araujo@collabora.co.uk>
parent 2d81d93d
No related branches found
No related tags found
No related merge requests found
......@@ -9,8 +9,8 @@ from jinja2 import Environment, FileSystemLoader
TEMPLATE_DIR="."
# This command makes sure the following formatting applies for the respective
# sections:
# This command parse lists to make sure the following formatting
# applies for the respective sections:
#
# pre-conditions:
# - Start line with '#' or '$' for commands, everything else is a comment.
......@@ -21,14 +21,12 @@ TEMPLATE_DIR="."
# run: steps:
# - Star '#' for comments , everything else is a command.
#
def comments_commands(lines, run=False):
def parse_list(lines, run=False):
processed_lines = []
for line in lines:
p, c = '', ''
sline = line.strip()
if not sline:
processed_lines.append((p, c))
continue
if run:
......@@ -48,7 +46,7 @@ def comments_commands(lines, run=False):
return processed_lines
def parse_format(testcase_data):
def get_template_values(testcase_data):
template_values = {}
# Mandatory fields
......@@ -62,7 +60,7 @@ def parse_format(testcase_data):
value = metadata.get(mv)
if value:
if mv == 'expected':
template_values.update({ mv : comments_commands(value) })
template_values.update({ mv : parse_list(value) })
else:
template_values.update({ mv.replace('-', '_') : value })
else:
......@@ -78,15 +76,13 @@ def parse_format(testcase_data):
if not steps:
print("Error: missing mandatory field steps for run")
sys.exit(1)
template_values.update({ 'run_steps' :
comments_commands(steps, run=True) })
template_values.update({ 'run_steps' : parse_list(steps, run=True) })
# No mandatory fields
for nm in ['notes', 'format', 'maintainer', 'resources', 'pre-conditions']:
value = metadata.get(nm)
if value:
template_values.update({ nm.replace('-', '_') :
comments_commands(value)
template_values.update({ nm.replace('-', '_') : parse_list(value)
if nm in ['notes', 'pre-conditions']
else value })
......@@ -102,18 +98,17 @@ def parse_format(testcase_data):
if '__main__' == __name__:
testcase_file = sys.argv[1]
try:
with open(testcase_file) as testcase:
testcase_data = yaml.safe_load(testcase)
tc_data = yaml.safe_load(testcase)
except yaml.scanner.ScannerError as e:
print("yaml format error:", e)
sys.exit(1)
env = Environment(loader=FileSystemLoader([TEMPLATE_DIR]))
# Get template from environment and render it.
data = env.get_template('index.html').render(parse_format(testcase_data))
data = env.get_template('index.html').render(get_template_values(tc_data))
print(data)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment