summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2014-10-11 22:18:24 +0100
committerRichard Maw <richard.maw@gmail.com>2014-10-15 14:07:44 +0000
commit16c307a779b929eb4c0010fc20e12df4f28b3247 (patch)
tree635df41d68cd05f935ee9e9f5032ba08d6656412
parent9b3cd8f334fe335a77b71cdd5c964d88eebd3fbd (diff)
downloadcmdtest-16c307a779b929eb4c0010fc20e12df4f28b3247.tar.gz
yarn: Move --no-act logic out of .run_scenario
-rwxr-xr-xyarn34
-rw-r--r--yarnlib/scenario_runner.py2
2 files changed, 23 insertions, 13 deletions
diff --git a/yarn b/yarn
index 47ef754..15b279a 100755
--- a/yarn
+++ b/yarn
@@ -32,6 +32,16 @@ import cmdtestlib
import yarnlib
+def dry_scenario_runner_factory(info, ts):
+ class DryScenarioRunner(yarnlib.ScenarioRunner):
+ def run_scenario(self, scenario, datadir, homedir):
+ info('Pretending everything went OK')
+ for step in scenario.steps:
+ ts['current_step'] = step
+ return True
+ return DryScenarioRunner
+
+
class YarnRunner(cliapp.Application):
def add_settings(self):
@@ -143,10 +153,16 @@ class YarnRunner(cliapp.Application):
self.steps_run = 0
self.timings = []
- scenario_runner = yarnlib.ScenarioRunner(shell_prelude, os.getcwd(),
- self.parse_env(),
- pre_step_cb=self.pre_step,
- post_step_cb=self.post_step)
+ if self.settings['no-act']:
+ runner_class = dry_scenario_runner_factory(self.info, self.ts)
+ else:
+ runner_class = yarnlib.ScenarioRunner
+ scenario_runner = runner_class(shell_prelude, os.getcwd(),
+ self.parse_env(),
+ pre_step_cb=self.pre_step,
+ post_step_cb=self.post_step,
+ pre_scenario_cb=self.pre_scenario,
+ post_scenario_cb=self.post_scenario)
start_time = time.time()
failed_scenarios = []
@@ -242,15 +258,7 @@ class YarnRunner(cliapp.Application):
os.mkdir(homedir)
ud = self.pre_scenario(scenario, datadir, homedir)
-
- if self.settings['no-act']:
- self.info('Pretending everything went OK')
- for step in scenario.steps:
- self.ts['current_step'] = step
- ok = True
- else:
- ok = scenario_runner.run_scenario(scenario, datadir, homedir)
-
+ ok = scenario_runner.run_scenario(scenario, datadir, homedir)
self.post_scenario(scenario, datadir, homedir, ud)
return ok
diff --git a/yarnlib/scenario_runner.py b/yarnlib/scenario_runner.py
index e0cdf62..28172e4 100644
--- a/yarnlib/scenario_runner.py
+++ b/yarnlib/scenario_runner.py
@@ -101,6 +101,8 @@ class ScenarioRunner(object):
def __init__(self, shell_prelude, srcdir, extra_env=(),
pre_step_cb=default_pre_step, post_step_cb=default_post_step,
+ pre_scenario_cb=lambda *x: None,
+ post_scenario_cb=lambda *x: None,
cmdrunner=cliapp.runcmd_unchecked):
self.shell_prelude = shell_prelude
self.srcdir = srcdir