Ejemplo n.º 1
0
def test_api_load_map_compiling_try_block():
    """
    Ensures Api.load functions return errors
    """
    files = {'asd': 'foo'}
    with raises(StoryError) as e:
        Api.load_map(files)
    assert e.value.short_message() == 'E0040: No operator provided'
Ejemplo n.º 2
0
def test_api_load_map_compiling_try_block():
    """
    Ensures Api.load_map functions return errors
    """
    files = {"asd": "foo ="}
    with raises(StoryError) as e:
        Api.load_map(files).check_success()
    assert e.value.short_message() == "E0007: Missing value after `=`"
Ejemplo n.º 3
0
def test_api_load_map_compiling_try_block():
    """
    Ensures Api.load functions return errors
    """
    files = {'asd': 'foo ='}
    with raises(StoryError) as e:
        Api.load_map(files)
    assert e.value.short_message() == 'E0007: Missing value after `=`'
Ejemplo n.º 4
0
def test_api_load_map_ice():
    """
    Simulate an ICE during load_map
    """
    with patch.object(Bundle, 'bundle') as p:
        p.side_effect = Exception('ICE')
        with raises(StoryError) as e:
            Api.load_map({})
        assert e.value.message() == \
            """Internal error occured: ICE
Ejemplo n.º 5
0
def test_api_load_map_syntax_error():
    """
    Ensures Api.load functions return errors
    """
    files = {'asd': 'foo ='}
    with raises(StoryError) as e:
        Api.load_map(files)
    assert e.value.short_message() == 'E0007: Missing value after `=`'
    e.value.with_color = False
    assert e.value.message() == \
        """Error: syntax error in story at line 1, column 6
Ejemplo n.º 6
0
def test_api_load_map_internal_error_debug(patch):
    """
    Ensures Api.loads handles unknown errors with debug=True
    """
    patch.init(Bundle)
    patch.object(Bundle, "bundle")
    patch.object(StoryError, "internal_error")
    StoryError.internal_error.return_value = Exception("ICE")
    Bundle.bundle.side_effect = Exception("An unknown error.")
    with raises(Exception) as e:
        Api.load_map({}, features={"debug": True}).check_success()

    assert str(e.value) == "An unknown error."
Ejemplo n.º 7
0
def test_api_load_map_internal_error_debug(patch):
    """
    Ensures Api.loads handles unknown errors with debug=True
    """
    patch.init(Bundle)
    patch.object(Bundle, 'bundle')
    patch.object(StoryError, 'internal_error')
    StoryError.internal_error.return_value = Exception('ICE')
    Bundle.bundle.side_effect = Exception('An unknown error.')
    with raises(Exception) as e:
        Api.load_map({}, features={'debug': True}).check_success()

    assert str(e.value) == 'An unknown error.'
Ejemplo n.º 8
0
def test_api_load_map_internal_error(patch):
    """
    Ensures Api.loads handles unknown errors
    """
    patch.init(Bundle)
    patch.object(Bundle, 'bundle')
    patch.object(StoryError, 'internal_error')
    StoryError.internal_error.return_value = Exception('ICE')
    Bundle.bundle.side_effect = Exception('An unknown error.')
    with raises(Exception) as e:
        Api.load_map({})

    assert str(e.value) == 'ICE'
Ejemplo n.º 9
0
def test_api_load_map_ice():
    """
    Simulate an ICE during load_map
    """
    with patch.object(Bundle, "bundle") as p:
        p.side_effect = Exception("ICE")
        s = Api.load_map({})
        e = s.errors()[0]
        assert (e.message() == """E0001: Internal error occured: ICE
Please report at https://github.com/storyscript/storyscript/issues""")
Ejemplo n.º 10
0
def test_api_load_map_ice():
    """
    Simulate an ICE during load_map
    """
    with patch.object(Bundle, 'bundle') as p:
        p.side_effect = Exception('ICE')
        s = Api.load_map({})
        e = s.errors()[0]
        assert e.message() == \
            """Internal error occured: ICE
Ejemplo n.º 11
0
def test_api_load_map(patch, magic):
    """
    Ensures Api.load_map can compile stories from a map
    """
    patch.init(Bundle)
    patch.object(Bundle, 'bundle')
    files = {'a.story': "import 'b' as b", 'b.story': 'x = 0'}
    result = Api.load_map(files).result()
    Bundle.__init__.assert_called_with(story_files=files)
    Bundle.bundle.assert_called()
    assert result == Bundle.bundle()
Ejemplo n.º 12
0
def test_api_load_map_syntax_error():
    """
    Ensures Api.load functions return errors
    """
    files = {'abc.story': 'foo ='}
    s = Api.load_map(files)
    e = s.errors()[0]
    assert e.short_message() == 'E0007: Missing value after `=`'
    e.with_color = False
    assert e.message() == \
        """Error: syntax error in abc.story at line 1, column 6
Ejemplo n.º 13
0
def test_api_load_map_internal_error(patch):
    """
    Ensures Api.loads handles unknown errors
    """
    patch.init(Bundle)
    patch.object(Bundle, "bundle")
    patch.object(StoryError, "internal_error")
    StoryError.internal_error.return_value = Exception("ICE")
    Bundle.bundle.side_effect = Exception("An unknown error.")
    s = Api.load_map({})
    e = s.errors()[0]

    assert str(e) == "ICE"
Ejemplo n.º 14
0
def test_api_load_map_syntax_error():
    """
    Ensures Api.load_map functions return errors
    """
    files = {"abc.story": "foo ="}
    s = Api.load_map(files)
    e = s.errors()[0]
    assert e.short_message() == "E0007: Missing value after `=`"
    e.with_color = False
    assert (
        e.message() == """Error: syntax error in abc.story at line 1, column 6

1|    foo =
           ^

E0007: Missing value after `=`""")
Ejemplo n.º 15
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
Ejemplo n.º 16
0
def test_compiler_only_comments():
    api_result = Api.load_map({"a.story": "# foo\n"}).result()
    result = api_result["stories"]["a.story"]
    assert result["tree"] == {}
    assert result["entrypoint"] is None
Ejemplo n.º 17
0
def test_compiler_only_comments():
    api_result = Api.load_map({'a.story': '# foo\n'}).result()
    result = api_result['stories']['a.story']
    assert result['tree'] == {}
    assert result['entrypoint'] is None