summaryrefslogtreecommitdiff
path: root/yarnlib
diff options
context:
space:
mode:
Diffstat (limited to 'yarnlib')
-rw-r--r--yarnlib/__init__.py2
-rw-r--r--yarnlib/block_parser.py17
-rw-r--r--yarnlib/block_parser_tests.py6
3 files changed, 19 insertions, 6 deletions
diff --git a/yarnlib/__init__.py b/yarnlib/__init__.py
index 7b81c66..07045fc 100644
--- a/yarnlib/__init__.py
+++ b/yarnlib/__init__.py
@@ -18,4 +18,4 @@
from mdparser import MarkdownParser
from elements import Story, StoryStep, Implementation
-from block_parser import BlockParser
+from block_parser import BlockParser, BlockError
diff --git a/yarnlib/block_parser.py b/yarnlib/block_parser.py
index 09a7a22..73d6178 100644
--- a/yarnlib/block_parser.py
+++ b/yarnlib/block_parser.py
@@ -16,9 +16,16 @@
# =*= License: GPL-3+ =*=
+import cliapp
+
import yarnlib
+class BlockError(cliapp.AppException):
+
+ pass
+
+
# Parse a sequence of textual blocks into Story and Implementation
# objects, and their constituent objects.
@@ -66,7 +73,7 @@ class BlockParser(object):
if words[0] == keyword:
return self.line_parsers[keyword](rest, blocks)
- raise StoryTestSyntaxError("Syntax error: unknown step: %s" % line1)
+ raise BlockError("Syntax error: unknown step: %s" % line1)
def parse_story(self, line, blocks):
self.stories.append(yarnlib.Story(line))
@@ -74,7 +81,7 @@ class BlockParser(object):
def parse_simple(self, what, line, blocks):
if not self.stories:
- raise StoryTestSyntaxError('Syntax errror: %s before STORY' % what)
+ raise BlockError('Syntax errror: %s before STORY' % what)
step = yarnlib.StoryStep(what, line)
self.stories[-1].steps.append(step)
return blocks
@@ -93,10 +100,10 @@ class BlockParser(object):
def parse_and(self, line, blocks):
if not self.stories:
- raise StoryTestSyntaxError('Syntax errror: AND before STORY')
+ raise BlockError('Syntax errror: AND before STORY')
story = self.stories[-1]
if not story.steps:
- raise StoryTestSyntaxError(
+ raise BlockError(
'Syntax errror: AND before what it would continue')
step = story.steps[-1]
assert step.what in self.line_parsers
@@ -105,7 +112,7 @@ class BlockParser(object):
def parse_implementing(self, line, blocks):
words = line.split()
if len(words) < 2:
- raise StoryTestSyntaxError(
+ raise BlockError(
'Syntax error: IMPLEMENTING must have what and regexp')
what = words[0]
regexp = ' '.join(words[1:])
diff --git a/yarnlib/block_parser_tests.py b/yarnlib/block_parser_tests.py
index 3dc8111..45bfe67 100644
--- a/yarnlib/block_parser_tests.py
+++ b/yarnlib/block_parser_tests.py
@@ -55,6 +55,12 @@ class BlockParserTests(unittest.TestCase):
self.parser.parse_blocks(['STORY foo\n\nGIVEN bar\nTHEN foobar'])
self.assertEqual(len(self.parser.stories), 1)
+ def test_raises_error_for_unknown_step(self):
+ self.assertRaises(
+ yarnlib.BlockError,
+ self.parser.parse_blocks,
+ ['STORY foo\nblah'])
+
def test_parses_implements_in_a_block_by_itself(self):
self.parser.parse_blocks(['IMPLEMENTS GIVEN foo\ntrue'])
impls = self.parser.implementations