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
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
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
def test_entity(): expected = { "entity": neon.entity.Entity("Column", { 0: "something", "type": "int" }) } assert neon.decode(NEON_ENTITY) == expected
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
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]
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]
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
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
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
def test_simple_list(): assert neon.decode(NEON_SIMPLE_LIST) == ["a", "b"]
def test_indented_list_dict(): assert neon.decode(NEON_INDENTED_LIST_OF_DICTS) == [{"a": "b"}]
def test_simple_dict(): assert neon.decode(NEON_SIMPLE_DICT) == {"a": "b", "c": "d"}
def test_unexpected_end(): with pytest.raises(errors.ParserError) as excinfo: neon.decode(NEON_UNEXPECTED_END) assert str(excinfo.value) == NEON_UNEXPECTED_END_MSG
def test_indented_comments(): assert neon.decode(NEON_INDENTED_COMMENTS) == {"root": ["aaa", "bbb"]}
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"}
def test_bad_indent(): with pytest.raises(errors.ParserError) as excinfo: neon.decode(NEON_BAD_INDENT) assert str(excinfo.value) == NEON_BAD_INDENT_MSG
def test_simple_list(): assert neon.decode(NEON_SIMPLE_LIST) == ['a', 'b']
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
def test_utf8_support(): expected = ["ěšíčťľĺ", "5 × 6 ÷ 7 ± ∞ - π"] assert neon.decode(NEON_UTF8_SUPPORT) == expected
def test_entity(): expected = {'entity': neon.entity.Entity( 'Column', {0: 'something', 'type': 'int'})} assert neon.decode(NEON_ENTITY) == expected
def test_decode_sample(): assert neon.decode(NEON_DECODE_SAMPLE)
def test_simple(): expected = {'a': [None, 'd'], 'b': {'e': None, 'g': 'h'}} assert neon.decode(NEON_SIMPLE) == expected
def test_list_of_dicts(): expected = [{'a': [{'b': False}]}, {'d': [1]}] assert neon.decode(NEON_LIST_OF_DICTS) == expected
def test_simple(): expected = {"a": [None, "d"], "b": {"e": None, "g": "h"}} assert neon.decode(NEON_SIMPLE) == expected
def test_simple_dict(): assert neon.decode(NEON_SIMPLE_DICT) == {'a': 'b', 'c': 'd'}
def test_list_of_dicts(): expected = [{"a": [{"b": False}]}, {"d": [1]}] assert neon.decode(NEON_LIST_OF_DICTS) == expected
def test_empty_data_structures(): expected = [{}, [], {}, neon.entity.Entity('Tree', {})] assert neon.decode(NEON_EMPTY_DATA_STRUCTURES) == expected
def test_empty_data_structures(): expected = [{}, [], {}, neon.entity.Entity("Tree", {})] assert neon.decode(NEON_EMPTY_DATA_STRUCTURES) == expected
def test_utf8_support(): expected = ['ěšíčťľĺ', '5 × 6 ÷ 7 ± ∞ - π'] assert neon.decode(NEON_UTF8_SUPPORT) == expected