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 ...@@ -9,8 +9,8 @@ from jinja2 import Environment, FileSystemLoader
TEMPLATE_DIR="." TEMPLATE_DIR="."
# This command makes sure the following formatting applies for the respective # This command parse lists to make sure the following formatting
# sections: # applies for the respective sections:
# #
# pre-conditions: # pre-conditions:
# - Start line with '#' or '$' for commands, everything else is a comment. # - Start line with '#' or '$' for commands, everything else is a comment.
...@@ -21,14 +21,12 @@ TEMPLATE_DIR="." ...@@ -21,14 +21,12 @@ TEMPLATE_DIR="."
# run: steps: # run: steps:
# - Star '#' for comments , everything else is a command. # - Star '#' for comments , everything else is a command.
# #
def comments_commands(lines, run=False): def parse_list(lines, run=False):
processed_lines = [] processed_lines = []
for line in lines: for line in lines:
p, c = '', '' p, c = '', ''
sline = line.strip() sline = line.strip()
if not sline: if not sline:
processed_lines.append((p, c))
continue continue
if run: if run:
...@@ -48,7 +46,7 @@ def comments_commands(lines, run=False): ...@@ -48,7 +46,7 @@ def comments_commands(lines, run=False):
return processed_lines return processed_lines
def parse_format(testcase_data): def get_template_values(testcase_data):
template_values = {} template_values = {}
# Mandatory fields # Mandatory fields
...@@ -62,7 +60,7 @@ def parse_format(testcase_data): ...@@ -62,7 +60,7 @@ def parse_format(testcase_data):
value = metadata.get(mv) value = metadata.get(mv)
if value: if value:
if mv == 'expected': if mv == 'expected':
template_values.update({ mv : comments_commands(value) }) template_values.update({ mv : parse_list(value) })
else: else:
template_values.update({ mv.replace('-', '_') : value }) template_values.update({ mv.replace('-', '_') : value })
else: else:
...@@ -78,15 +76,13 @@ def parse_format(testcase_data): ...@@ -78,15 +76,13 @@ def parse_format(testcase_data):
if not steps: if not steps:
print("Error: missing mandatory field steps for run") print("Error: missing mandatory field steps for run")
sys.exit(1) sys.exit(1)
template_values.update({ 'run_steps' : template_values.update({ 'run_steps' : parse_list(steps, run=True) })
comments_commands(steps, run=True) })
# No mandatory fields # No mandatory fields
for nm in ['notes', 'format', 'maintainer', 'resources', 'pre-conditions']: for nm in ['notes', 'format', 'maintainer', 'resources', 'pre-conditions']:
value = metadata.get(nm) value = metadata.get(nm)
if value: if value:
template_values.update({ nm.replace('-', '_') : template_values.update({ nm.replace('-', '_') : parse_list(value)
comments_commands(value)
if nm in ['notes', 'pre-conditions'] if nm in ['notes', 'pre-conditions']
else value }) else value })
...@@ -102,18 +98,17 @@ def parse_format(testcase_data): ...@@ -102,18 +98,17 @@ def parse_format(testcase_data):
if '__main__' == __name__: if '__main__' == __name__:
testcase_file = sys.argv[1] testcase_file = sys.argv[1]
try: try:
with open(testcase_file) as testcase: with open(testcase_file) as testcase:
testcase_data = yaml.safe_load(testcase) tc_data = yaml.safe_load(testcase)
except yaml.scanner.ScannerError as e: except yaml.scanner.ScannerError as e:
print("yaml format error:", e) print("yaml format error:", e)
sys.exit(1) sys.exit(1)
env = Environment(loader=FileSystemLoader([TEMPLATE_DIR])) env = Environment(loader=FileSystemLoader([TEMPLATE_DIR]))
# Get template from environment and render it. # 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) 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