Exemplo n.º 1
0
def test_error_colons():
    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_ERROR_COLON1)
    assert str(excinfo.value) == NEON_ERROR_COLON1_MSG

    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_ERROR_COLON2)
    assert str(excinfo.value) == NEON_ERROR_COLON2_MSG
Exemplo n.º 2
0
def test_error_colons():
    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_ERROR_COLON1)
    assert str(excinfo.value) == NEON_ERROR_COLON1_MSG

    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_ERROR_COLON2)
    assert str(excinfo.value) == NEON_ERROR_COLON2_MSG
Exemplo n.º 3
0
def test_datetime():
    expected = [
        datetime(2013, 4, 23, 13, 24, 55, 123456, tzinfo=tz.tzutc()),
        datetime(2015, 1, 20),
        datetime(2015, 5, 10),
    ]
    assert neon.decode(NEON_DATETIME) == expected
Exemplo n.º 4
0
def test_data_structures():
    expected = {
        'list': [1, 'a', ['v', True]],
        'dict1': {'a': 5, 'b': {1: [True]}},
        'dict2': {'d': 8, 'e': {None: False}},
    }
    assert neon.decode(NEON_DATA_STRUCTURES) == expected
Exemplo n.º 5
0
def test_entity():
    expected = {
        "entity": neon.entity.Entity("Column", {
            0: "something",
            "type": "int"
        })
    }
    assert neon.decode(NEON_ENTITY) == expected
Exemplo n.º 6
0
def load_config(path_to_neon):
    """
    load configuration from local 'neon' file

    :param path_to_neon: path to neon file with configuration
    :return: dict of values
    """
    with open(path_to_neon, 'r') as fd:
        config = neon.decode(fd.read())
    # print("Load config file...")
    return config
Exemplo n.º 7
0
def test_types():
    expected = {
        'string': 'a () #\' text',
        'integer': 5902,
        'hexint': 0xAA,
        'float': 5.234,
        'floatbig': 5e10,
        'nones': [None] * 3,
        'bools': [True] * 9 + [False] * 9,
    }
    result = neon.decode(NEON_TYPES)
    for key in expected:
        assert result[key] == expected[key]
Exemplo n.º 8
0
def test_types():
    expected = {
        "string": "a () #' text",
        "integer": 5902,
        "hexint": 0xAA,
        "octint": 0o666,
        "binint": 0b111000111,
        "float": 5.234,
        "floatbig": 5e10,
        "nones": [None] * 3,
        "bools": [True] * 9 + [False] * 9,
    }
    result = neon.decode(NEON_TYPES)
    for key in expected:
        assert result[key] == expected[key]
Exemplo n.º 9
0
def test_data_structures():
    expected = {
        "list": [1, "a", ["v", True]],
        "dict1": {
            "a": 5,
            "b": {
                1: [True]
            }
        },
        "dict2": {
            "d": 8,
            "e": {
                None: False
            }
        },
    }
    assert neon.decode(NEON_DATA_STRUCTURES) == expected
Exemplo n.º 10
0
def main():
    story_file_path = get_arg(1)

    if not story_file_path:
        sp("Story file not provided.")
        return

    elif not path.isfile(story_file_path):
        sp(f"File '{story_file_path}' not found.")
        return

    sp(f"Loading story file {story_file_path} ...")

    with open(story_file_path, "r") as file:
        try:
            story_data = neon.decode(file.read())
        except Exception:
            sp("There was an error when decoding story file.")
            return
Exemplo n.º 11
0
def test_decode_sample():
    expected = {
        "name":
        "Homer",
        "address": {
            "street": "742 Evergreen Terrace",
            "city": "Springfield",
            "country": ["a"],
            "whatever": ["b"],
        },
        "phones": {
            "home": "555-6528",
            "work": {
                "asdf": "555-7334",
                "wtf": 1234,
            },
        },
        "whoa": ["a", "b", "c", 100000.0, 34,
                 datetime(2014, 1, 1, 0, 0)],
        "children": [
            "Bart",
            "Lisa",
            "Maggie",
            {
                "type": "whatever",
                "wtf": {
                    "wtf": 5
                },
            },
        ],
        "entity":
        neon.entity.Entity("Column", {"type": "integer"}),
        "special":
        "#characters put in quotes",
    }
    assert neon.decode(NEON_DECODE_SAMPLE) == expected
Exemplo n.º 12
0
def test_simple_list():
    assert neon.decode(NEON_SIMPLE_LIST) == ["a", "b"]
