예제 #1
0
파일: App.py 프로젝트: nemani/storyscript
def test_app_compile_ebnf(patch, bundle):
    """
    Ensures App.compile supports specifying an ebnf file
    """
    patch.object(json, 'dumps')
    App.compile('path', ebnf='ebnf')
    Bundle.from_path().bundle.assert_called_with(ebnf='ebnf')
예제 #2
0
파일: App.py 프로젝트: nemani/storyscript
def test_app_compile(patch, bundle):
    patch.object(json, 'dumps')
    result = App.compile('path')
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    Bundle.from_path().bundle.assert_called_with(ebnf=None)
    json.dumps.assert_called_with(Bundle.from_path().bundle(), indent=2)
    assert result == json.dumps()
예제 #3
0
파일: App.py 프로젝트: nemani/storyscript
def test_app_parse(bundle):
    """
    Ensures App.parse returns the parsed bundle
    """
    result = App.parse('path')
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    Bundle.from_path().bundle_trees.assert_called_with(ebnf=None)
    assert result == Bundle.from_path().bundle_trees()
예제 #4
0
def test_app_compile_concise(patch, bundle):
    patch.object(json, 'dumps')
    patch.object(AppModule, '_clean_dict')
    result = App.compile('path', concise=True)
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    Bundle.from_path().bundle.assert_called_with(ebnf=None)
    AppModule._clean_dict.assert_called_with(Bundle.from_path().bundle())
    json.dumps.assert_called_with(AppModule._clean_dict(), indent=2)
    assert result == json.dumps()
예제 #5
0
def test_bundle_from_path_directory_ignored(patch):
    """
    Ensures Bundle.from_path accepts an ignored_path keyword argument
    """
    patch.object(os.path, 'isdir')
    patch.init(Bundle)
    patch.many(Bundle, ['load_story', 'parse_directory'])
    Bundle.from_path('path', ignored_path='ignored')
    Bundle.parse_directory.assert_called_with('path', ignored_path='ignored')
예제 #6
0
def test_bundle_from_path_directory_ignored(patch):
    """
    Ensures Bundle.from_path accepts an ignored_path keyword argument
    """
    patch.object(os.path, "isdir")
    patch.init(Bundle)
    patch.many(Bundle, ["load_story", "parse_directory"])
    Bundle.from_path("path", ignored_path="ignored")
    Bundle.parse_directory.assert_called_with("path", ignored_path="ignored")
예제 #7
0
def test_app_compile_first(patch, bundle):
    """
    Ensures that the App only returns the first story
    """
    Bundle.from_path().bundle.return_value = {'stories': {'my_story': 42}}
    patch.object(json, 'dumps')
    result = App.compile('path', first=True)
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    Bundle.from_path().bundle.assert_called_with(ebnf=None)
    json.dumps.assert_called_with(42, indent=2)
    assert result == json.dumps()
예제 #8
0
def test_app_parse_lower(patch, bundle, magic):
    """
    Ensures App.parse applies the loweror
    """
    story = magic()
    Bundle.from_path().bundle_trees.return_value = {'foo.story': story}
    result = App.parse('path', lower=True)
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    bt = Bundle.from_path().bundle_trees
    bt.assert_called_with(ebnf=None, lower=True)
    assert result == Bundle.from_path().bundle_trees(story)
예제 #9
0
def test_bundle_from_path_directory(patch):
    """
    Ensures Bundle.from_path can create a Bundle from a directory path
    """
    patch.object(os.path, 'isdir')
    patch.init(Bundle)
    patch.many(Bundle, ['load_story', 'parse_directory'])
    Bundle.parse_directory.return_value = ['one.story']
    Bundle.from_path('path')
    Bundle.parse_directory.assert_called_with('path', ignored_path=None)
    Bundle.load_story.assert_called_with('one.story')
예제 #10
0
def test_bundle_from_path_directory(patch):
    """
    Ensures Bundle.from_path can create a Bundle from a directory path
    """
    patch.object(os.path, "isdir")
    patch.init(Bundle)
    patch.many(Bundle, ["load_story", "parse_directory"])
    Bundle.parse_directory.return_value = ["one.story"]
    Bundle.from_path("path")
    Bundle.parse_directory.assert_called_with("path", ignored_path=None)
    Bundle.load_story.assert_called_with("one.story")
예제 #11
0
def test_app_parse_preprocess(patch, bundle, magic):
    """
    Ensures App.parse applies the preprocessor
    """
    patch.object(Preprocessor, 'process')
    story = magic()
    Bundle.from_path().bundle_trees.return_value = {'foo.story': story}
    result = App.parse('path', preprocess=True)
    assert Preprocessor.process.call_count == 1
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    Bundle.from_path().bundle_trees.assert_called_with(ebnf=None)
    assert result == {'foo.story': Preprocessor.process(story)}
예제 #12
0
def test_app_compile_first_error(patch, bundle):
    """
    Ensures that the App throws an error for --first with more than one story
    """
    Bundle.from_path().bundle.return_value = {'stories': {
        'my_story': 42, 'another_story': 43,
    }}
    patch.object(json, 'dumps')
    with raises(StoryError) as e:
        App.compile('path', first=True)
    assert e.value.message() == \
        'The option `--first`/-`f` can only be used if one story is complied.'
    Bundle.from_path.assert_called_with('path', ignored_path=None)
    Bundle.from_path().bundle.assert_called_with(ebnf=None)
예제 #13
0
def test_app_parse_ebnf(bundle):
    """
    Ensures App.parse supports specifying an ebnf
    """
    App.parse('path', ebnf='ebnf')
    bt = Bundle.from_path().bundle_trees
    bt.assert_called_with(ebnf='ebnf', lower=False)
예제 #14
0
def test_bundle_from_path(patch):
    """
    Ensures Bundle.from_path can create a Bundle from a filepath
    """
    patch.object(os.path, 'isdir', return_value=False)
    patch.init(Bundle)
    patch.object(Bundle, 'load_story')
    result = Bundle.from_path('path')
    Bundle.load_story.assert_called_with('path')
    assert isinstance(result, Bundle)
예제 #15
0
파일: App.py 프로젝트: nemani/storyscript
def test_app_lex_ebnf(bundle):
    App.lex('/path', ebnf='my.ebnf')
    Bundle.from_path().lex.assert_called_with(ebnf='my.ebnf')
예제 #16
0
파일: App.py 프로젝트: nemani/storyscript
def test_app_lex(bundle):
    result = App.lex('/path')
    Bundle.from_path.assert_called_with('/path')
    Bundle.from_path().lex.assert_called_with(ebnf=None)
    assert result == Bundle.from_path().lex()