Exemplo n.º 1
0
def test_bundle_bundle_trees_ebnf(patch, bundle):
    patch.many(Bundle, ['find_stories', 'parse', 'parser'])
    bundle.bundle_trees(ebnf='ebnf')
    Bundle.parser.assert_called_with('ebnf')
    Bundle.parse.assert_called_with(Bundle.find_stories(),
                                    parser=Bundle.parser(),
                                    lower=False)
Exemplo n.º 2
0
def test_bundle_bundle_trees_ebnf(patch, bundle):
    patch.many(Bundle, ["find_stories", "parse", "parser"])
    bundle.bundle_trees(ebnf="ebnf")
    Bundle.parser.assert_called_with("ebnf")
    Bundle.parse.assert_called_with(Bundle.find_stories(),
                                    parser=Bundle.parser(),
                                    lower=False)
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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')
Exemplo n.º 5
0
def test_bundle_bundle_trees(patch, bundle):
    patch.many(Bundle, ['find_stories', 'parse', 'parser'])
    result = bundle.bundle_trees()
    Bundle.parser.assert_called_with(None)
    Bundle.parse.assert_called_with(Bundle.find_stories(),
                                    parser=Bundle.parser(),
                                    lower=False)
    assert result == bundle.stories
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
 def parse():
     files = request.json['files']
     bundle = Bundle(story_files=files)
     bundle.parse(bundle.find_stories(), ebnf=None)
     resp = {}
     for k, v in bundle.stories.items():
         resp[k] = lark_tree(v)
     return jsonify(resp)
Exemplo n.º 8
0
def test_bundle_bundle_lower(patch, bundle, magic):
    patch.many(Bundle, ["find_stories", "parse", "parser"])
    a_story = magic()
    bundle.stories = {"foo": a_story}
    bundle.bundle_trees(ebnf="ebnf", lower=True)
    Bundle.parser.assert_called_with("ebnf")
    Bundle.parse.assert_called_with(Bundle.find_stories(),
                                    parser=Bundle.parser(),
                                    lower=True)
Exemplo n.º 9
0
def test_bundle_bundle(patch, bundle):
    patch.many(Bundle, ['find_stories', 'services', 'compile', 'parser'])
    result = bundle.bundle()
    Bundle.parser.assert_called_with(None)
    Bundle.compile.assert_called_with(Bundle.find_stories(),
                                      parser=Bundle.parser())
    expected = {'stories': bundle.stories, 'services': Bundle.services(),
                'entrypoint': Bundle.find_stories()}
    assert result == expected
Exemplo n.º 10
0
def test_bundle_bundle_lower(patch, bundle, magic):
    patch.many(Bundle, ['find_stories', 'parse', 'parser'])
    a_story = magic()
    bundle.stories = {'foo': a_story}
    bundle.bundle_trees(ebnf='ebnf', lower=True)
    Bundle.parser.assert_called_with('ebnf')
    Bundle.parse.assert_called_with(Bundle.find_stories(),
                                    parser=Bundle.parser(),
                                    lower=True)
Exemplo n.º 11
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')
Exemplo n.º 12
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()
Exemplo n.º 13
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")
Exemplo n.º 14
0
def test_bundle_parse_directory_ignored_path(patch, bundle):
    patch.object(
        os,
        "walk",
        return_value=[(os.path.join(".", "root"), [], ["one.story"])],
    )
    patch.many(Bundle, ["gitignores", "ignores"])
    Bundle.gitignores.return_value = []
    Bundle.parse_directory("dir", ignored_path="ignored")
    Bundle.ignores.assert_called_with("ignored")
Exemplo n.º 15
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')
Exemplo n.º 16
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)
Exemplo n.º 17
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")
Exemplo n.º 18
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()
Exemplo n.º 19
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)}
Exemplo n.º 20
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)
Exemplo n.º 21
0
def test_bundle_bundle(patch, bundle):
    patch.many(Bundle, ["find_stories", "services", "compile", "parser"])
    result = bundle.bundle()
    Bundle.parser.assert_called_with(None)
    Bundle.compile.assert_called_with(Bundle.find_stories(),
                                      parser=Bundle.parser())
    expected = (
        {
            "stories": bundle.stories,
            "services": Bundle.services(),
            "entrypoint": Bundle.find_stories(),
        },
        bundle.deprecations,
    )
    assert result == expected
Exemplo n.º 22
0
def test_bundle_parse(patch, bundle):
    parse = bundle.parse
    patch.many(Bundle, ['parse', 'load_story'])
    parse(['one.story'], None, lower=False)
    Bundle.load_story.assert_called_with('one.story')
    story = Bundle.load_story()
    assert bundle.stories['one.story'] == story.tree
Exemplo n.º 23
0
def test_bundle_filter_path_ignores():
    result = Bundle.filter_path(
        os.path.join(".", "root"),
        "one.story",
        [os.path.join("root", "one.story")],
    )
    assert result is None
Exemplo n.º 24
0
def test_bundle_parse(patch, bundle):
    parse = bundle.parse
    patch.many(Bundle, ["parse", "load_story"])
    parse(["one.story"], None, lower=False)
    Bundle.load_story.assert_called_with("one.story")
    story = Bundle.load_story()
    assert bundle.stories["one.story"] == story.tree
Exemplo n.º 25
0
def test_bundle_parse(patch, bundle):
    patch.many(Bundle, ['parse_modules', 'load_story'])
    bundle.parse(['one.story'], None)
    Bundle.load_story.assert_called_with('one.story')
    story = Bundle.load_story()
    Bundle.parse_modules.assert_called_with(story.modules(), None)
    assert bundle.stories['one.story'] == story.tree
Exemplo n.º 26
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)
Exemplo n.º 27
0
def test_bundle_gitignores_command_not_found_oserror(patch):
    """
    Test what happens when executing the git command failed.
    """
    patch.object(subprocess, 'run', side_effect=OSError())
    result = Bundle.gitignores()
    assert result == []
Exemplo n.º 28
0
def test_bundle_gitignores_command_not_found(patch):
    """
    Test what happens when there's no git command available.
    """
    patch.object(subprocess, 'run', side_effect=FileNotFoundError())
    result = Bundle.gitignores()
    assert result == []
Exemplo n.º 29
0
def test_api_load_map(patch, magic):
    """
    Ensures Api.load_map can compile stories from a map
    """
    patch.init(Bundle)
    patch.init(Features)
    patch.object(Bundle, "bundle")
    files = {"a.story": "import 'b' as b", "b.story": "x = 0"}
    api_loaded = Api.load_map(files)
    result = api_loaded.result()
    deprecations = api_loaded.deprecations()
    Bundle.__init__.assert_called_with(story_files=files, features=ANY)
    assert isinstance(Bundle.__init__.call_args[1]["features"], Features)
    Bundle.bundle.assert_called()
    assert result == Bundle.bundle().results
    assert deprecations == Bundle.bundle().deprecations
Exemplo n.º 30
0
def test_bundle_parse_directory_gitignored(patch, bundle):
    """
    Ensures parse_directory does not return gitignored files
    """
    patch.object(os, 'walk', return_value=[('./root', [], ['one.story'])])
    patch.object(Bundle, 'gitignores')
    Bundle.gitignores.return_value = ['root/one.story']
    assert Bundle.parse_directory('dir') == []