diff --git a/exercises/sgf-parsing/example.py b/exercises/sgf-parsing/example.py index 243dd420c3..cc21e0b6db 100644 --- a/exercises/sgf-parsing/example.py +++ b/exercises/sgf-parsing/example.py @@ -72,10 +72,13 @@ def peek(): return stack[0] def pop_until(ch): - v = '' - while peek() != ch: - v += pop() - return v + try: + v = '' + while peek() != ch: + v += pop() + return v + except IndexError: + raise ValueError('Unable to find {}'.format(ch)) while stack: assert_that(pop() == '(' and peek() == ';') while pop() == ';': diff --git a/exercises/sgf-parsing/sgf_parsing_test.py b/exercises/sgf-parsing/sgf_parsing_test.py index 0cabd08799..a802ff78dd 100644 --- a/exercises/sgf-parsing/sgf_parsing_test.py +++ b/exercises/sgf-parsing/sgf_parsing_test.py @@ -3,6 +3,8 @@ from sgf_parsing import parse, SgfTree +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 + class SgfParsingTest(unittest.TestCase): def test_empty_input(self): input_string = '' @@ -30,7 +32,7 @@ def test_single_node_tree(self): self.assertEqual(parse(input_string), expected) def test_properties_without_delimiter(self): - input_string = '(;a)' + input_string = '(;A)' with self.assertRaisesWithMessage(ValueError): parse(input_string)