示例#1
0
def test_api_load_ice():
    """
    Simulate an ICE during load
    """
    with patch.object(Story, 'from_stream') as p:
        p.side_effect = Exception('ICE')
        with raises(StoryError) as e:
            Api.load('foo')
        assert e.value.message() == \
            """Internal error occured: ICE
示例#2
0
def test_api_load_internal_error_debug(patch, magic):
    """
    Ensures Api.load handles unknown errors with debug=True
    """
    patch.init(Story)
    patch.object(Story, "from_stream")
    patch.object(StoryError, "internal_error")
    StoryError.internal_error.return_value = Exception("ICE")
    Story.from_stream.side_effect = Exception("An unknown error.")
    stream = magic()
    with raises(Exception) as e:
        Api.load(stream, features={"debug": True}).check_success()

    assert str(e.value) == "An unknown error."
示例#3
0
def test_api_load_internal_error_debug(patch, magic):
    """
    Ensures Api.load handles unknown errors with debug=True
    """
    patch.init(Story)
    patch.object(Story, 'from_stream')
    patch.object(StoryError, 'internal_error')
    StoryError.internal_error.return_value = Exception('ICE')
    Story.from_stream.side_effect = Exception('An unknown error.')
    stream = magic()
    with raises(Exception) as e:
        Api.load(stream, debug=True).check_success()

    assert str(e.value) == 'An unknown error.'
示例#4
0
def test_api_load_ice():
    """
    Simulate an ICE during load
    """
    with patch.object(Story, "from_stream") as p:
        p.side_effect = Exception("ICE")
        s = Api.load("foo")
        e = s.errors()[0]
        assert (e.message() == """E0001: Internal error occured: ICE
Please report at https://github.com/storyscript/storyscript/issues""")
示例#5
0
def test_api_load_ice():
    """
    Simulate an ICE during load
    """
    with patch.object(Story, 'from_stream') as p:
        p.side_effect = Exception('ICE')
        s = Api.load('foo')
        e = s.errors()[0]
        assert e.message() == \
            """Internal error occured: ICE
示例#6
0
def test_api_load(patch, magic):
    """
    Ensures Api.load can compile stories from a file stream
    """
    patch.object(Story, 'from_stream')
    stream = magic()
    result = Api.load(stream).result()
    Story.from_stream.assert_called_with(stream)
    Story.from_stream().process.assert_called()
    story = Story.from_stream().process()
    assert result == {stream.name: story, 'services': story['services']}
示例#7
0
def test_api_load_story_error(patch, magic):
    """
    Ensures Api.loads handles unknown errors
    """
    patch.init(Story)
    patch.object(Story, "from_stream")
    Story.from_stream.side_effect = StoryError.internal_error(".error.")
    stream = magic()
    s = Api.load(stream)
    e = s.errors()[0]

    assert e.message().startswith("E0001: Internal error occured: .error.")
示例#8
0
def test_api_load(patch, magic):
    """
    Ensures Api.load can compile stories from a file stream
    """
    patch.init(Features)
    patch.object(Story, "from_stream")
    stream = magic()
    result = Api.load(stream).result()
    Story.from_stream.assert_called_with(stream, ANY)
    assert isinstance(Story.from_stream.call_args[0][1], Features)
    Story.from_stream().process.assert_called()
    story = Story.from_stream().process()
    assert result == {stream.name: story, "services": story["services"]}
示例#9
0
def test_api_load_internal_error(patch, magic):
    """
    Ensures Api.loads handles unknown errors
    """
    patch.init(Story)
    patch.object(Story, "from_stream")
    patch.object(StoryError, "internal_error")
    StoryError.internal_error.return_value = Exception("ICE")
    Story.from_stream.side_effect = Exception("An unknown error.")
    stream = magic()
    s = Api.load(stream)
    e = s.errors()[0]

    assert str(e) == "ICE"