def test_app_lexer(patch, read_story): patch.init(Parser) patch.object(Parser, 'lex') patch.object(App, 'get_stories', return_value=['one.story']) result = App.lex('/path') App.read_story.assert_called_with('one.story') Parser.lex.assert_called_with(App.read_story()) assert result == {'one.story': Parser.lex()}
def test_app_compile(patch): patch.object(json, 'dumps') patch.many(App, ['get_stories', 'parse', 'services']) result = App.compile('path') App.get_stories.assert_called_with('path') App.parse.assert_called_with(App.get_stories(), ebnf_file=None) App.services.assert_called_with(App.parse()) dictionary = {'stories': App.parse(), 'services': App.services()} json.dumps.assert_called_with(dictionary, indent=2) assert result == json.dumps()
def test_app_parse(patch, parser, read_story): """ Ensures App.parse runs Parser.parse """ patch.object(Compiler, 'compile') result = App.parse(['test.story']) App.read_story.assert_called_with('test.story') Parser.__init__.assert_called_with(ebnf_file=None) Parser().parse.assert_called_with(App.read_story()) Compiler.compile.assert_called_with(Parser().parse()) assert result == {'test.story': Compiler.compile()}
def test_cli_parse_json(runner, echo, app, option): """ Ensures --json outputs json """ runner.invoke(Cli.parse, ['/path', option]) App.compile.assert_called_with('/path', ebnf_file=None) click.echo.assert_called_with(App.compile())
def test_app_lexer(patch): patch.object(Story, 'from_file') patch.init(Bundle) patch.object(Bundle, 'find_stories', return_value=['one.story']) result = App.lex('/path') Story.from_file.assert_called_with('one.story') assert result == {'one.story': Story.from_file().lex()}
def test_app_get_stories_directory(mocker): """ Ensures App.get_stories returns stories in a directory """ mocker.patch.object(os.path, 'isdir') mocker.patch.object(os, 'walk', return_value=[('root', [], ['one.story', 'two'])]) assert App.get_stories('stories') == ['root/one.story']
def test_app_compile(patch): patch.object(json, 'dumps') patch.init(Bundle) patch.object(Bundle, 'bundle') result = App.compile('path') Bundle.__init__.assert_called_with('path') Bundle.bundle.assert_called_with(ebnf_file=None, debug=False) json.dumps.assert_called_with(Bundle.bundle(), indent=2) assert result == json.dumps()
def test_app_services_no_duplicates(): compiled_stories = {'a': {'services': ['one']}, 'b': {'services': ['one']}} result = App.services(compiled_stories) assert result == ['one']
def test_app_parse_ebnf_file(patch, parser, read_story): patch.object(Compiler, 'compile') App.parse(['test.story'], ebnf_file='test.ebnf') Parser.__init__.assert_called_with(ebnf_file='test.ebnf')
def test_app_get_stories(mocker): """ Ensures App.get_stories returns the original path if it's not a directory """ mocker.patch.object(os.path, 'isdir', return_value=False) assert App.get_stories('stories') == ['stories']
def test_app_read_story(story, storypath): """ Ensures App.read_story reads a story """ result = App.read_story(storypath) assert result == story
def test_app_grammar(patch): patch.init(Grammar) patch.object(Grammar, 'build') assert App.grammar() == Grammar().build()
def test_app_compile_ebnf_file(patch): patch.object(json, 'dumps') patch.many(App, ['get_stories', 'parse', 'services']) App.compile('path', ebnf_file='test.ebnf') App.parse.assert_called_with(App.get_stories(), ebnf_file='test.ebnf')
def test_app_compile_debug(patch): patch.object(json, 'dumps') patch.init(Bundle) patch.object(Bundle, 'bundle') App.compile('path', debug='debug') Bundle.bundle.assert_called_with(ebnf_file=None, debug='debug')
def test_app_compile_ebnf_file(patch): patch.object(json, 'dumps') patch.init(Bundle) patch.object(Bundle, 'bundle') App.compile('path', ebnf_file='ebnf') Bundle.bundle.assert_called_with(ebnf_file='ebnf', debug=False)