diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-03-20 08:15:37 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-03-20 08:15:37 +0200 |
commit | 78614308d228c054a9fa7c30edbc4d49476a7925 (patch) | |
tree | c5765de1cc36ec992c76abd0aad0582a61ce6bbe /templates | |
parent | fb6db04c1117d493bfa043b6f4b651cbdbf33a36 (diff) | |
download | subplot-78614308d228c054a9fa7c30edbc4d49476a7925.tar.gz |
Change: generated Python program runs scenarios in random order
Diffstat (limited to 'templates')
-rw-r--r-- | templates/python.py | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/templates/python.py b/templates/python.py index 4b5f343..a0f4ec5 100644 --- a/templates/python.py +++ b/templates/python.py @@ -10,6 +10,7 @@ import base64 import logging import os +import random import shutil import tempfile @@ -80,26 +81,36 @@ os.chdir(_datadir) {% for scenario in scenarios %} ###################################### # Scenario: {{ scenario.title }} -title = decode_str('{{ scenario.title | base64 }}') -print('scenario: {}'.format(title)) -_scendir = tempfile.mkdtemp(dir=_datadir) -os.chdir(_scendir) -ctx = Context() -{% for step in scenario.steps %} -# Step: {{ step.text }} -step = decode_str('{{ step.text | base64 }}') -print(' step: {{ step.kind | lower }} {}'.format(step)) -args = {} -{% for part in step.parts %}{% if part.CapturedText is defined -%} -name = decode_str('{{ part.CapturedText.name | base64 }}') -text = decode_str('{{ part.CapturedText.text | base64 }}') -args[name] = text -{% endif -%} -{% endfor -%} -{{ step.function }}(ctx, **args) -{% endfor %} +def scenario_{{ loop.index }}(): + title = decode_str('{{ scenario.title | base64 }}') + print('scenario: {}'.format(title)) + _scendir = tempfile.mkdtemp(dir=_datadir) + os.chdir(_scendir) + ctx = Context() + {% for step in scenario.steps %} + # Step: {{ step.text }} + step = decode_str('{{ step.text | base64 }}') + print(' step: {{ step.kind | lower }} {}'.format(step)) + args = {} + {% for part in step.parts %}{% if part.CapturedText is defined -%} + name = decode_str('{{ part.CapturedText.name | base64 }}') + text = decode_str('{{ part.CapturedText.text | base64 }}') + args[name] = text + {% endif -%} + {% endfor -%} + {{ step.function }}(ctx, **args) + {% endfor %} {% endfor %} +def main(): + scenarios = [{% for scenario in scenarios %} + scenario_{{ loop.index }},{% endfor %} + ] + random.shuffle(scenarios) + for s in scenarios: + s() + +main() ############################################################################# # Clean up temporary directory and report success. |