Exemplo n.º 1
0
def test_error_message(patch):
    patch.many(ErrorCodes, ['is_error', 'get_error'])
    e = CompilerError(None, message='test error')
    assert str(e) == 'test error'

    ErrorCodes.is_error.return_value = True
    ErrorCodes.get_error.return_value = [None, 'foo']
    e2 = CompilerError('my_custom_error')
    assert str(e2) == 'foo'

    ErrorCodes.is_error.return_value = False
    e3 = CompilerError(None)
    assert str(e3) == 'Unknown compiler error'
Exemplo n.º 2
0
def test_cli_compile_not_found(patch, runner, echo, app):
    """
    Ensures the compile command catches errors
    """
    ce = CompilerError(None)
    app.compile.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.compile, ['/a/non/existent/file'])
    assert e.exit_code == 1
    click.echo.assert_called_with(f'E0001: {StoryError._internal_error(ce)}')
Exemplo n.º 3
0
def test_cli_compile_not_found(runner, echo, app):
    """
    Ensures the compile command catches errors
    """
    ce = CompilerError(None, message='error')
    app.compile.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.compile, ['/a/non/existent/file'])
    assert e.exit_code == 1
    click.echo.assert_called_with('error')
Exemplo n.º 4
0
def test_cli_compile_not_found_debug(runner, echo, app):
    """
    Ensures the compile command raises errors with debug=True
    """
    ce = CompilerError(None)
    app.compile.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.compile, ['--debug', '/a/non/existent/file'])
    assert e.exit_code == 1
    assert isinstance(e.exception, CompilerError)
    assert e.exception.message() == 'Unknown compiler error'
Exemplo n.º 5
0
def test_cli_parse_not_found(runner, echo, app, patch):
    """
    Ensures the parse command catches errors
    """
    patch.object(StoryError, 'message')
    ce = CompilerError(None)
    app.parse.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.parse, ['/a/non/existent/file'])
    assert e.exit_code == 1
    click.echo.assert_called_with(StoryError.message())
Exemplo n.º 6
0
def test_cli_lex_not_found(patch, runner, echo, app):
    """
    Ensures the compile command catches errors
    """
    ce = CompilerError(None, message='error')
    patch.object(App, 'lex')
    App.lex.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.lex, ['/a/non/existent/file'])
    assert e.exit_code == 1
    click.echo.assert_called_with('error')
Exemplo n.º 7
0
def test_cli_format_not_found_debug(patch, runner, echo, app):
    """
    Ensures the format command raises errors with debug=True
    """
    ce = CompilerError(None)
    patch.object(App, 'format')
    App.format.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.format, ['--debug', '/a/non/existent/file'])
    assert e.exit_code == 1
    assert isinstance(e.exception, CompilerError)
    assert e.exception.message() == 'Unknown compiler error'
Exemplo n.º 8
0
def test_cli_format_not_found(patch, runner, echo, app):
    """
    Ensures the format command catches errors
    """
    patch.object(StoryError, 'message')
    ce = CompilerError(None)
    patch.object(App, 'format')
    App.format.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.format, ['/a/non/existent/file'])
    assert e.exit_code == 1
    click.echo.assert_called_with(StoryError.message())
Exemplo n.º 9
0
def test_cli_lex_not_found_debug(patch, runner, echo, app):
    """
    Ensures the compile command raises errors with debug=True
    """
    ce = CompilerError(None, message='error')
    patch.object(App, 'lex')
    App.lex.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.lex, ['--debug', '/a/non/existent/file'])
    assert e.exit_code == 1
    assert isinstance(e.exception, StoryError)
    assert e.exception.short_message() == 'E0001: error'
Exemplo n.º 10
0
def test_cli_parse_debug(runner, echo, app):
    """
    Ensures the parse command supports raises errors with debug=True
    """
    runner.invoke(Cli.parse, ['--debug'])
    ce = CompilerError(None, message='unexpected error')
    app.parse.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.parse, ['--debug', '/a/non/existent/file'])
    assert e.exit_code == 1
    assert isinstance(e.exception, StoryError)
    assert e.exception.short_message() == 'E0001: unexpected error'
Exemplo n.º 11
0
def test_cli_lex_not_found_debug(patch, runner, echo, app):
    """
    Ensures the lex command raises errors with debug=True
    """
    ce = CompilerError(None)
    patch.object(App, "lex")
    App.lex.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.lex, ["--debug", "/a/non/existent/file"])
    assert e.exit_code == 1
    assert isinstance(e.exception, CompilerError)
    assert e.exception.message() == "Unknown compiler error"
Exemplo n.º 12
0
def test_cli_lex_not_found(patch, runner, echo, app):
    """
    Ensures the lex command catches errors
    """
    patch.object(StoryError, "message")
    ce = CompilerError(None)
    patch.object(App, "lex")
    App.lex.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.lex, ["/a/non/existent/file"])
    assert e.exit_code == 1
    click.echo.assert_called_with(StoryError.message())
Exemplo n.º 13
0
def test_cli_parse_debug(runner, echo, app):
    """
    Ensures the parse command supports raises errors with debug=True
    """
    runner.invoke(Cli.parse, ["--debug"])
    ce = CompilerError(None)
    app.parse.side_effect = StoryError(ce, None)
    e = runner.invoke(Cli.parse, ["--debug", "/a/non/existent/file"])
    assert e.exit_code == 1
    assert isinstance(e.exception, CompilerError)
    assert e.exception.message() == "Unknown compiler error"
Exemplo n.º 14
0
def test_compiler_error_extra_parameters():
    e2 = CompilerError('my_custom_error', my_param='p1', my_param2='p2')
    assert e2.extra.my_param == 'p1'
    assert e2.extra.my_param2 == 'p2'