From 2c288169fd38032575feb4414c039e9c1e9e8764 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 19 Jun 2013 20:42:58 +0100 Subject: Switch to "scenario testing" --- yarnlib/__init__.py | 2 +- yarnlib/block_parser.py | 28 ++++++++++++------------- yarnlib/block_parser_tests.py | 48 +++++++++++++++++++++---------------------- yarnlib/elements.py | 8 ++++---- yarnlib/mdparser.py | 6 +++--- 5 files changed, 46 insertions(+), 46 deletions(-) (limited to 'yarnlib') diff --git a/yarnlib/__init__.py b/yarnlib/__init__.py index 07045fc..88bf46f 100644 --- a/yarnlib/__init__.py +++ b/yarnlib/__init__.py @@ -17,5 +17,5 @@ from mdparser import MarkdownParser -from elements import Story, StoryStep, Implementation +from elements import Scenario, ScenarioStep, Implementation from block_parser import BlockParser, BlockError diff --git a/yarnlib/block_parser.py b/yarnlib/block_parser.py index 1a600ee..84074e2 100644 --- a/yarnlib/block_parser.py +++ b/yarnlib/block_parser.py @@ -26,16 +26,16 @@ class BlockError(cliapp.AppException): pass -# Parse a sequence of textual blocks into Story and Implementation +# Parse a sequence of textual blocks into scenario and Implementation # objects, and their constituent objects. class BlockParser(object): def __init__(self): - self.stories = [] + self.scenarios = [] self.implementations = [] self.line_parsers = { - 'STORY': self.parse_story, + 'SCENARIO': self.parse_scenario, 'GIVEN': self.parse_given, 'WHEN': self.parse_when, 'THEN': self.parse_then, @@ -75,15 +75,15 @@ class BlockParser(object): raise BlockError("Syntax error: unknown step: %s" % line1) - def parse_story(self, line, blocks): - self.stories.append(yarnlib.Story(line)) + def parse_scenario(self, line, blocks): + self.scenarios.append(yarnlib.Scenario(line)) return blocks def parse_simple(self, what, line, blocks): - if not self.stories: - raise BlockError('Syntax errror: %s before STORY' % what) - step = yarnlib.StoryStep(what, line) - self.stories[-1].steps.append(step) + if not self.scenarios: + raise BlockError('Syntax errror: %s before SCENARIO' % what) + step = yarnlib.ScenarioStep(what, line) + self.scenarios[-1].steps.append(step) return blocks def parse_given(self, line, blocks): @@ -99,13 +99,13 @@ class BlockParser(object): return self.parse_simple('FINALLY', line, blocks) def parse_and(self, line, blocks): - if not self.stories: - raise BlockError('Syntax errror: AND before STORY') - story = self.stories[-1] - if not story.steps: + if not self.scenarios: + raise BlockError('Syntax errror: AND before SCENARIO') + scenario = self.scenarios[-1] + if not scenario.steps: raise BlockError( 'Syntax errror: AND before what it would continue') - step = story.steps[-1] + step = scenario.steps[-1] assert step.what in self.line_parsers return self.line_parsers[step.what](line, blocks) diff --git a/yarnlib/block_parser_tests.py b/yarnlib/block_parser_tests.py index 975444f..c988479 100644 --- a/yarnlib/block_parser_tests.py +++ b/yarnlib/block_parser_tests.py @@ -27,52 +27,52 @@ class BlockParserTests(unittest.TestCase): self.parser = yarnlib.BlockParser() def test_is_initially_empty(self): - self.assertEqual(self.parser.stories, []) + self.assertEqual(self.parser.scenarios, []) self.assertEqual(self.parser.implementations, []) def test_parses_simple_elements(self): self.parser.parse_blocks( - ['STORY foo', 'GIVEN bar', + ['SCENARIO foo', 'GIVEN bar', 'WHEN foobar\nTHEN yoyo\nFINALLY yay\nAND yeehaa']) - self.assertEqual(len(self.parser.stories), 1) + self.assertEqual(len(self.parser.scenarios), 1) self.assertEqual(len(self.parser.implementations), 0) - story = self.parser.stories[0] - self.assertEqual(story.name, 'foo') - self.assertEqual(len(story.steps), 5) - self.assertEqual(story.steps[0].what, 'GIVEN') - self.assertEqual(story.steps[0].text, 'bar') - self.assertEqual(story.steps[1].what, 'WHEN') - self.assertEqual(story.steps[1].text, 'foobar') - self.assertEqual(story.steps[2].what, 'THEN') - self.assertEqual(story.steps[2].text, 'yoyo') - self.assertEqual(story.steps[3].what, 'FINALLY') - self.assertEqual(story.steps[3].text, 'yay') - self.assertEqual(story.steps[4].what, 'FINALLY') - self.assertEqual(story.steps[4].text, 'yeehaa') + scenario = self.parser.scenarios[0] + self.assertEqual(scenario.name, 'foo') + self.assertEqual(len(scenario.steps), 5) + self.assertEqual(scenario.steps[0].what, 'GIVEN') + self.assertEqual(scenario.steps[0].text, 'bar') + self.assertEqual(scenario.steps[1].what, 'WHEN') + self.assertEqual(scenario.steps[1].text, 'foobar') + self.assertEqual(scenario.steps[2].what, 'THEN') + self.assertEqual(scenario.steps[2].text, 'yoyo') + self.assertEqual(scenario.steps[3].what, 'FINALLY') + self.assertEqual(scenario.steps[3].text, 'yay') + self.assertEqual(scenario.steps[4].what, 'FINALLY') + self.assertEqual(scenario.steps[4].text, 'yeehaa') def test_normalises_whitespace(self): - self.parser.parse_blocks(['STORY foo bar ']) - self.assertEqual(self.parser.stories[0].name, 'foo bar') + self.parser.parse_blocks(['SCENARIO foo bar ']) + self.assertEqual(self.parser.scenarios[0].name, 'foo bar') def test_handles_empty_line(self): - self.parser.parse_blocks(['STORY foo\n\nGIVEN bar\nTHEN foobar']) - self.assertEqual(len(self.parser.stories), 1) + self.parser.parse_blocks(['SCENARIO foo\n\nGIVEN bar\nTHEN foobar']) + self.assertEqual(len(self.parser.scenarios), 1) def test_raises_error_for_unknown_step(self): self.assertRaises( yarnlib.BlockError, self.parser.parse_blocks, - ['STORY foo\nblah']) + ['SCENARIO foo\nblah']) - def test_raises_error_for_step_outside_story(self): + def test_raises_error_for_step_outside_scenario(self): self.assertRaises( yarnlib.BlockError, self.parser.parse_blocks, ['GIVEN foo']) - def test_raises_error_for_AND_before_story(self): + def test_raises_error_for_AND_before_scenario(self): self.assertRaises( yarnlib.BlockError, self.parser.parse_blocks, @@ -82,7 +82,7 @@ class BlockParserTests(unittest.TestCase): self.assertRaises( yarnlib.BlockError, self.parser.parse_blocks, - ['STORY foo\nAND bar']) + ['SCENARIO foo\nAND bar']) def test_parses_implements_in_a_block_by_itself(self): self.parser.parse_blocks(['IMPLEMENTS GIVEN foo\ntrue']) diff --git a/yarnlib/elements.py b/yarnlib/elements.py index a1dea0d..9eeb1b7 100644 --- a/yarnlib/elements.py +++ b/yarnlib/elements.py @@ -16,9 +16,9 @@ # =*= License: GPL-3+ =*= -# This is a step in a story: GIVEN, WHEN, THEN, etc. +# This is a step in a scenario: GIVEN, WHEN, THEN, etc. -class StoryStep(object): +class ScenarioStep(object): def __init__(self, what, text): self.what = what @@ -26,9 +26,9 @@ class StoryStep(object): self.implementation = None -# This is the story itself. +# This is the scenario itself. -class Story(object): +class Scenario(object): def __init__(self, name): self.name = name diff --git a/yarnlib/mdparser.py b/yarnlib/mdparser.py index 6d16772..6708369 100644 --- a/yarnlib/mdparser.py +++ b/yarnlib/mdparser.py @@ -25,7 +25,7 @@ from markdown.treeprocessors import Treeprocessor # # Classes for Markdown parsing. See python-markdown documentation # for details. We want to find all top level code blocks (indented -# four spaces in the Markdown), which we'll parse for story test +# four spaces in the Markdown), which we'll parse for scenario test # stuff later on. We create a Python markdown extension and use # "tree processor" to analyse the parsed ElementTree at the right # moment for top level
 blocks.
@@ -50,7 +50,7 @@ class GatherCodeBlocks(Treeprocessor):
 # gatherer at the right time. It stores the list of top level
 # code blocks as the blocks attribute.
 
-class ParseStoryTestBlocks(markdown.extensions.Extension):
+class ParseScenarioTestBlocks(markdown.extensions.Extension):
 
     def extendMarkdown(self, md, md_globals):
         self.blocks = []
@@ -64,7 +64,7 @@ class MarkdownParser(object):
         self.blocks = []
 
     def parse_string(self, text):
-        ext = ParseStoryTestBlocks()
+        ext = ParseScenarioTestBlocks()
         f = StringIO.StringIO()
         markdown.markdown(text, output=f, extensions=[ext])
         self.blocks = ext.blocks
-- 
cgit v1.2.1