Exemplo n.º 13
0
def test_indented_list_dict():
    assert neon.decode(NEON_INDENTED_LIST_OF_DICTS) == [{"a": "b"}]
Exemplo n.º 14
0
def test_simple_dict():
    assert neon.decode(NEON_SIMPLE_DICT) == {"a": "b", "c": "d"}
Exemplo n.º 15
0
def test_unexpected_end():
    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_UNEXPECTED_END)
    assert str(excinfo.value) == NEON_UNEXPECTED_END_MSG
Exemplo n.º 16
0
def test_indented_comments():
    assert neon.decode(NEON_INDENTED_COMMENTS) == {"root": ["aaa", "bbb"]}
Exemplo n.º 17
0
def test_string_escaping():
    assert neon.decode('key: "msg"') == {"key": "msg"}
    assert neon.decode('key: "msg \\" end"') == {"key": 'msg " end'}
    assert neon.decode("key: 'msg \\' end'") == {"key": "msg ' end"}
    assert neon.decode('src: "\\\\usr\\\\share"') == {"src": "\\usr\\share"}
Exemplo n.º 18
0
def test_bad_indent():
    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_BAD_INDENT)
    assert str(excinfo.value) == NEON_BAD_INDENT_MSG
Exemplo n.º 19
0
def test_simple_list():
    assert neon.decode(NEON_SIMPLE_LIST) == ['a', 'b']
Exemplo n.º 20
0
def test_datetime():
    expected = [datetime(2013, 4, 23, 13, 24, 55, 123456, tzinfo=tz.tzutc()),
                datetime(2015, 1, 20),
                datetime(2015, 5, 10)]
    assert neon.decode(NEON_DATETIME) == expected
Exemplo n.º 21
0
def test_utf8_support():
    expected = ["ěšíčťľĺ", "5 × 6 ÷ 7 ± ∞ - π"]
    assert neon.decode(NEON_UTF8_SUPPORT) == expected
Exemplo n.º 22
0
def test_entity():
    expected = {'entity': neon.entity.Entity(
        'Column', {0: 'something', 'type': 'int'})}
    assert neon.decode(NEON_ENTITY) == expected
Exemplo n.º 23
0
def test_decode_sample():
    assert neon.decode(NEON_DECODE_SAMPLE)
Exemplo n.º 24
0
def test_simple():
    expected = {'a': [None, 'd'], 'b': {'e': None, 'g': 'h'}}
    assert neon.decode(NEON_SIMPLE) == expected
Exemplo n.º 25
0
def test_list_of_dicts():
    expected = [{'a': [{'b': False}]}, {'d': [1]}]
    assert neon.decode(NEON_LIST_OF_DICTS) == expected
Exemplo n.º 26
0
def test_simple():
    expected = {"a": [None, "d"], "b": {"e": None, "g": "h"}}
    assert neon.decode(NEON_SIMPLE) == expected
Exemplo n.º 27
0
def test_simple_dict():
    assert neon.decode(NEON_SIMPLE_DICT) == {'a': 'b', 'c': 'd'}
Exemplo n.º 28
0
def test_list_of_dicts():
    expected = [{"a": [{"b": False}]}, {"d": [1]}]
    assert neon.decode(NEON_LIST_OF_DICTS) == expected
Exemplo n.º 29
0
def test_empty_data_structures():
    expected = [{}, [], {}, neon.entity.Entity('Tree', {})]
    assert neon.decode(NEON_EMPTY_DATA_STRUCTURES) == expected
Exemplo n.º 30
0
def test_empty_data_structures():
    expected = [{}, [], {}, neon.entity.Entity("Tree", {})]
    assert neon.decode(NEON_EMPTY_DATA_STRUCTURES) == expected
Exemplo n.º 31
0
def test_bad_indent():
    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_BAD_INDENT)
    assert str(excinfo.value) == NEON_BAD_INDENT_MSG
Exemplo n.º 32
0
def test_utf8_support():
    expected = ['ěšíčťľĺ', '5 × 6 ÷ 7 ± ∞ - π']
    assert neon.decode(NEON_UTF8_SUPPORT) == expected
Exemplo n.º 33
0
def test_unexpected_end():
    with pytest.raises(errors.ParserError) as excinfo:
        neon.decode(NEON_UNEXPECTED_END)
    assert str(excinfo.value) == NEON_UNEXPECTED_END_MSG