コード例 #1
0
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'
コード例 #2
0
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]