Example #1
0
def test_parse_output_invalid_cast(story):
    command_conf = {
        'output': {
            'type': 'int'
        }
    }

    with pytest.raises(StoryscriptError):
        Services.parse_output(command_conf, 'not_an_int', story, {}, '')
Example #2
0
def test_parse_output_invalid_type(story):
    command_conf = {
        'output': {
            'type': 'foo'
        }
    }

    with pytest.raises(StoryscriptError):
        Services.parse_output(command_conf, 'blah', story, {}, '')
Example #3
0
def test_parse_output(output_type, story):
    line = {}
    command_conf = {
        'output': {
            'type': output_type
        }
    }

    expected_output = None
    actual_input = None

    if output_type == 'string':
        actual_input = 'hello'
        expected_output = 'hello'
    elif output_type == 'int':
        actual_input = b'10'
        expected_output = 10
    elif output_type == 'float':
        actual_input = b'7.0'
        expected_output = 7.0
    elif output_type == 'boolean':
        actual_input = f'true'
        expected_output = True
    elif output_type is None:
        actual_input = None
        expected_output = None
    elif output_type == 'any':
        actual_input = b'empty'
        expected_output = b'empty'

    assert Services.parse_output(
        command_conf, actual_input, story, line, '') == expected_output