Exemplo n.º 1
0
 def indented_chain(self, tree, parent):
     """
     Compiles an indented mutation.
     """
     prev_line = self.lines.last()
     if prev_line is not None:
         if prev_line["method"] != "mutation":
             raise StorySyntaxError("arguments_nomutation", tree=tree)
         prev_line["args"] = prev_line["args"] + self.chained_mutations(
             tree)
         return
     raise StorySyntaxError("arguments_nomutation", tree=tree)
Exemplo n.º 2
0
 def arguments(self, tree, parent):
     """
     Compiles arguments. This is called only for nested arguments.
     """
     prev_line = self.lines.last()
     if prev_line is not None:
         if prev_line["method"] != "execute":
             raise StorySyntaxError("arguments_noservice", tree=tree)
         prev_args = prev_line["args"]
         prev_line["args"] = prev_args + self.objects.arguments(tree)
         return
     raise StorySyntaxError("arguments_noservice", tree=tree)
Exemplo n.º 3
0
 def indented_chain(self, tree, parent):
     """
     Compiles an indented mutation.
     """
     prev_line = self.lines.last()
     if prev_line is not None:
         if prev_line['method'] != 'mutation':
             raise StorySyntaxError('arguments_nomutation', tree=tree)
         prev_line['args'] = prev_line['args'] + \
             self.chained_mutations(tree)
         return
     raise StorySyntaxError('arguments_nomutation', tree=tree)
Exemplo n.º 4
0
def test_compiler_service_syntax_error(patch, compiler, lines, tree):
    patch.object(Objects, 'arguments')
    patch.object(Compiler, 'output')
    patch.object(StorySyntaxError, 'tree_position')
    lines.execute.side_effect = StorySyntaxError('error')
    with raises(StorySyntaxError):
        compiler.service(tree, None, 'parent')
    StorySyntaxError.tree_position.assert_called_with(tree)
Exemplo n.º 5
0
def test_compiler_service_syntax_error(patch, compiler, lines, tree):
    patch.object(Objects, "arguments")
    patch.object(JSONCompiler, "output")
    patch.object(StorySyntaxError, "tree_position")
    lines.execute.side_effect = StorySyntaxError("error")
    tree.data = "service"
    with raises(StorySyntaxError):
        compiler.service(tree, None, "parent")
    StorySyntaxError.tree_position.assert_called_with(tree)
Exemplo n.º 6
0
 def check_service_name(self, service, line):
     """
     Checks whether a service name is valid
     """
     if '.' in service:
         raise StorySyntaxError('service_name')
Exemplo n.º 7
0
def test_story_error(patch, story):
    """
    Ensures Story.error creates a StoryError error
    """
    assert isinstance(story.error(StorySyntaxError('error')), StoryError)
Exemplo n.º 8
0
    story.parse(parser=parser)
    parser.parse.assert_called_with(story.story)


def test_story_parse_lower(patch, story, parser):
    patch.object(Lowering, 'process')
    story.parse(parser=parser, lower=True)
    parser.parse.assert_called_with(story.story)
    Lowering.process.assert_called_with(Parser.parse())
    assert story.tree == Lowering.process(Lowering.process())


@mark.parametrize('error', [
    UnexpectedToken('token', 'expected'),
    UnexpectedInput('token', 'expected'),
    StorySyntaxError('test'),
])
def test_story_parse_error(patch, story, parser, error):
    """
    Ensures Story.parse uses Story.error for UnexpectedToken errors.
    """
    parser.parse.side_effect = error
    patch.object(Story, 'error')
    with raises(Exception):
        story.parse(parser=parser)
    Story.error.assert_called_with(error)


def test_story_modules(magic, story):
    import_tree = magic()
    story.tree = magic()