def test__parse_a_regular_dict_to_lconf2(): """ Tests: test__parse_a_regular_dict_to_lconf2 """ print('::: TEST: test__parse_a_regular_dict_to_lconf2()') example_dict = { '___SECTION': 'PERMISSIONS', 'description': 'A trivial terminal emulator', 'maintainer': 'Timothy Hobbs < (at) dot cz>', 'last_update_time': '2014_02_12_12:59', 'dependency': 'libx11', 'executable': '/usr/bin/xterm', 'x11': [123.0, 123], 'sound_card': False, 'inherit_working_directory': None, '___END': None } result_dict_to_lconf_str = lconf_dict_to_lconf(example_dict, 'PERMISSIONS', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(example_dict, 'PERMISSIONS', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf11(): """ Tests: test__parse_a_regular_nested_dict_to_lconf11 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf11()') nested_dict = {"empty_list": [], "normal_list": [1, 2, 3]} result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf2(): """ Tests: test__parse_a_regular_nested_dict_to_lconf2 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf2()') nested_dict = { "first": "John", "last": "Doe", "age": 39, "interests": ["Reading", "Mountain Biking", "Hacking"], "registered": 'true', "salary": 70000, "sex": "M" } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 2', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 2', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf3(): """ Tests: test__parse_a_regular_nested_dict_to_lconf3 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf3()') nested_dict = { "first": "John", "last": "Doe", "sex": "M", "age": 39, "salary": 70000, "favorites": { "food": "Spaghetti", "sport": "Soccer", "color": "Blue" }, "registered": 'true' } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 3', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 3', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf1(): """ Tests: test__parse_a_regular_nested_dict_to_lconf1 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf1()') nested_dict = { "description": "A trivial terminal emulator", "maintainer": "Timothy Hobbs < (at) dot cz>", "last_update_time": "2014_02_12_12:59", "dependency": "libx11", "executable": "/usr/bin/xterm", "x11": [ 123.0, 123 ], "sound_card": False, "inherit_working_directory": None, "allow_network_access": True, "test_mapping": { "test_mapping_key1": None, "test_mapping_key2": 234, "test_mapping_key3": 'value', "test_mapping_key4": '', } } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_('- x11 :: 123.0,123' in section_lines, msg=None) ok_(' test_mapping_key1 ::' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_('- x11' in section_lines, msg=None) ok_(' test_mapping_key1 ::' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=True, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_('- x11 :: 123.0,123' in section_lines, msg=None) ok_(' test_mapping_key1 :: None' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=False, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_('- x11' in section_lines, msg=None) ok_(' test_mapping_key1 :: None' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None)
def test__parse_a_regular_nested_dict_to_lconf4(): """ Tests: test__parse_a_regular_nested_dict_to_lconf4 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf4()') nested_dict = { "registered_employees": 28594, "Employee": { "Person1": { "first": "John", "last": "Doe", "sex": "M", "age": "39", "past_salary": { "year2012": 45000, "year2013": 62000 }, "emails": [ "<*****@*****.**>", "<*****@*****.**>" ] } }, "registered_customer": 28594, "accounting": [ [ "2010", 38459845, 15835945, 3000945 ], [ "2011", 38459845, 15835945, 3000945 ], [ "2012", 28456849, 4846123, 2599901 ], [ "2013", 38459845, 15835945, 3000945 ] ] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 4', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 4', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_dict_to_lconf_wrong_list_itemtype_expect_failure(): """ Tests: test__parse_a_dict_to_lconf_wrong_list_itemtype_expect_failure """ print( '::: TEST: test__parse_a_dict_to_lconf_wrong_list_itemtype_expect_failure()' ) nested_dict = { "skills": [{ "category": "PHP", "tests": [{ "score": 90, "name": "One" }, { "score": 96, "name": "Two" }] }, { "category": "Node.js", "tests": [{ "score": 97, "name": "One" }, { "score": 93, "name": "Two" }] }] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=True)
def test__parse_a_regular_nested_dict_to_lconf10_expect_failure(): """ Tests: test__parse_a_regular_nested_dict_to_lconf10_expect_failure """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf10_expect_failure()') nested_dict = { "accounting": [ [ "2010", 38459845, 15835945, 3000945 ], [ "2011", 38459845, 15835945, 3000945 ], [ "2012", 28456849, 4846123, 2599901 ], [ "2013", 38459845, ] ] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_dict_to_lconf1(): """ Tests: test__parse_a_regular_dict_to_lconf1 """ print('::: TEST: test__parse_a_regular_dict_to_lconf1()') example_dict = { 'description': 'A trivial terminal emulator', 'maintainer': 'Timothy Hobbs < (at) dot cz>', 'last_update_time': '2014_02_12_12:59', 'dependency': 'libx11', 'executable': '/usr/bin/xterm', 'x11': [123.0, 123], 'sound_card': False, 'inherit_working_directory': None } result_dict_to_lconf_str = lconf_dict_to_lconf(example_dict, 'PERMISSIONS', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(example_dict, 'PERMISSIONS', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf11(): """ Tests: test__parse_a_regular_nested_dict_to_lconf11 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf11()') nested_dict = { "empty_list": [], "normal_list": [1, 2, 3] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf4(): """ Tests: test__parse_a_regular_nested_dict_to_lconf4 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf4()') nested_dict = { "registered_employees": 28594, "Employee": { "Person1": { "first": "John", "last": "Doe", "sex": "M", "age": "39", "past_salary": { "year2012": 45000, "year2013": 62000 }, "emails": ["<*****@*****.**>", "<*****@*****.**>"] } }, "registered_customer": 28594, "accounting": [["2010", 38459845, 15835945, 3000945], ["2011", 38459845, 15835945, 3000945], ["2012", 28456849, 4846123, 2599901], ["2013", 38459845, 15835945, 3000945]] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 4', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 4', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf2(): """ Tests: test__parse_a_regular_nested_dict_to_lconf2 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf2()') nested_dict = { "first": "John", "last": "Doe", "age": 39, "interests": [ "Reading", "Mountain Biking", "Hacking" ], "registered": 'true', "salary": 70000, "sex": "M" } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 2', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 2', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf3(): """ Tests: test__parse_a_regular_nested_dict_to_lconf3 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf3()') nested_dict = { "first": "John", "last": "Doe", "sex": "M", "age": 39, "salary": 70000, "favorites": { "food": "Spaghetti", "sport": "Soccer", "color": "Blue" }, "registered": 'true' } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 3', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 3', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf8_expect_failure(): """ Tests: test__parse_a_regular_nested_dict_to_lconf8_expect_failure """ print( '::: TEST: test__parse_a_regular_nested_dict_to_lconf7_expect_failure()' ) nested_dict = { "accounting": [["2010", 38459845, 15835945, 3000945], ["2011", 38459845, 15835945, 3000945], ["2012", 28456849, 4846123, 2599901], ["2013", 38459845, 15835945, 3000945], { 'wrong': '1' }] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_regular_nested_dict_to_lconf6_expect_failure(): """ Tests: test__parse_a_regular_nested_dict_to_lconf6_expect_failure """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf6_expect_failure()') nested_dict = { "skills": [ { "category": "PHP", "tests": [ { "score": 90, "name": "One" }, { "score": 96, "name": "Two" } ] }, { "category": "Node.js", "tests": [ { "score": 97, "name": "One" }, { "score": 93, "name": "Two" } ] } ] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 5', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test__parse_a_dict_to_lconf_wrong_list_itemtype_expect_failure(): """ Tests: test__parse_a_dict_to_lconf_wrong_list_itemtype_expect_failure """ print('::: TEST: test__parse_a_dict_to_lconf_wrong_list_itemtype_expect_failure()') nested_dict = { "skills": [ { "category": "PHP", "tests": [ { "score": 90, "name": "One" }, { "score": 96, "name": "Two" } ] }, { "category": "Node.js", "tests": [ { "score": 97, "name": "One" }, { "score": 93, "name": "Two" } ] } ] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=True)
def test__parse_a_regular_nested_dict_to_lconf6_expect_failure(): """ Tests: test__parse_a_regular_nested_dict_to_lconf6_expect_failure """ print( '::: TEST: test__parse_a_regular_nested_dict_to_lconf6_expect_failure()' ) nested_dict = { "skills": [{ "category": "PHP", "tests": [{ "score": 90, "name": "One" }, { "score": 96, "name": "Two" }] }, { "category": "Node.js", "tests": [{ "score": 97, "name": "One" }, { "score": 93, "name": "Two" }] }] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'Json EXAMPLE 5', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str)
def test_lconf_to_ordered_native_type_ok0(): """ Tests: test_lconf_to_ordered_native_type_ok0 """ print('::: TEST: test_lconf_to_ordered_native_type_ok0()') lconf_section__template_obj = Root([ # Default Empty Line ('#1', ''), # Default Comment Line ('#2', '# Comment-Line: `Key :: Value Pair`'), ('first', ''), ('last', ''), ('sex', ''), ('age', ''), ('salary', ''), ('#3', '# Comment-Line: `Key-Value-List`'), ('interests', KVList(True, [])), ('#4', '# Comment-Line: `Key :: Value Pair`'), ('registered', ''), ]) lconf_section_raw_str = r'''___SECTION :: EXAMPLE 1 #1 :: #2 :: # Comment-Line: `Key :: Value Pair` first :: Joe last :: Smith sex :: m age :: 18 salary :: 12500 #3 :: # Comment-Line: `Key-Value-List` - interests soccer tennis #4 :: # Comment-Line: `Key :: Value Pair` registered :: False ___END''' lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'EXAMPLE 1', lconf_section__template_obj, with_comments=True, validate=True ) result_ordered_native_type = lconf_to_ordered_native_type(lconf_obj) ok_(isinstance(lconf_obj, LconfRoot), msg=None) ok_(isinstance(result_ordered_native_type, OrderedDict), msg=None) ok_(isinstance(lconf_obj['interests'], LconfKVList), msg=None) ok_(isinstance(result_ordered_native_type['interests'], list), msg=None) # RE DUMP AS JSON re_dump_json = json_dumps(result_ordered_native_type, indent=3) # RE CONVERT TO LCONF result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json, object_pairs_hook=OrderedDict), 'EXAMPLE 1', onelinelists=False, skip_none_value=False ) eq_(lconf_section_raw_str, result_reconverted_dict_to_lconf2, msg=None)
def test_lconf_to_ordered_native_type_ok1(): """ Tests: test_lconf_to_ordered_native_type_ok1 """ print('::: TEST: test_lconf_to_ordered_native_type_ok1()') lconf_section__template_obj = get_lconf_section__base_example_template_obj() lconf_section_raw_str = get_lconf_section__base_example_lconf_section_raw_str() lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'BaseEXAMPLE', lconf_section__template_obj, with_comments=False, validate=True) result_ordered_native_type = lconf_to_ordered_native_type(lconf_obj) ok_(isinstance(lconf_obj, LconfRoot), msg=None) ok_(isinstance(result_ordered_native_type, OrderedDict), msg=None) # RE DUMP AS JSON: NOTE SPECIAL characters might not be handled correctly # IMPORTANT: datetime.datetime(2014, 5, 8, 13, 39) is not JSON serializable result_ordered_native_type['key11value_mapping']['mapping11_key2_mapping'][ 'mapping11_key2_nested_mapping_key1'] = '2014-05-08 13:39:00' re_dump_json = json_dumps(result_ordered_native_type, indent=3) re_dump_json_lines = re_dump_json.splitlines() eq_(re_dump_json_lines[1], ' "key1value_pair": "NOT-DEFINED",', msg=None) eq_(re_dump_json_lines[3], ' "key3value_pair": "",', msg=None) eq_(re_dump_json_lines[10], ' "key10value_mapping": {', msg=None) eq_(re_dump_json_lines[32], ' "mapping10_key7_list": [', msg=None) eq_(re_dump_json_lines[35], ' 2.0,', msg=None) eq_(re_dump_json_lines[72], ' "key14list_of_color_tuples": [', msg=None) eq_(re_dump_json_lines[80], ' "brick",', msg=None) eq_(re_dump_json_lines[96], ' "nested_mapping_key1": "franz",', msg=None) eq_(re_dump_json_lines[103], ' "block-item_key1": 12345.99,', msg=None) eq_(re_dump_json_lines[144], ' "blk_mapping_key2": -9999999999.055,', msg=None) eq_(re_dump_json_lines[224], ' "Nested Repeated Block Identifier": {}', msg=None) # RE CONVERT TO LCONF - NOTE: there will not be any Block-Identifier result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json, object_pairs_hook=OrderedDict), 'EXAMPLE 1', onelinelists=False, skip_none_value=False ) # NOTE: there will not be any Block-Identifier result_reconverted_dict_to_lconf2_lines = result_reconverted_dict_to_lconf2.splitlines() eq_(result_reconverted_dict_to_lconf2_lines[4], 'key4value_pair :: True', msg=None) eq_(result_reconverted_dict_to_lconf2_lines[9], r'key9value_pair :: different characters # \n * | , & @ https://translate.google.com/ translate ਅਨੁਵਾਦ 翻訳する μεταφράζω', msg=None) eq_(result_reconverted_dict_to_lconf2_lines[23], ' - mapping10_key7_list |item1|item2|item3|', msg=None) eq_(result_reconverted_dict_to_lconf2_lines[31], ' . sky_blue_blk_name1', msg=None) eq_(result_reconverted_dict_to_lconf2_lines[70], ' - block-item_key3_list |item1|item2|item3|', msg=None) eq_(result_reconverted_dict_to_lconf2_lines[104], ' - block-item_key3_list', msg=None) # REDO AGAIN redo__lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'BaseEXAMPLE', lconf_section__template_obj, with_comments=False, validate=True) redo__result_ordered_native_type = lconf_to_ordered_native_type(redo__lconf_obj) redo__dump_json = json_dumps(result_ordered_native_type, indent=3) eq_(redo__dump_json, re_dump_json, msg=None) redo__result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json, object_pairs_hook=OrderedDict), 'EXAMPLE 1', onelinelists=False, skip_none_value=False ) eq_(redo__result_reconverted_dict_to_lconf2, result_reconverted_dict_to_lconf2, msg=None)
def test_lconf_to_native_type_ok0(): """ Tests: test_lconf_to_native_type_ok0 """ print('::: TEST: test_lconf_to_native_type_ok0()') lconf_section__template_obj = Root([ # Default Empty Line ('#1', ''), # Default Comment Line ('#2', '# Comment-Line: `Key :: Value Pair`'), ('first', ''), ('last', '', None, 'NOT-DEFINED'), ('sex', '', None, 'NOT-DEFINED'), ('age', '', lconf_to_int, -1), ('salary', ''), ('#3', '# Comment-Line: `Key-Value-List`'), ('interests', KVList(True, [])), ('#4', '# Comment-Line: `Key :: Value Pair`'), ('registered', ''), ]) lconf_section_raw_str = r'''___SECTION :: EXAMPLE 1 #1 :: #2 :: # Comment-Line: `Key :: Value Pair` first :: Joe last :: Smith sex :: m age :: 18 salary :: 12500 #3 :: # Comment-Line: `Key-Value-List` - interests soccer tennis #4 :: # Comment-Line: `Key :: Value Pair` registered :: False ___END''' lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'EXAMPLE 1', lconf_section__template_obj, with_comments=False, validate=True ) result_native_type = lconf_to_native_type(lconf_obj) ok_(isinstance(lconf_obj, LconfRoot), msg=None) ok_(isinstance(result_native_type, dict), msg=None) ok_(isinstance(lconf_obj['interests'], LconfKVList), msg=None) ok_(isinstance(result_native_type['interests'], list), msg=None) ok_(lconf_obj['last'] == result_native_type['last'] == 'Smith', msg=None) ok_(lconf_obj['age'] == result_native_type['age'] == 18, msg=None) # RE DUMP AS JSON re_dump_json = json_dumps(result_native_type, indent=3) # RE CONVERT TO LCONF result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json), 'EXAMPLE 1', onelinelists=False, skip_none_value=False ) lconf_validate_one_section_str(result_reconverted_dict_to_lconf2) if has_yaml: dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True) parsed_load_yaml = yaml_load(dump_yaml) ok_(isinstance(parsed_load_yaml, dict), msg=None) ok_(isinstance(parsed_load_yaml['interests'], list), msg=None) ok_(parsed_load_yaml['last'] == lconf_obj['last'] == result_native_type['last'] == 'Smith', msg=None) ok_(parsed_load_yaml['age'] == lconf_obj['age'] == result_native_type['age'] == 18, msg=None)
def test_lconf_to_native_type_ok2(): """ Tests: test_lconf_to_native_type_ok2 """ print('::: TEST: test_lconf_to_native_type_ok2()') lconf_section__template_obj = get_lconf_section__base_example_template_obj() lconf_section_raw_str = get_lconf_section__base_example_lconf_section_raw_str() lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'BaseEXAMPLE', lconf_section__template_obj, with_comments=False, validate=True) eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key2_block_identifier'][ 'sky_blue_blk_name1']['blk_item_green'], 206, msg=None) eq_(lconf_obj.key_order, ['key1value_pair', 'key2value_pair', 'key3value_pair', 'key4value_pair', 'key5value_pair', 'key6value_pair', 'key7value_pair', 'key8value_pair', 'key9value_pair', 'key10value_mapping', 'key11value_mapping', 'key12list', 'key13value_pairlist', 'key14list_of_color_tuples', 'key15value_pairlist', 'key16value_pairlist', 'key17list_of_tuples', 'RepeatedBlk1'], msg=None) eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key2_block_identifier'][ 'sky_blue_blk_name1'].key_order, ['blk_item_red', 'blk_item_green', 'blk_item_blue'], msg=None) eq_(lconf_obj['key11value_mapping']['mapping11_key1'], '/home/examples', msg=None) eq_(lconf_obj['key1value_pair'], 'NOT-DEFINED', msg=None) # `Empty-KeyValuePair-ReplacementValue` "NOT-DEFINED" eq_(lconf_obj['key7value_pair'], -94599.5, msg=None) # `Empty-KeyValuePair-ReplacementValue` "-94599.5" eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key3'], 'car', msg=None) # `Empty-KeyValuePair-ReplacementValue` "0" eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key2_block_identifier'][ 'sky_blue_blk_name1']['blk_item_red'], 0, msg=None) eq_(lconf_obj['key14list_of_color_tuples'].column_names, ('Color Name', 'Red', 'Green', 'Blue'), msg=None) eq_( lconf_obj['key14list_of_color_tuples'].column_names_idx_lookup, {'Color Name': 0, 'Red': 1, 'Green': 2, 'Blue': 3}, msg=None ) eq_(lconf_obj['key14list_of_color_tuples'][0], ('forestgreen', 34, 139, 34), msg=None) eq_(lconf_obj['RepeatedBlk1'].key_order, ['BLK_OBJ1', 'BLK_OBJ2', 'BLK_OBJ3', 'BLK_OBJ4'], msg=None) eq_(lconf_obj['RepeatedBlk1'].min_required_blocks, 2, msg=None) eq_(lconf_obj['RepeatedBlk1'].max_allowed_blocks, 5, msg=None) eq_(lconf_obj['RepeatedBlk1'].has_comments, False, msg=None) eq_( lconf_obj['RepeatedBlk1']['BLK_OBJ4'].key_order, ['MyKey1_mapping', 'MyKey2', 'MyKey3', 'MyKey4', 'MyKey5list', 'MyKey6list', 'MyKey7list', 'MyKey8'], msg=None ) # `Empty-KeyValuePair-ReplacementValue` "-9999999999.055" eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ1']['MyKey1_mapping']['blk_mapping_key2'], 12345.99, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ2']['MyKey1_mapping']['blk_mapping_key2'], -9999999999.055, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ3']['MyKey1_mapping']['blk_mapping_key2'], 9999.999, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4']['MyKey1_mapping']['blk_mapping_key2'], 9999.999, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4']['MyKey5list'], ['one item'], msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4']['MyKey4'], 'GREAT LIFE', msg=None) result_native_type = lconf_to_native_type(lconf_obj) ok_(isinstance(lconf_obj, LconfRoot), msg=None) ok_(isinstance(result_native_type, dict), msg=None) ok_(lconf_obj['key1value_pair'] == result_native_type['key1value_pair'] == 'NOT-DEFINED', msg=None) ok_(lconf_obj['key7value_pair'] == result_native_type['key7value_pair'] == -94599.5, msg=None) # RE DUMP AS JSON: NOTE SPECIAL characters might not be handled correctly # IMPORTANT: datetime.datetime(2014, 5, 8, 13, 39) is not JSON serializable result_native_type['key11value_mapping']['mapping11_key2_mapping'][ 'mapping11_key2_nested_mapping_key1'] = '2014-05-08 13:39:00' re_dump_json = json_dumps(result_native_type, indent=3) # RE CONVERT TO LCONF - NOTE: there will not be any Block-Identifier also the order might be messed up which does not work # with comment lines result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json), 'BaseEXAMPLE', onelinelists=False, skip_none_value=False ) lconf_validate_one_section_str(result_reconverted_dict_to_lconf2) # do yaml of result_native_type if has_yaml: dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True) parsed_load_yaml = yaml_load(dump_yaml) ok_(isinstance(parsed_load_yaml, dict), msg=None) eq_( parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key1'], '2014-05-08 13:39:00' ) eq_(parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping'][ 'mapping11_key2_nested_mapping_key2_block_identifier']['sky_blue_blk_name1']['blk_item_green'], 206, msg=None) eq_(parsed_load_yaml['key11value_mapping']['mapping11_key1'], '/home/examples', msg=None) eq_(parsed_load_yaml['key1value_pair'], 'NOT-DEFINED', msg=None) # `Empty-KeyValuePair-ReplacementValue` "NOT-DEFINED" eq_(parsed_load_yaml['key7value_pair'], -94599.5, msg=None) # `Empty-KeyValuePair-ReplacementValue` "-94599.5" eq_(parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key3'], 'car', msg=None) # `Empty-KeyValuePair-ReplacementValue` "0" eq_(parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping'][ 'mapping11_key2_nested_mapping_key2_block_identifier']['sky_blue_blk_name1']['blk_item_red'], 0, msg=None) # Tuple are changed to lists eq_(parsed_load_yaml['key14list_of_color_tuples'][0], ['forestgreen', 34, 139, 34], msg=None) # `Empty-KeyValuePair-ReplacementValue` "-9999999999.055" eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ1']['MyKey1_mapping']['blk_mapping_key2'], 12345.99, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ2']['MyKey1_mapping']['blk_mapping_key2'], -9999999999.055, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ3']['MyKey1_mapping']['blk_mapping_key2'], 9999.999, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ4']['MyKey1_mapping']['blk_mapping_key2'], 9999.999, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ4']['MyKey5list'], ['one item'], msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ4']['MyKey4'], 'GREAT LIFE', msg=None)
def test__parse_a_regular_nested_dict_to_lconf1(): """ Tests: test__parse_a_regular_nested_dict_to_lconf1 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf1()') nested_dict = { "description": "A trivial terminal emulator", "maintainer": "Timothy Hobbs < (at) dot cz>", "last_update_time": "2014_02_12_12:59", "dependency": "libx11", "executable": "/usr/bin/xterm", "x11": [123.0, 123], "sound_card": False, "inherit_working_directory": None, "allow_network_access": True, "test_mapping": { "test_mapping_key1": None, "test_mapping_key2": 234, "test_mapping_key3": 'value', "test_mapping_key4": '', } } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_('- x11 :: 123.0,123' in section_lines, msg=None) ok_(' test_mapping_key1 ::' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_('- x11' in section_lines, msg=None) ok_(' test_mapping_key1 ::' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=True, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_('- x11 :: 123.0,123' in section_lines, msg=None) ok_(' test_mapping_key1 :: None' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'PERMISSIONS', onelinelists=False, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_('- x11' in section_lines, msg=None) ok_(' test_mapping_key1 :: None' in section_lines, msg=None) ok_(' test_mapping_key3 ::' in section_lines, msg=None) ok_(' test_mapping_key4 ::' in section_lines, msg=None)
def test__parse_a_regular_nested_dict_to_lconf12(): """ Tests: test__parse_a_regular_nested_dict_to_lconf12 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf12()') nested_dict = { "accounting": { "nested": { "Inner": 'something' }, "nested key": None, "nested key2": False, "nested key3": '', "nested list1": [], "nested list2": [1, 2, 3], }, "key": None, "key2": False, "key3": '', "list1": [], "list2": [1, 2, 3] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key ::' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key ::' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key :: None' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key :: None' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key ::' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key ::' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines(result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key :: None' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key :: None' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None)
def test__parse_a_regular_nested_dict_to_lconf12(): """ Tests: test__parse_a_regular_nested_dict_to_lconf12 """ print('::: TEST: test__parse_a_regular_nested_dict_to_lconf12()') nested_dict = { "accounting": { "nested": { "Inner": 'something' }, "nested key": None, "nested key2": False, "nested key3": '', "nested list1": [], "nested list2": [1, 2, 3], }, "key": None, "key2": False, "key3": '', "list1": [], "list2": [1, 2, 3] } result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key ::' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key ::' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=True, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key :: None' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key :: None' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=True) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key ::' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key ::' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None) result_dict_to_lconf_str = lconf_dict_to_lconf(nested_dict, 'example', onelinelists=False, skip_none_value=False) lconf_validate_source(result_dict_to_lconf_str) section_lines, section_name = lconf_section_splitlines( result_dict_to_lconf_str, validate_first_line=False) ok_(' nested key :: None' in section_lines, msg=None) ok_(' nested key2 :: False' in section_lines, msg=None) ok_(' nested key3 ::' in section_lines, msg=None) ok_('key :: None' in section_lines, msg=None) ok_('key2 :: False' in section_lines, msg=None) ok_('key3 ::' in section_lines, msg=None)
def test_lconf_to_native_type_ok2(): """ Tests: test_lconf_to_native_type_ok2 """ print('::: TEST: test_lconf_to_native_type_ok2()') lconf_section__template_obj = get_lconf_section__base_example_template_obj( ) lconf_section_raw_str = get_lconf_section__base_example_lconf_section_raw_str( ) lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'BaseEXAMPLE', lconf_section__template_obj, with_comments=False, validate=True) eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key2_block_identifier'] ['sky_blue_blk_name1']['blk_item_green'], 206, msg=None) eq_(lconf_obj.key_order, [ 'key1value_pair', 'key2value_pair', 'key3value_pair', 'key4value_pair', 'key5value_pair', 'key6value_pair', 'key7value_pair', 'key8value_pair', 'key9value_pair', 'key10value_mapping', 'key11value_mapping', 'key12list', 'key13value_pairlist', 'key14list_of_color_tuples', 'key15value_pairlist', 'key16value_pairlist', 'key17list_of_tuples', 'RepeatedBlk1' ], msg=None) eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key2_block_identifier'] ['sky_blue_blk_name1'].key_order, ['blk_item_red', 'blk_item_green', 'blk_item_blue'], msg=None) eq_(lconf_obj['key11value_mapping']['mapping11_key1'], '/home/examples', msg=None) eq_(lconf_obj['key1value_pair'], 'NOT-DEFINED', msg=None) # `Empty-KeyValuePair-ReplacementValue` "NOT-DEFINED" eq_(lconf_obj['key7value_pair'], -94599.5, msg=None) # `Empty-KeyValuePair-ReplacementValue` "-94599.5" eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key3'], 'car', msg=None) # `Empty-KeyValuePair-ReplacementValue` "0" eq_(lconf_obj['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key2_block_identifier'] ['sky_blue_blk_name1']['blk_item_red'], 0, msg=None) eq_(lconf_obj['key14list_of_color_tuples'].column_names, ('Color Name', 'Red', 'Green', 'Blue'), msg=None) eq_(lconf_obj['key14list_of_color_tuples'].column_names_idx_lookup, { 'Color Name': 0, 'Red': 1, 'Green': 2, 'Blue': 3 }, msg=None) eq_(lconf_obj['key14list_of_color_tuples'][0], ('forestgreen', 34, 139, 34), msg=None) eq_(lconf_obj['RepeatedBlk1'].key_order, ['BLK_OBJ1', 'BLK_OBJ2', 'BLK_OBJ3', 'BLK_OBJ4'], msg=None) eq_(lconf_obj['RepeatedBlk1'].min_required_blocks, 2, msg=None) eq_(lconf_obj['RepeatedBlk1'].max_allowed_blocks, 5, msg=None) eq_(lconf_obj['RepeatedBlk1'].has_comments, False, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4'].key_order, [ 'MyKey1_mapping', 'MyKey2', 'MyKey3', 'MyKey4', 'MyKey5list', 'MyKey6list', 'MyKey7list', 'MyKey8' ], msg=None) # `Empty-KeyValuePair-ReplacementValue` "-9999999999.055" eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ1']['MyKey1_mapping'] ['blk_mapping_key2'], 12345.99, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ2']['MyKey1_mapping'] ['blk_mapping_key2'], -9999999999.055, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ3']['MyKey1_mapping'] ['blk_mapping_key2'], 9999.999, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4']['MyKey1_mapping'] ['blk_mapping_key2'], 9999.999, msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4']['MyKey5list'], ['one item'], msg=None) eq_(lconf_obj['RepeatedBlk1']['BLK_OBJ4']['MyKey4'], 'GREAT LIFE', msg=None) result_native_type = lconf_to_native_type(lconf_obj) ok_(isinstance(lconf_obj, LconfRoot), msg=None) ok_(isinstance(result_native_type, dict), msg=None) ok_(lconf_obj['key1value_pair'] == result_native_type['key1value_pair'] == 'NOT-DEFINED', msg=None) ok_(lconf_obj['key7value_pair'] == result_native_type['key7value_pair'] == -94599.5, msg=None) # RE DUMP AS JSON: NOTE SPECIAL characters might not be handled correctly # IMPORTANT: datetime.datetime(2014, 5, 8, 13, 39) is not JSON serializable result_native_type['key11value_mapping']['mapping11_key2_mapping'][ 'mapping11_key2_nested_mapping_key1'] = '2014-05-08 13:39:00' re_dump_json = json_dumps(result_native_type, indent=3) # RE CONVERT TO LCONF - NOTE: there will not be any Block-Identifier also the order might be messed up which does not work # with comment lines result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json), 'BaseEXAMPLE', onelinelists=False, skip_none_value=False) lconf_validate_one_section_str(result_reconverted_dict_to_lconf2) # do yaml of result_native_type if has_yaml: dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True) parsed_load_yaml = yaml_load(dump_yaml) ok_(isinstance(parsed_load_yaml, dict), msg=None) eq_( parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key1'], '2014-05-08 13:39:00') eq_(parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key2_block_identifier'] ['sky_blue_blk_name1']['blk_item_green'], 206, msg=None) eq_(parsed_load_yaml['key11value_mapping']['mapping11_key1'], '/home/examples', msg=None) eq_(parsed_load_yaml['key1value_pair'], 'NOT-DEFINED', msg=None) # `Empty-KeyValuePair-ReplacementValue` "NOT-DEFINED" eq_(parsed_load_yaml['key7value_pair'], -94599.5, msg=None) # `Empty-KeyValuePair-ReplacementValue` "-94599.5" eq_(parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key3'], 'car', msg=None) # `Empty-KeyValuePair-ReplacementValue` "0" eq_(parsed_load_yaml['key11value_mapping']['mapping11_key2_mapping'] ['mapping11_key2_nested_mapping_key2_block_identifier'] ['sky_blue_blk_name1']['blk_item_red'], 0, msg=None) # Tuple are changed to lists eq_(parsed_load_yaml['key14list_of_color_tuples'][0], ['forestgreen', 34, 139, 34], msg=None) # `Empty-KeyValuePair-ReplacementValue` "-9999999999.055" eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ1']['MyKey1_mapping'] ['blk_mapping_key2'], 12345.99, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ2']['MyKey1_mapping'] ['blk_mapping_key2'], -9999999999.055, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ3']['MyKey1_mapping'] ['blk_mapping_key2'], 9999.999, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ4']['MyKey1_mapping'] ['blk_mapping_key2'], 9999.999, msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ4']['MyKey5list'], ['one item'], msg=None) eq_(parsed_load_yaml['RepeatedBlk1']['BLK_OBJ4']['MyKey4'], 'GREAT LIFE', msg=None)
def test_lconf_to_native_type_ok0(): """ Tests: test_lconf_to_native_type_ok0 """ print('::: TEST: test_lconf_to_native_type_ok0()') lconf_section__template_obj = Root([ # Default Empty Line ('#1', ''), # Default Comment Line ('#2', '# Comment-Line: `Key :: Value Pair`'), ('first', ''), ('last', '', None, 'NOT-DEFINED'), ('sex', '', None, 'NOT-DEFINED'), ('age', '', lconf_to_int, -1), ('salary', ''), ('#3', '# Comment-Line: `Key-Value-List`'), ('interests', KVList(True, [])), ('#4', '# Comment-Line: `Key :: Value Pair`'), ('registered', ''), ]) lconf_section_raw_str = r'''___SECTION :: EXAMPLE 1 #1 :: #2 :: # Comment-Line: `Key :: Value Pair` first :: Joe last :: Smith sex :: m age :: 18 salary :: 12500 #3 :: # Comment-Line: `Key-Value-List` - interests soccer tennis #4 :: # Comment-Line: `Key :: Value Pair` registered :: False ___END''' lconf_obj = lconf_parse_section_extract_by_name( lconf_section_raw_str, 'EXAMPLE 1', lconf_section__template_obj, with_comments=False, validate=True) result_native_type = lconf_to_native_type(lconf_obj) ok_(isinstance(lconf_obj, LconfRoot), msg=None) ok_(isinstance(result_native_type, dict), msg=None) ok_(isinstance(lconf_obj['interests'], LconfKVList), msg=None) ok_(isinstance(result_native_type['interests'], list), msg=None) ok_(lconf_obj['last'] == result_native_type['last'] == 'Smith', msg=None) ok_(lconf_obj['age'] == result_native_type['age'] == 18, msg=None) # RE DUMP AS JSON re_dump_json = json_dumps(result_native_type, indent=3) # RE CONVERT TO LCONF result_reconverted_dict_to_lconf2 = lconf_dict_to_lconf( json_loads(re_dump_json), 'EXAMPLE 1', onelinelists=False, skip_none_value=False) lconf_validate_one_section_str(result_reconverted_dict_to_lconf2) if has_yaml: dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True) parsed_load_yaml = yaml_load(dump_yaml) ok_(isinstance(parsed_load_yaml, dict), msg=None) ok_(isinstance(parsed_load_yaml['interests'], list), msg=None) ok_(parsed_load_yaml['last'] == lconf_obj['last'] == result_native_type['last'] == 'Smith', msg=None) ok_(parsed_load_yaml['age'] == lconf_obj['age'] == result_native_type['age'] == 18, msg=None)