async def test_if_condition_2(patch, logger, magic):
    tree = {
        '1': {
            'ln': '1',
            'method': 'if',
            'enter': '2',
            'next': '2'
        },
        '2': {
            'ln': '2',
            'parent': '1',
            'next': '3'
        },
        '3': {
            'ln': '3',
            'next': None,
            'method': 'execute'
        }
    }

    patch.object(Lexicon, '_is_if_condition_true', return_value=False)
    story = Stories(magic(), 'foo', logger)

    story.tree = tree
    ret = await Lexicon.if_condition(logger, story, tree['1'])
    assert ret == '3'
Beispiel #2
0
def story(app, logger):
    asset_dir = examples.__path__[0]

    with open(asset_dir + '/stories.json', 'r') as file:
        app.stories = ujson.loads(file.read())['stories']

    return Stories(app, 'hello.story', logger)
async def test_if_condition(patch, logger, magic, case):
    tree = {
        '1': {
            'ln': '1',
            'method': 'if',
            'parent': None,
            'enter': '2',
            'next': '2'
        },
        '2': {
            'ln': '2',
            'parent': '1',
            'next': '3'
        },
        '3': {
            'ln': '3',
            'method': 'elif',
            'parent': None,
            'enter': '4',
            'next': '4'
        },
        '4': {
            'ln': '4',
            'parent': '3',
            'next': '5'
        },
        '5': {
            'ln': '5',
            'method': 'elif',
            'parent': None,
            'enter': '6',
            'next': '6'
        },
        '6': {
            'ln': '6',
            'parent': '5',
            'next': '7'
        },
        '7': {
            'ln': '7',
            'method': 'else',
            'parent': None,
            'next': '8',
            'enter': '8'
        },
        '8': {
            'ln': '8',
            'parent': '7',
            'next': None
        }
    }

    patch.object(Lexicon, '_is_if_condition_true', side_effect=case[0])
    story = Stories(magic(), 'foo', logger)

    story.tree = tree
    ret = await Lexicon.if_condition(logger, story, tree['1'])
    assert ret == case[1]
Beispiel #4
0
    story = storyscript.Api.loads(all_lines, features={'globals': True})
    errors = story.errors()
    if len(errors) > 0:
        print(f'Failed to compile the following story:'
              f'\n\n{all_lines}',
              file=sys.stderr)
        raise errors[0]

    app = MagicMock()

    app.stories = {story_name: story.result()}
    app.environment = {}

    context = {}

    story = Stories(app, story_name, logger)
    story.prepare(context)
    try:
        await Story.execute(logger, story)
    except StoryscriptError as e:
        try:
            assert isinstance(case.assertion, RuntimeExceptionAssertion)
            case.assertion.verify(e)
        except BaseException as e:
            print(
                f'Failed to assert exception for the following story:'
                f'\n\n{all_lines}',
                file=sys.stderr)
            raise e
        return
    except BaseException as e:
Beispiel #5
0
def story(app, logger):
    return Stories(app, 'hello.story', logger)