summaryrefslogtreecommitdiff
path: root/yarn
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-06-19 20:42:58 +0100
committerLars Wirzenius <liw@liw.fi>2013-06-19 20:42:58 +0100
commit2c288169fd38032575feb4414c039e9c1e9e8764 (patch)
tree365b3467e08cac322943ce00830dfb140fcfb77a /yarn
parent54e347e461327c09746b45d19b1d24631652da8e (diff)
downloadcmdtest-2c288169fd38032575feb4414c039e9c1e9e8764.tar.gz
Switch to "scenario testing"
Diffstat (limited to 'yarn')
-rwxr-xr-xyarn78
1 files changed, 40 insertions, 38 deletions
diff --git a/yarn b/yarn
index 4c2f533..d9b2b47 100755
--- a/yarn
+++ b/yarn
@@ -35,35 +35,37 @@ class YarnRunner(cliapp.Application):
def setup(self):
self.ts = ttystatus.TerminalStatus(period=0.001)
self.ts.format(
- '%ElapsedTime() %Index(story,stories): %String(story_name): '
+ '%ElapsedTime() %Index(scenario,scenarios): '
+ '%String(scenario_name): '
'step %Index(step,steps): %String(step_name)')
def process_args(self, args):
- stories, implementations = self.parse_stories(args)
- self.connect_implementations(stories, implementations)
+ scenarios, implementations = self.parse_scenarios(args)
+ self.connect_implementations(scenarios, implementations)
- self.ts['stories'] = stories
- self.ts['num_stories'] = len(stories)
- logging.info('Found %d stories' % len(stories))
+ self.ts['scenarios'] = scenarios
+ self.ts['num_scenarios'] = len(scenarios)
+ logging.info('Found %d scenarios' % len(scenarios))
start_time = time.time()
- failed_stories = []
- for story in stories:
- if not self.run_story(story):
- failed_stories.append(story)
+ failed_scenarios = []
+ for scenario in scenarios:
+ if not self.run_scenario(scenario):
+ failed_scenarios.append(scenario)
duration = time.time() - start_time
self.ts.clear()
self.ts.finish()
- if failed_stories:
+ if failed_scenarios:
raise cliapp.AppException(
- 'Test suite FAILED in %s stories' % len(failed_stories))
+ 'Test suite FAILED in %s scenarios' % len(failed_scenarios))
- print ('Story test suite PASS, with %d stories, in %.1f seconds' %
- (len(stories), duration))
+ print (
+ 'Scenario test suite PASS, with %d scenarios, in %.1f seconds' %
+ (len(scenarios), duration))
- def parse_stories(self, filenames):
+ def parse_scenarios(self, filenames):
mdparser = yarnlib.MarkdownParser()
for filename in filenames:
mdparser.parse_file(filename)
@@ -71,56 +73,56 @@ class YarnRunner(cliapp.Application):
block_parser = yarnlib.BlockParser()
block_parser.parse_blocks(mdparser.blocks)
- return block_parser.stories, block_parser.implementations
+ return block_parser.scenarios, block_parser.implementations
- def connect_implementations(self, stories, implementations):
- for story in stories:
- for step in story.steps:
- self.connect_implementation(story, step, implementations)
+ def connect_implementations(self, scenarios, implementations):
+ for scenario in scenarios:
+ for step in scenario.steps:
+ self.connect_implementation(scenario, step, implementations)
- def connect_implementation(self, story, step, implementations):
+ def connect_implementation(self, scenario, step, implementations):
matching = [i for i in implementations
if step.what == i.what and
re.match('(%s)$' % i.regexp, step.text, re.I)]
if len(matching) == 0:
raise cliapp.AppException(
- 'Story %s, step "%s %s" has no matching '
+ 'Scenario %s, step "%s %s" has no matching '
'implementation' %
- (story.name, step.what, step.text))
+ (scenario.name, step.what, step.text))
if len(matching) > 1:
s = '\n'.join(
'IMPLEMENTS %s %s' % (i.what, i.regexp)
for i in matching)
raise cliapp.AppException(
- 'Story "%s", step "%s %s" has more than one '
+ 'Scenario "%s", step "%s %s" has more than one '
'matching implementations:\n%s' %
- (story.name, step.what, step.text, s))
+ (scenario.name, step.what, step.text, s))
assert step.implementation is None
step.implementation = matching[0]
- def run_story(self, story):
- logging.info('Running story %s' % story.name)
- self.ts['story'] = story
- self.ts['story_name'] = story.name
- self.ts['steps'] = story.steps
+ def run_scenario(self, scenario):
+ logging.info('Running scenario %s' % scenario.name)
+ self.ts['scenario'] = scenario
+ self.ts['scenario_name'] = scenario.name
+ self.ts['steps'] = scenario.steps
datadir = tempfile.mkdtemp()
- cleanup = [s for s in story.steps if s.what == 'FINALLY']
- normal = [s for s in story.steps if s not in cleanup]
+ cleanup = [s for s in scenario.steps if s.what == 'FINALLY']
+ normal = [s for s in scenario.steps if s not in cleanup]
ok = True
for step in normal:
- exit = self.run_step(datadir, story, step)
+ exit = self.run_step(datadir, scenario, step)
if exit != 0:
ok = False
break
for step in cleanup:
- exit = self.run_step(datadir, story, step)
+ exit = self.run_step(datadir, scenario, step)
if exit != 0:
ok = False
break
@@ -129,7 +131,7 @@ class YarnRunner(cliapp.Application):
return ok
- def run_step(self, datadir, story, step):
+ def run_step(self, datadir, scenario, step):
logging.info('Running step "%s %s"' % (step.what, step.text))
logging.info('DATADIR is %s' % datadir)
self.ts['step'] = step
@@ -157,12 +159,12 @@ class YarnRunner(cliapp.Application):
if exit != 0:
self.ts.error(
- 'ERROR: In story "%s"\nstep "%s %s" failed,\n'
+ 'ERROR: In scenario "%s"\nstep "%s %s" failed,\n'
'with exit code %d:\n'
'Standard output from shell command:\n%s'
'Standard error from shell command:\n%s' %
- (story.name, step.what, step.text, exit, self.indent(stdout),
- self.indent(stderr)))
+ (scenario.name, step.what, step.text, exit,
+ self.indent(stdout), self.indent(stderr)))
return exit