def test_lconf_key_value_list_ok2():
    """ Tests: test_lconf_key_value_list_ok2
   """
    print('::: TEST: test_lconf_key_value_list_ok2()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key-Value-List`
# Comment-Line: below is a Main `Key-Value-List`
- list
   1
   2
   3
___END'''

    example_lconf_template = Root([(
        '#1',
        '# Comment-Line: below is a Main `Key :: Value-List`: with transform_function - use_oneline is False '
    ),
                                   ('list',
                                    KVList(
                                        False,
                                        ['default_value1', 'default_value2']),
                                    transform_function)])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_default_comment_lines_ok2():
    """ Tests: test_lconf_default_comment_lines_ok2
   """
    print('::: TEST: test_lconf_default_comment_lines_ok2()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs`
key1 :: value1
key2 :: value2
___END'''

    example_lconf_template = Root([
        # Comment below is an `Empty default Comment Line` which can be emitted
        ('#1', ''),
        ('key1', 'default_value1'),
        # Comment below is another `Empty default Comment Line` which can be emitted
        ('#2', ''),
        ('key2', 'default_value1'),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_list_of_tuples_ok1():
    """ Tests: test_lconf_list_of_tuples_ok1
   """
    print('::: TEST: test_lconf_list_of_tuples_ok1()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `List-Of-Tuples`
# Comment-Line: below is a Main `List-Of-Tuples` with 4 items: |Color Name|Red|Green|Blue|
- list_of_color_tuples |Color Name|Red|Green|Blue|
   # Comment-Line: `List-Of-Tuples` item lines (rows)
   forestgreen,   34,   139,  34
   brick,         156,  102,  31
___END'''

    example_lconf_template = Root([
        # Comment-Line: below is a Main `List-Of-Tuples` with 4 columns: |Color Name|Red|Green|Blue|'
        ('list_of_color_tuples',
         ListOT(('Color Name', 'Red', 'Green', 'Blue'),
                [('default_value_Color_Name', 'default_value_Red',
                  'default_value_Green', 'default_value_Blue'),
                 ('default_value_Color_Name', 'default_value_Red',
                  'default_value_Green', 'default_value_Blue')])),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_list_of_tuples_ok2():
   """ Tests: test_lconf_list_of_tuples_ok2
   """
   print('::: TEST: test_lconf_list_of_tuples_ok2()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `List-Of-Tuples`
# Comment-Line: below is a Main `List-Of-Tuples` with 4 items: |Color Name|Red|Green|Blue|
- list_of_color_tuples |Color Name|Red|Green|Blue|
   # Comment-Line: `List-Of-Tuples` item lines (rows)
   forestgreen,   34,   139,  34
   brick,         156,  102,  31
___END'''

   example_lconf_template = Root([
      # Comment-Line: below is a Main `List-Of-Tuples` with 4 columns: |Color Name|Red|Green|Blue|'
      ('list_of_color_tuples', ListOT(('Color Name', 'Red', 'Green', 'Blue'), [
         ('default_value_Color_Name', 'default_value_Red', 'default_value_Green', 'default_value_Blue'),
         ('default_value_Color_Name', 'default_value_Red', 'default_value_Green', 'default_value_Blue')
      ]), (None, transform_function, transform_function, transform_function)),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_empty_key_value_pair_replacement_ok1():
    """ Tests: test_lconf_empty_key_value_pair_replacement_ok1
   """
    print('::: TEST: test_lconf_empty_key_value_pair_replacement_ok1()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs` items
# Comment-Line: Root/Main key value pair
key1 :: value1
key2 :: Red
key3 ::
___END'''

    example_lconf_template = Root([
        ('#1',
         '# Comment: Root/Main key value pair - no transform function - with  `Empty-KeyValuePair-ReplacementValue`'
         ),
        ('key1', 'default_value1', None,
         'Empty-KeyValuePair-ReplacementValue'),
        ('key2', 'Blue', None, 'NO-COLOR-DEFINED'),
        ('key3', 'Blue', None, 'NO-COLOR-DEFINED'),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_list_of_tuples_ok5():
    """ Tests: test_lconf_list_of_tuples_ok5
   """
    print('::: TEST: test_lconf_list_of_tuples_ok5()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `List-Of-Tuples`
# Comment-Line: below is a Main `List-Of-Tuples` with 3 items: |x|y|z|
- list_of_point_tuples |x|y|z|
   # Comment-Line: `List-Of-Tuples` item lines (rows) with missing items
   ,,
   2, ,14
___END'''

    example_lconf_template = Root([
        # Comment-Line: below is a Main `List-Of-Tuples` with 3 items: |x|y|z|
        ('list_of_point_tuples',
         ListOT(('x', 'y', 'z'), [
             ('default_value_x', 'default_value_y', 'default_value_z'),
             ('default_value_x', 'default_value_y', 'default_value_z'),
         ],
                column_replace_missing=('-1', '-1', '-1'))),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_main_root_obj_ok():
   """ Tests: test_lconf_main_root_obj_ok
   """
   print('::: TEST: test_lconf_main_root_obj_ok()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF Root
key1 :: value1
key2 :: value2
key3 :: value3
key4 ::
# Comment-Line: Root/Main LCONF-Section END TAG Line
___END'''

   example_lconf_template = Root([
      ('#1', '# Comment-Line: Root/Main key value pair'),
      ('key1', 'default_value1'),
      ('key2', 'default_value2', transform_function),
      ('#2', '# Comment-Line: Root/Main key value pair with transform_function and `Empty-KeyValuePair-ReplacementValue`'),
      ('key3', 'default_value3', transform_function, 'empty_replacement_value3'),
      ('key4', 'default_value4', transform_function, 'empty_replacement_value4'),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_empty_key_value_pair_replacement_ok2():
   """ Tests: test_lconf_empty_key_value_pair_replacement_ok2
   """
   print('::: TEST: test_lconf_empty_key_value_pair_replacement_ok2()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs` items
# Comment-Line: Root/Main key value pair
key1 :: value1
key2 ::
key3 ::
___END'''

   example_lconf_template = Root([
      ('#1', '# Comment Root/Main key value pair - with transform function - with `Empty-KeyValuePair-ReplacementValue`'),
      ('key1', 'default_value1', transform_function, 'Empty-KeyValuePair-ReplacementValue'),
      # Comment-Line: in the case below: if `key2` is in the `LCONF source` set to empty: the parsed lconf obj will have
      # the `Empty-KeyValuePair-ReplacementValue` -1
      ('key2', 500, lconf_to_int, -1),
      # Comment-Line: in the case below: if `key3` is by default empty: the parsed lconf obj will have
      #     the `Empty-KeyValuePair-ReplacementValue` -1 except the `LCONF source` to be parsed has set it to something
      ('key3', '', lconf_to_float, -999.4),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_key_value_separator_items_ok4():
    """ Tests: test_lconf_key_value_separator_items_ok4
   """
    print('::: TEST: test_lconf_key_value_separator_items_ok4()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs`
# Comment-Line: Root/Main key value pair
key1 :: value1
___END'''

    example_lconf_template = Root([
        ('#1a',
         '# Comment: Root/Main key value pair with no transform_function and Empty-KeyValuePair-ReplacementValue'
         ),
        ('#1b', '#          Instead of the transform_function use None'),
        ('key1', 'default_value1', None, 'empty_replacement_value1'),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_key_value_separator_items_ok2():
    """ Tests: test_lconf_key_value_separator_items_ok2
   """
    print('::: TEST: test_lconf_key_value_separator_items_ok2()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs`
# Comment-Line: Root/Main key value pair
key1 :: value1
___END'''

    example_lconf_template = Root([
        # Comment-Line: Root/Main key value pair with transform_function
        ('key1', 'default_value1', transform_function),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_prepare_default_obj__ok1():
   """ Tests: test_lconf_prepare_default_obj__ok1
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok1()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      # Default Comment Line
      ('#2', '# Comment-Line: `Key :: Value Pair`'),
      ('first', ''),
      ('last', ''),
      ('sex', '', None, 'NOT-DEFINED'),
      ('age', '', lconf_to_int, -1),
      ('salary', 0.0, lconf_to_float),
      ('#3', '# Comment-Line: `Key-Value-List`'),
      ('interests', KVList(True, [])),
      ('#4', '# Comment-Line: `Key :: Value Pair`'),
      ('registered', True, lconf_to_bool),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   eq_(default_lconf_obj.key_empty_replacementvalue, {'age': -1, 'sex': 'NOT-DEFINED'}, msg=None)

   eq_(type(default_lconf_obj['age']), int, msg=None)
   eq_(default_lconf_obj['age'], -1, msg=None)  # `Empty-KeyValuePair-ReplacementValues`
   eq_(type(default_lconf_obj['salary']), float, msg=None)
   eq_(type(default_lconf_obj['registered']), bool, msg=None)

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(default_lconf_obj.key_empty_replacementvalue, {'age': -1, 'sex': 'NOT-DEFINED'}, msg=None)
def test_lconf_list_of_tuples_ok7():
   """ Tests: test_lconf_list_of_tuples_ok7
   """
   print('::: TEST: test_lconf_list_of_tuples_ok7()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `List-Of-Tuples`
# Comment-Line: below is a Main `List-Of-Tuples` with 3 items: |x|y|z|
- list_of_point_tuples |x|y|z|
   # Comment-Line: `List-Of-Tuples` item lines (rows) with missing items
   ,,
   2, ,14
___END'''

   example_lconf_template = Root([
      # Comment-Line: below is a Main `List-Of-Tuples` with 3 items: |x|y|z|
      ('list_of_point_tuples', ListOT(('x', 'y', 'z'), [
         ('default_value_x', 'default_value_y', 'default_value_z'),
         ('default_value_x', 'default_value_y', 'default_value_z'),
      ], column_replace_missing=('-1', '-1', '-1')), (transform_function, transform_function, transform_function)),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_key_value_mapping_ok():
   """ Tests: test_lconf_key_value_mapping_ok
   """
   print('::: TEST: test_lconf_key_value_mapping_ok()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key-Value-Mapping`
# Comment-Line: below is a Main `Key-Value-Mapping`
. key_value_mapping
   key1 :: value1
   key2 :: value2
   key3 :: value3
   key4 ::
___END'''

   example_lconf_template = Root([
      # Comment-Line: below is a Main `Key-Value-Mapping`
      ('key_value_mapping', KVMap([
         ('#1', '# Comment-Line: Root/Main key value pair'),
         ('key1', 'default_value1'),
         ('key2', 'default_value2', transform_function),
         ('#2', '# Comment: Root/Main key value pair with transform_function and  `Empty-KeyValuePair-ReplacementValue`'),
         ('key3', 'default_value3', transform_function, 'empty_replacement_value3'),
         ('key4', 'default_value4', transform_function, 'empty_replacement_value4'),
      ])),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_prepare_default_obj__parse_section_lines_ok0():
   """ Tests: test_lconf_prepare_default_obj__parse_section_lines_ok0
   """
   print('::: TEST: test_lconf_prepare_default_obj__parse_section_lines_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 :: Test Example1

# Comment-Line: `Key :: Value Pair`
first :: Joe
last :: Smith
sex :: m
age :: 18
salary :: 12500
# Comment-Line
- interests
   soccer
   tennis

# Comment-Line: `Key :: Value Pair`
registered :: False
___END
'''
   lconf_validate_one_section_str(lconf_section_raw_str)
   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=False)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)

   ok_(isinstance(lconf_obj, LconfRoot), msg=None)
   eq_(lconf_obj['first'], 'Joe', msg=None)
   eq_(lconf_obj['last'], 'Smith', msg=None)
   eq_(lconf_obj['sex'], 'm', msg=None)
   eq_(lconf_obj['age'], '18', msg=None)
   eq_(lconf_obj['salary'], '12500', msg=None)

   ok_(isinstance(lconf_obj['interests'], LconfKVList), msg=None)
   eq_(lconf_obj['interests'], ['soccer', 'tennis'], msg=None)
   eq_(lconf_obj['interests'].use_oneline, True, msg=None)

   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=True)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
def test_lconf_repeated_block_identifier_ok2():
    """ Tests: test_lconf_repeated_block_identifier_ok2
   """
    print('::: TEST: test_lconf_repeated_block_identifier_ok2()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Repeated-Block-Identifier`
# Comment-Line: below is a Main `Repeated-Block-Identifier`
* My_Repeated_Block

   BlockName1
      key1 :: value1
      key2 :: value2
      key3 ::

   BlockName2
      key1 :: value1
      key2 :: value2
      key3 :: value3

___END'''

    example_lconf_template = Root([
        # Comment-Line: Root/Main `Repeated-Block-Identifier`: **min_required_blocks, max_allowed_blocks** set both to 2
        (
            'My_Repeated_Block',
            BlkI(
                2,
                2,
                # Comment-Line: Dummy Block
                Blk([
                    # Comment-Line: Block key value pair
                    ('key1', 'default_value1`'),
                    # Comment-Line: Block key value pair with transform_function
                    ('key2', 'default_value2', transform_function),
                    ('#1',
                     '# Comment: Block key value pair with transform_function and `Empty-KeyValuePair-ReplacementValue`'
                     ),
                    ('key3', 'default_value3', transform_function,
                     'empty_replacement_value3'),
                ]))),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_prepare_default_obj__ok5():
   """ Tests: test_lconf_prepare_default_obj__ok5
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok5()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      ('other type', set()),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
def test_lconf_prepare_default_obj__parse_section_lines_ok1():
   """ Tests: test_lconf_prepare_default_obj__parse_section_lines_ok1
   """
   print('::: TEST: test_lconf_prepare_default_obj__parse_section_lines_ok1()')

   lconf_section__template_obj = Root([
      ('keyvalue_mapping', KVMap([
         ('#1', '# Comment-Line:  Key-Value-Mapping items: `Key :: Value Pairs`'),
         ('mapping1_key1', 'default'),
         ('mapping1_key2', 'default'),
         ('mapping1_key3', 'default'),
      ])),
      ('keyvalue_mapping2', KVMap([
         ('mapping2_key1', 'default'),
      ])),
      ('keyvalue_mapping3', KVMap([
         ('mapping3_key1', 'default'),
      ])),
   ])

   lconf_section_raw_str = r'''___SECTION :: Test Example1

# Comment: Key-Value-Mapping
. keyvalue_mapping
   mapping1_key1 :: Something
   mapping1_key2 :: Something2
   mapping1_key3 :: Something3

# Comment: empty Key-Value-Mapping: uses all default values similar if it would not be defined
. keyvalue_mapping2
___END
'''
   lconf_validate_one_section_str(lconf_section_raw_str)
   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=True)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)

   ok_(isinstance(lconf_obj, LconfRoot), msg=None)
   ok_(isinstance(lconf_obj['keyvalue_mapping'], LconfKVMap), msg=None)
   eq_(lconf_obj['keyvalue_mapping']['mapping1_key1'], 'Something', msg=None)
   eq_(lconf_obj['keyvalue_mapping']['mapping1_key3'], 'Something3', msg=None)
   eq_(lconf_obj['keyvalue_mapping'].key_order, ['mapping1_key1', 'mapping1_key2', 'mapping1_key3'], msg=None)

   ok_(isinstance(lconf_obj['keyvalue_mapping2'], LconfKVMap), msg=None)
   eq_(lconf_obj['keyvalue_mapping2']['mapping2_key1'], 'default', msg=None)

   ok_(isinstance(lconf_obj['keyvalue_mapping3'], LconfKVMap), msg=None)
   eq_(lconf_obj['keyvalue_mapping3']['mapping3_key1'], 'default', msg=None)

   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=False)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)
def test_lconf_prepare_default_obj__ok4():
   """ Tests: test_lconf_prepare_default_obj__ok4
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok4()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      ('conf_path', '/home/test', lconf_to_pathexpanduser),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(type(default_lconf_obj['conf_path']), str, msg=None)

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
def test_lconf_prepare_default_obj__ok7():
   """ Tests: test_lconf_prepare_default_obj__ok7
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok7()')

   # noinspection PySetFunctionToLiteral
   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      ('other type', set({'1', '2'})),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   ok_(isinstance(default_lconf_obj['other type'], set), msg=None)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
Exemple #20
0
def test_lconf_prepare_default_obj__ok5():
    """ Tests: test_lconf_prepare_default_obj__ok5
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok5()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        ('other type', set()),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
Exemple #21
0
def test_lconf_prepare_default_obj__ok2():
    """ Tests: test_lconf_prepare_default_obj__ok2
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok2()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        # Default Comment Line
        ('#2', '# Comment-Line: `Key :: Value Pair`'),
        ('first', ''),
        ('last', ''),
        ('sex', ''),
        ('age', '', lconf_to_int),
        ('salary', 0.0, lconf_to_float),
        ('#3', '# Comment-Line: `Key-Value-Mapping`'),
        ('favorites',
         KVMap([
             ('food', ''),
             ('sport', '', None, 'Not-Defined'),
             ('color', ''),
         ])),
        ('#4', '# Comment-Line: `Key :: Value Pair`'),
        ('registered', True, lconf_to_bool),
    ])

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    eq_(default_lconf_obj.key_order,
        ['first', 'last', 'sex', 'age', 'salary', 'favorites', 'registered'],
        msg=None)
    eq_(default_lconf_obj['favorites'].key_order, ['food', 'sport', 'color'],
        msg=None)
    eq_(default_lconf_obj['favorites'].key_empty_replacementvalue,
        {'sport': 'Not-Defined'},
        msg=None)

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    eq_(default_lconf_obj.key_order, [
        '#1', '#2', 'first', 'last', 'sex', 'age', 'salary', '#3', 'favorites',
        '#4', 'registered'
    ],
        msg=None)
    eq_(default_lconf_obj['favorites'].key_order, ['food', 'sport', 'color'],
        msg=None)
    eq_(default_lconf_obj['favorites'].key_empty_replacementvalue,
        {'sport': 'Not-Defined'},
        msg=None)
def test_lconf_prepare_default_obj__ok3():
   """ Tests: test_lconf_prepare_default_obj__ok3
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok3()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      ('executiontime', datetime.strptime('2014-05-08 13:39', '%Y-%m-%d %H:%M'), lconf_to_datetime),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   eq_(type(default_lconf_obj['executiontime']), datetime, msg=None)

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(type(default_lconf_obj['executiontime']), datetime, msg=None)
Exemple #23
0
def test_lconf_prepare_default_obj__ok4():
    """ Tests: test_lconf_prepare_default_obj__ok4
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok4()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        ('conf_path', '/home/test', lconf_to_pathexpanduser),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    eq_(type(default_lconf_obj['conf_path']), str, msg=None)

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
Exemple #24
0
def test_lconf_prepare_default_obj__ok7():
    """ Tests: test_lconf_prepare_default_obj__ok7
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok7()')

    # noinspection PySetFunctionToLiteral
    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        ('other type', set({'1', '2'})),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    ok_(isinstance(default_lconf_obj['other type'], set), msg=None)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
Exemple #25
0
def test_lconf_parse_section_ok1():
   """ Tests: test_lconf_parse_section_ok1
   """
   print('::: TEST: test_lconf_parse_section_ok1()')

   lconf_section__template_obj = Root([
      ('keyvalue_mapping', KVMap([
         ('#1', '# Comment-Line:  Key-Value-Mapping items: `Key :: Value Pairs`'),
         ('mapping_key1', 'default'),
         ('mapping_key2', 'default'),
         ('mapping_key3', 'default'),
      ])),
   ])

   lconf_section_raw_str = r'''___SECTION :: Test Example1

. keyvalue_mapping
   mapping_key1 :: Something
   mapping_key2 :: Something2
   mapping_key3 :: Something3
___END
'''
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, lconf_section__template_obj, validate=True)

   ok_(isinstance(lconf_obj, LconfRoot), msg=None)
   ok_(isinstance(lconf_obj['keyvalue_mapping'], LconfKVMap), msg=None)
   eq_(lconf_obj['keyvalue_mapping']['mapping_key1'], 'Something', msg=None)
   eq_(lconf_obj['keyvalue_mapping']['mapping_key3'], 'Something3', msg=None)
   eq_(lconf_obj['keyvalue_mapping'].key_order, ['mapping_key1', 'mapping_key2', 'mapping_key3'], msg=None)
def test_lconf_section_splitlines__trailing_space__expect_failure():
    """ Tests: test_lconf_section_splitlines__trailing_space__expect_failure
   """
    print(
        '::: TEST: test_lconf_section_splitlines__trailing_space__expect_failure()'
    )

    # Main `Section-Template OBJ: type: Root
    lconf_section__template_obj = Root([('#1', '# Comment-Line'),
                                        ('key1value_pair', ''),
                                        ('key2value_pair',
                                         9999.999, lconf_to_float),
                                        ('key3value_pair', '')])

    path_to_lconf_file = path_join(SCRIPT_PATH,
                                   'example_to_validate_with_err6.lconf')
    with open(path_to_lconf_file, 'r') as file_:
        lconf_section_raw_str = lconf_extract_one_section_by_name(
            file_.read(), 'Example')

    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=False)
    for line in section_lines:
        print(('<{}>'.format(line)))
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
def test_lconf_parse_section_ok0():
    """ Tests: test_lconf_parse_section_ok0
   """
    print('::: TEST: test_lconf_parse_section_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 :: Test Example1

# Comment-Line: `Key :: Value Pair`
first :: Joe
last :: Smith
sex :: m
age :: 18
salary :: 12500
# Comment-Line
- interests
   soccer
   tennis

# Comment-Line: `Key :: Value Pair`
registered :: False
___END
'''
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    lconf_section__template_obj,
                                    validate=True)

    ok_(isinstance(lconf_obj, LconfRoot), msg=None)
    eq_(lconf_obj['first'], 'Joe', msg=None)
    eq_(lconf_obj['last'], 'Smith', msg=None)
    eq_(lconf_obj['sex'], 'm', msg=None)
    eq_(lconf_obj['age'], '18', msg=None)
    eq_(lconf_obj['salary'], '12500', msg=None)

    ok_(isinstance(lconf_obj['interests'], LconfKVList), msg=None)
    eq_(lconf_obj['interests'], ['soccer', 'tennis'], msg=None)
    eq_(lconf_obj['interests'].use_oneline, True, msg=None)

    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    lconf_section__template_obj,
                                    validate=False)
def test_lconf_key_value_separator_items_ok1():
   """ Tests: test_lconf_key_value_separator_items_ok1
   """
   print('::: TEST: test_lconf_key_value_separator_items_ok1()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs`
# Comment-Line: Root/Main key value pair
key1 :: value1
___END'''

   example_lconf_template = Root([
      # Comment-Line: Root/Main key value pair
      ('key1', 'default_value1'),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_key_value_separator_items_ok3():
   """ Tests: test_lconf_key_value_separator_items_ok3
   """
   print('::: TEST: test_lconf_key_value_separator_items_ok3()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs`
# Comment-Line: Root/Main key value pair
key1 :: value1
___END'''

   example_lconf_template = Root([
      ('#1', '# Comment-Line: Root/Main key value pair with transform_function and Empty-KeyValuePair-ReplacementValue'),
      ('key1', 'default_value1', transform_function, 'empty_replacement_value1'),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_key_value_separated_list_ok2():
   """ Tests: test_lconf_key_value_separated_list_ok2
   """
   print('::: TEST: test_lconf_key_value_separated_list_ok2()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value-List`
# Comment-Line: below is a Main `Key :: Value-List`
- list :: 1,2,3
___END'''

   example_lconf_template = Root([
      ('#1', '# Comment-Line: below is a Main `Key :: Value-List`: with transform_function - use_oneline is True '),
      ('list', KVList(True, ['default_value1', 'default_value2']), transform_function)
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
Exemple #31
0
def test_lconf_prepare_default_obj__ok3():
    """ Tests: test_lconf_prepare_default_obj__ok3
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok3()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        ('executiontime',
         datetime.strptime('2014-05-08 13:39',
                           '%Y-%m-%d %H:%M'), lconf_to_datetime),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    eq_(type(default_lconf_obj['executiontime']), datetime, msg=None)

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    eq_(type(default_lconf_obj['executiontime']), datetime, msg=None)
def test_lconf_key_value_mapping_ok():
    """ Tests: test_lconf_key_value_mapping_ok
   """
    print('::: TEST: test_lconf_key_value_mapping_ok()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key-Value-Mapping`
# Comment-Line: below is a Main `Key-Value-Mapping`
. key_value_mapping
   key1 :: value1
   key2 :: value2
   key3 :: value3
   key4 ::
___END'''

    example_lconf_template = Root([
        # Comment-Line: below is a Main `Key-Value-Mapping`
        ('key_value_mapping',
         KVMap([
             ('#1', '# Comment-Line: Root/Main key value pair'),
             ('key1', 'default_value1'),
             ('key2', 'default_value2', transform_function),
             ('#2',
              '# Comment: Root/Main key value pair with transform_function and  `Empty-KeyValuePair-ReplacementValue`'
              ),
             ('key3', 'default_value3', transform_function,
              'empty_replacement_value3'),
             ('key4', 'default_value4', transform_function,
              'empty_replacement_value4'),
         ])),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_prepare_default_obj__ok6():
   """ Tests: test_lconf_prepare_default_obj__ok6
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok6()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      ('RepeatedBlk1', BlkI(-1, -1,
         Blk([
            ('MyKey1', ''),
            ('MyKey2', '', None, 'Not-Defined'),
         ])
      )),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   eq_(default_lconf_obj['RepeatedBlk1'], {}, msg=None)

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(default_lconf_obj, {'RepeatedBlk1': {}, '#1': ''}, msg=None)
Exemple #34
0
def test_lconf_prepare_default_obj__ok1():
    """ Tests: test_lconf_prepare_default_obj__ok1
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok1()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        # Default Comment Line
        ('#2', '# Comment-Line: `Key :: Value Pair`'),
        ('first', ''),
        ('last', ''),
        ('sex', '', None, 'NOT-DEFINED'),
        ('age', '', lconf_to_int, -1),
        ('salary', 0.0, lconf_to_float),
        ('#3', '# Comment-Line: `Key-Value-List`'),
        ('interests', KVList(True, [])),
        ('#4', '# Comment-Line: `Key :: Value Pair`'),
        ('registered', True, lconf_to_bool),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    eq_(default_lconf_obj.key_empty_replacementvalue, {
        'age': -1,
        'sex': 'NOT-DEFINED'
    },
        msg=None)

    eq_(type(default_lconf_obj['age']), int, msg=None)
    eq_(default_lconf_obj['age'], -1,
        msg=None)  # `Empty-KeyValuePair-ReplacementValues`
    eq_(type(default_lconf_obj['salary']), float, msg=None)
    eq_(type(default_lconf_obj['registered']), bool, msg=None)

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    eq_(default_lconf_obj.key_empty_replacementvalue, {
        'age': -1,
        'sex': 'NOT-DEFINED'
    },
        msg=None)
Exemple #35
0
def test_lconf_prepare_default_obj__ok0():
    """ Tests: test_lconf_prepare_default_obj__ok0
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok0()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        # Default Comment Line
        ('#2', '# Comment-Line: `Key :: Value Pair`'),
        ('first', ''),
        ('last', ''),
        ('sex', '', None, 'NOT-DEFINED'),
        ('age', ''),
        ('salary', ''),
        ('#3', '# Comment-Line: `Key-Value-List`'),
        ('interests', KVList(True, [])),
        ('#4', '# Comment-Line: `Key :: Value Pair`'),
        ('registered', ''),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    eq_(default_lconf_obj.key_order,
        ['first', 'last', 'sex', 'age', 'salary', 'interests', 'registered'],
        msg=None)
    eq_(default_lconf_obj.key_empty_replacementvalue, {'sex': 'NOT-DEFINED'},
        msg=None)

    eq_(default_lconf_obj.has_comments, False, msg=None)

    eq_(type(default_lconf_obj['age']), str, msg=None)
    eq_(default_lconf_obj['age'], '', msg=None)

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    eq_(default_lconf_obj.key_order, [
        '#1', '#2', 'first', 'last', 'sex', 'age', 'salary', '#3', 'interests',
        '#4', 'registered'
    ],
        msg=None)
    eq_(default_lconf_obj.has_comments, True, msg=None)
def test_lconf_default_comment_lines_ok1():
   """ Tests: test_lconf_default_comment_lines_ok1
   """
   print('::: TEST: test_lconf_default_comment_lines_ok1()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs`
key1 :: value1
key2 :: value2
___END'''

   example_lconf_template = Root([
      ('#1', '# Comment this is a `Default Comment Line` which can be emitted'),
      ('key1', 'default_value1'),
      ('#2', '# this is another `Default Comment Line` which can be emitted'),
      ('key2', 'default_value1'),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_repeated_block_identifier_ok2():
   """ Tests: test_lconf_repeated_block_identifier_ok2
   """
   print('::: TEST: test_lconf_repeated_block_identifier_ok2()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Repeated-Block-Identifier`
# Comment-Line: below is a Main `Repeated-Block-Identifier`
* My_Repeated_Block

   BlockName1
      key1 :: value1
      key2 :: value2
      key3 ::

   BlockName2
      key1 :: value1
      key2 :: value2
      key3 :: value3

___END'''

   example_lconf_template = Root([
      # Comment-Line: Root/Main `Repeated-Block-Identifier`: **min_required_blocks, max_allowed_blocks** set both to 2
      ('My_Repeated_Block', BlkI(2, 2,
         # Comment-Line: Dummy Block
         Blk([
            # Comment-Line: Block key value pair
            ('key1', 'default_value1`'),
            # Comment-Line: Block key value pair with transform_function
            ('key2', 'default_value2', transform_function),
            ('#1', '# Comment: Block key value pair with transform_function and `Empty-KeyValuePair-ReplacementValue`'),
            ('key3', 'default_value3', transform_function, 'empty_replacement_value3'),
         ])
      )),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_main_root_obj_ok():
    """ Tests: test_lconf_main_root_obj_ok
   """
    print('::: TEST: test_lconf_main_root_obj_ok()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF Root
key1 :: value1
key2 :: value2
key3 :: value3
key4 ::
# Comment-Line: Root/Main LCONF-Section END TAG Line
___END'''

    example_lconf_template = Root([
        ('#1', '# Comment-Line: Root/Main key value pair'),
        ('key1', 'default_value1'),
        ('key2', 'default_value2', transform_function),
        ('#2',
         '# Comment-Line: Root/Main key value pair with transform_function and `Empty-KeyValuePair-ReplacementValue`'
         ),
        ('key3', 'default_value3', transform_function,
         'empty_replacement_value3'),
        ('key4', 'default_value4', transform_function,
         'empty_replacement_value4'),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
Exemple #39
0
def test_lconf_prepare_default_obj__ok6():
    """ Tests: test_lconf_prepare_default_obj__ok6
   """
    print('::: TEST: test_lconf_prepare_default_obj__ok6()')

    lconf_section__template_obj = Root([
        # Default Empty Line
        ('#1', ''),
        ('RepeatedBlk1',
         BlkI(-1, -1,
              Blk([
                  ('MyKey1', ''),
                  ('MyKey2', '', None, 'Not-Defined'),
              ]))),
    ])
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    eq_(default_lconf_obj['RepeatedBlk1'], {}, msg=None)

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    eq_(default_lconf_obj, {'RepeatedBlk1': {}, '#1': ''}, msg=None)
def test_lconf_empty_key_value_pair_replacement_ok2():
    """ Tests: test_lconf_empty_key_value_pair_replacement_ok2
   """
    print('::: TEST: test_lconf_empty_key_value_pair_replacement_ok2()')

    lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs` items
# Comment-Line: Root/Main key value pair
key1 :: value1
key2 ::
key3 ::
___END'''

    example_lconf_template = Root([
        ('#1',
         '# Comment Root/Main key value pair - with transform function - with `Empty-KeyValuePair-ReplacementValue`'
         ),
        ('key1', 'default_value1', transform_function,
         'Empty-KeyValuePair-ReplacementValue'),
        # Comment-Line: in the case below: if `key2` is in the `LCONF source` set to empty: the parsed lconf obj will have
        # the `Empty-KeyValuePair-ReplacementValue` -1
        ('key2', 500, lconf_to_int, -1),
        # Comment-Line: in the case below: if `key3` is by default empty: the parsed lconf obj will have
        #     the `Empty-KeyValuePair-ReplacementValue` -1 except the `LCONF source` to be parsed has set it to something
        ('key3', '', lconf_to_float, -999.4),
    ])

    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=True)
    default_lconf_obj = lconf_prepare_default_obj(example_lconf_template,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    example_lconf_template,
                                    validate=False)
def test_lconf_prepare_default_obj__ok2():
   """ Tests: test_lconf_prepare_default_obj__ok2
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok2()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      # Default Comment Line
      ('#2', '# Comment-Line: `Key :: Value Pair`'),
      ('first', ''),
      ('last', ''),
      ('sex', ''),
      ('age', '', lconf_to_int),
      ('salary', 0.0, lconf_to_float),
      ('#3', '# Comment-Line: `Key-Value-Mapping`'),
      ('favorites', KVMap([
         ('food', ''),
         ('sport', '', None, 'Not-Defined'),
         ('color', ''),
      ])),
      ('#4', '# Comment-Line: `Key :: Value Pair`'),
      ('registered', True, lconf_to_bool),
   ])

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   eq_(default_lconf_obj.key_order, ['first', 'last', 'sex', 'age', 'salary', 'favorites', 'registered'], msg=None)
   eq_(default_lconf_obj['favorites'].key_order, ['food', 'sport', 'color'], msg=None)
   eq_(default_lconf_obj['favorites'].key_empty_replacementvalue, {'sport': 'Not-Defined'}, msg=None)

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(
      default_lconf_obj.key_order,
      ['#1', '#2', 'first', 'last', 'sex', 'age', 'salary', '#3', 'favorites', '#4', 'registered'],
      msg=None
   )
   eq_(default_lconf_obj['favorites'].key_order, ['food', 'sport', 'color'], msg=None)
   eq_(default_lconf_obj['favorites'].key_empty_replacementvalue, {'sport': 'Not-Defined'}, msg=None)
def test_lconf_empty_key_value_pair_replacement_ok1():
   """ Tests: test_lconf_empty_key_value_pair_replacement_ok1
   """
   print('::: TEST: test_lconf_empty_key_value_pair_replacement_ok1()')

   lconf_section_raw_str = r'''___SECTION :: Example LCONF `Key :: Value Pairs` items
# Comment-Line: Root/Main key value pair
key1 :: value1
key2 :: Red
key3 ::
___END'''

   example_lconf_template = Root([
      ('#1', '# Comment: Root/Main key value pair - no transform function - with  `Empty-KeyValuePair-ReplacementValue`'),
      ('key1', 'default_value1', None, 'Empty-KeyValuePair-ReplacementValue'),
      ('key2', 'Blue', None, 'NO-COLOR-DEFINED'),
      ('key3', 'Blue', None, 'NO-COLOR-DEFINED'),
   ])

   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=True)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=True)
   default_lconf_obj = lconf_prepare_default_obj(example_lconf_template, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, example_lconf_template, validate=False)
def test_lconf_prepare_default_obj__ok0():
   """ Tests: test_lconf_prepare_default_obj__ok0
   """
   print('::: TEST: test_lconf_prepare_default_obj__ok0()')

   lconf_section__template_obj = Root([
      # Default Empty Line
      ('#1', ''),
      # Default Comment Line
      ('#2', '# Comment-Line: `Key :: Value Pair`'),
      ('first', ''),
      ('last', ''),
      ('sex', '', None, 'NOT-DEFINED'),
      ('age', ''),
      ('salary', ''),
      ('#3', '# Comment-Line: `Key-Value-List`'),
      ('interests', KVList(True, [])),
      ('#4', '# Comment-Line: `Key :: Value Pair`'),
      ('registered', ''),
   ])
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   eq_(default_lconf_obj.key_order, ['first', 'last', 'sex', 'age', 'salary', 'interests', 'registered'], msg=None)
   eq_(default_lconf_obj.key_empty_replacementvalue, {'sex': 'NOT-DEFINED'}, msg=None)

   eq_(default_lconf_obj.has_comments, False, msg=None)

   eq_(type(default_lconf_obj['age']), str, msg=None)
   eq_(default_lconf_obj['age'], '', msg=None)

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(
      default_lconf_obj.key_order,
      ['#1', '#2', 'first', 'last', 'sex', 'age', 'salary', '#3', 'interests', '#4', 'registered'],
      msg=None
   )
   eq_(default_lconf_obj.has_comments, True, msg=None)
def test_lconf_section_splitlines__missing_identifier__expect_failure():
    """ Tests: test_lconf_section_splitlines__missing_identifier__expect_failure
   """
    print(
        '::: TEST: test_lconf_section_splitlines__missing_identifier__expect_failure()'
    )

    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 :: Test Example1

# Comment-Line: `Key :: Value Pair`
first :: Joe
last :: Smith
sex :: m
age :: 18
salary :: 12500
# Comment-Line
interests
   soccer
   tennis

# Comment-Line: `Key :: Value Pair`
registered :: False
___END
'''
    lconf_validate_one_section_str(lconf_section_raw_str)
    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=False)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
def test_lconf_section_splitlines__limited_number_of_blocks__expect_failure2():
    """ Tests: test_lconf_section_splitlines__limited_number_of_blocks__expect_failure2
   """
    print(
        '::: TEST: test_lconf_section_splitlines__limited_number_of_blocks__expect_failure2()'
    )

    # Main `Section-Template OBJ: type: Root
    lconf_section__template_obj = Root([
        ('RepeatedBlk1',
         BlkI(
             0, 1,
             Blk([
                 ('#1', '# Comment-Line: below Block-Item'),
                 ('blk_key1', ''),
                 ('blk_key2', 9999.999, lconf_to_float),
             ]))), ('key', '')
    ])

    lconf_section_raw_str = r'''___SECTION :: TestExample

# test comment

* RepeatedBlk1
   BLK0
      blk_key1 :: value
      blk_key2 :: -1

   BLK1
      blk_key1 :: value
      blk_key2 :: -1

key :: value
___END
'''
    lconf_validate_one_section_str(lconf_section_raw_str)
    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=True)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
def test_lconf_section_splitlines__missing_identifier__expect_failure():
   """ Tests: test_lconf_section_splitlines__missing_identifier__expect_failure
   """
   print('::: TEST: test_lconf_section_splitlines__missing_identifier__expect_failure()')

   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 :: Test Example1

# Comment-Line: `Key :: Value Pair`
first :: Joe
last :: Smith
sex :: m
age :: 18
salary :: 12500
# Comment-Line
interests
   soccer
   tennis

# Comment-Line: `Key :: Value Pair`
registered :: False
___END
'''
   lconf_validate_one_section_str(lconf_section_raw_str)
   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=False)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)
Exemple #47
0
def test_lconf_emit_expect_failure1():
    """ Tests: test_lconf_emit_expect_failure1
   """
    print('::: TEST: test_lconf_emit_expect_failure1()')

    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 :: Test Example1

# Comment-Line: `Key :: Value Pair`
first :: Joe
last :: Smith
sex :: m
age :: 18
salary :: 12500
# Comment-Line: `Key-Value-List`
- interests :: soccer,tennis
# Comment-Line: `Key :: Value Pair`
registered :: False
___END'''

    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)

    emit_result = lconf_emit(default_lconf_obj,
                             onelinelists=LCONF_DEFAULT,
                             empty_key_value_pair=True)
    eq_(lconf_section_raw_str, emit_result, msg=None)
def test_lconf_section_splitlines_expect_failure2():
    """ Tests: test_lconf_section_splitlines_expect_failure2
   """
    print('::: TEST: test_lconf_section_splitlines_expect_failure2()')

    # Main `Section-Template OBJ: type: Root
    lconf_section__template_obj = Root([
        ('#1',
         '# Comment-Line: below is a Main `List-Of-Tuples` with 4 columns: |Color Name|Red|Green|Blue|'
         ),
        ('list_of_color_tuples',
         ListOT(('Color Name', 'Red', 'Green', 'Blue'), [],
                column_replace_missing=('Not Defined', '-1', '-1', '-1')),
         (None, lconf_to_int, lconf_to_int, lconf_to_int)),
        ('mapping', KVMap([
            ('key1', ''),
            ('key2', ''),
        ])),
    ])

    lconf_section_raw_str = r'''___SECTION :: TestExample

# Comment-Line: below is a Main `List-Of-Tuples` with 4 items: |Color Name|Red|Green|Blue|
- list_of_color_tuples |Color Name|Red|Green|Blue|
   # Comment-Line: `List-Of-Tuples` item lines (rows)
   forestgreen,   ,   139,  34
   brick,         156,  102,  31
. mapping
   key1 ::

      # Wrong comment Indent
   key2 :: value
___END
'''
    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=True)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
Exemple #49
0
def test_lconf_emit_expect_failure1():
   """ Tests: test_lconf_emit_expect_failure1
   """
   print('::: TEST: test_lconf_emit_expect_failure1()')

   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 :: Test Example1

# Comment-Line: `Key :: Value Pair`
first :: Joe
last :: Smith
sex :: m
age :: 18
salary :: 12500
# Comment-Line: `Key-Value-List`
- interests :: soccer,tennis
# Comment-Line: `Key :: Value Pair`
registered :: False
___END'''

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)

   emit_result = lconf_emit(default_lconf_obj, onelinelists=LCONF_DEFAULT, empty_key_value_pair=True)
   eq_(lconf_section_raw_str, emit_result, msg=None)
def test_lconf_section_splitlines__trailing_space__expect_failure():
   """ Tests: test_lconf_section_splitlines__trailing_space__expect_failure
   """
   print('::: TEST: test_lconf_section_splitlines__trailing_space__expect_failure()')

   # Main `Section-Template OBJ: type: Root
   lconf_section__template_obj = Root([
      ('#1', '# Comment-Line'),
      ('key1value_pair', ''),
      ('key2value_pair', 9999.999, lconf_to_float),
      ('key3value_pair', '')
   ])

   path_to_lconf_file = path_join(SCRIPT_PATH, 'example_to_validate_with_err6.lconf')
   with open(path_to_lconf_file, 'r') as file_:
      lconf_section_raw_str = lconf_extract_one_section_by_name(file_.read(), 'Example')

   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=False)
   for line in section_lines:
      print('<{}>'.format(line))
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)
def test_lconf_parse_section_ok1():
    """ Tests: test_lconf_parse_section_ok1
   """
    print('::: TEST: test_lconf_parse_section_ok1()')

    lconf_section__template_obj = Root([
        ('keyvalue_mapping',
         KVMap([
             ('#1',
              '# Comment-Line:  Key-Value-Mapping items: `Key :: Value Pairs`'
              ),
             ('mapping_key1', 'default'),
             ('mapping_key2', 'default'),
             ('mapping_key3', 'default'),
         ])),
    ])

    lconf_section_raw_str = r'''___SECTION :: Test Example1

. keyvalue_mapping
   mapping_key1 :: Something
   mapping_key2 :: Something2
   mapping_key3 :: Something3
___END
'''
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section(default_lconf_obj,
                                    lconf_section_raw_str,
                                    lconf_section__template_obj,
                                    validate=True)

    ok_(isinstance(lconf_obj, LconfRoot), msg=None)
    ok_(isinstance(lconf_obj['keyvalue_mapping'], LconfKVMap), msg=None)
    eq_(lconf_obj['keyvalue_mapping']['mapping_key1'], 'Something', msg=None)
    eq_(lconf_obj['keyvalue_mapping']['mapping_key3'], 'Something3', msg=None)
    eq_(lconf_obj['keyvalue_mapping'].key_order,
        ['mapping_key1', 'mapping_key2', 'mapping_key3'],
        msg=None)
def test_lconf_section_splitlines_expect_failure2():
   """ Tests: test_lconf_section_splitlines_expect_failure2
   """
   print('::: TEST: test_lconf_section_splitlines_expect_failure2()')

   # Main `Section-Template OBJ: type: Root
   lconf_section__template_obj = Root([
      ('#1', '# Comment-Line: below is a Main `List-Of-Tuples` with 4 columns: |Color Name|Red|Green|Blue|'),
      ('list_of_color_tuples', ListOT(
         ('Color Name', 'Red', 'Green', 'Blue'),
         [],
         column_replace_missing=('Not Defined', '-1', '-1', '-1')
      ),
      (None, lconf_to_int, lconf_to_int, lconf_to_int)),
      ('mapping', KVMap([
         ('key1', ''),
         ('key2', ''),
      ])),
   ])

   lconf_section_raw_str = r'''___SECTION :: TestExample

# Comment-Line: below is a Main `List-Of-Tuples` with 4 items: |Color Name|Red|Green|Blue|
- list_of_color_tuples |Color Name|Red|Green|Blue|
   # Comment-Line: `List-Of-Tuples` item lines (rows)
   forestgreen,   ,   139,  34
   brick,         156,  102,  31
. mapping
   key1 ::

      # Wrong comment Indent
   key2 :: value
___END
'''
   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=True)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)
def test_lconf_section_splitlines__limited_number_of_blocks__expect_failure2():
   """ Tests: test_lconf_section_splitlines__limited_number_of_blocks__expect_failure2
   """
   print('::: TEST: test_lconf_section_splitlines__limited_number_of_blocks__expect_failure2()')

   # Main `Section-Template OBJ: type: Root
   lconf_section__template_obj = Root([
      ('RepeatedBlk1', BlkI(0, 1,
         Blk([
            ('#1', '# Comment-Line: below Block-Item'),
            ('blk_key1', ''),
            ('blk_key2', 9999.999, lconf_to_float),
         ])
      )),
      ('key', '')
   ])

   lconf_section_raw_str = r'''___SECTION :: TestExample

# test comment

* RepeatedBlk1
   BLK0
      blk_key1 :: value
      blk_key2 :: -1

   BLK1
      blk_key1 :: value
      blk_key2 :: -1

key :: value
___END
'''
   lconf_validate_one_section_str(lconf_section_raw_str)
   section_lines, section_name = lconf_section_splitlines(lconf_section_raw_str, validate_first_line=True)
   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines, section_name, lconf_section__template_obj)
def test_lconf_prepare_default_obj__parse_section_lines__base_example_ok():
    """ Tests: test_lconf_prepare_default_obj__parse_section_lines__base_example_ok
   """
    print(
        '::: TEST: test_lconf_prepare_default_obj__parse_section_lines__base_example_ok()'
    )

    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_validate_one_section_str(lconf_section_raw_str)
    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=True)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)

    ok_(isinstance(lconf_obj, LconfRoot), msg=None)
    ok_(isinstance(lconf_obj['key10value_mapping'], LconfKVMap), msg=None)
    ok_(isinstance(lconf_obj['key1value_pair'], str), msg=None)
    ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key4_list'],
                   LconfKVList),
        msg=None)
    ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key5_list'],
                   LconfKVList),
        msg=None)
    ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key6_list'],
                   LconfListOT),
        msg=None)
    ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key7_list'],
                   LconfListOT),
        msg=None)
    ok_(isinstance(lconf_obj['key11value_mapping'], LconfKVMap), msg=None)
    ok_(isinstance(lconf_obj['key11value_mapping']['mapping11_key2_mapping'],
                   LconfKVMap),
        msg=None)
    ok_(isinstance(
        lconf_obj['key11value_mapping']['mapping11_key2_mapping']
        ['mapping11_key2_nested_mapping_key2_block_identifier'], LconfBlkI),
        msg=None)
    ok_(isinstance(
        lconf_obj['key11value_mapping']['mapping11_key2_mapping']
        ['mapping11_key2_nested_mapping_key2_block_identifier']
        ['sky_blue_blk_name1'], LconfBlk),
        msg=None)
    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)
    ok_(isinstance(
        lconf_obj['key11value_mapping']['mapping11_key2_mapping']
        ['mapping11_key2_nested_mapping_key1'], datetime),
        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)

    ok_(isinstance(lconf_obj['key14list_of_color_tuples'], LconfListOT),
        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)

    ok_(isinstance(lconf_obj['RepeatedBlk1'], LconfBlkI), 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)

    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=False)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
def test_lconf_prepare_default_obj__parse_section_lines_ok3():
    """ Tests: test_lconf_prepare_default_obj__parse_section_lines_ok3
   """
    print(
        '::: TEST: test_lconf_prepare_default_obj__parse_section_lines_ok3()')

    # Main `Section-Template OBJ: type: Root
    lconf_section__template_obj = Root([
        ('#1',
         '# Comment-Line: below is a Main `List-Of-Tuples` with 4 columns: |Color Name|Red|Green|Blue|'
         ),
        ('list_of_color_tuples',
         ListOT(('Color Name', 'Red', 'Green', 'Blue'), [],
                column_replace_missing=('Not Defined', '-1', '-1', '-1')),
         (None, lconf_to_int, lconf_to_int, lconf_to_int)),
        ('#2',
         '# Comment-Line: below is a Main `List-Of-Tuples` with 3 columns: |a|b|c|'
         ),
        ('list_of_tuples2',
         ListOT(('a', 'b', 'c'), [('1', '2', '3'), ('44', '55', '66')],
                column_replace_missing=('-1', '-1', '-1')),
         (lconf_to_int, lconf_to_int, lconf_to_int)),
        ('#3', '# Comment-Line: using one transform function for all'),
        ('list_of_tuples3',
         ListOT(
             ('a', 'b', 'c'), [('1.0', '2.0', '3.0'),
                               ('44.0', '55.0', '66.0')],
             column_replace_missing=('-1.0', '-1.0', '-1.0')), lconf_to_float),
    ])

    lconf_section_raw_str = r'''___SECTION :: TestExample

# Comment-Line: below is a Main `List-Of-Tuples` with 4 items: |Color Name|Red|Green|Blue|
- list_of_color_tuples |Color Name|Red|Green|Blue|
   # Comment-Line: `List-Of-Tuples` item lines (rows)
   forestgreen,   ,   139,  34
   brick,         156,  102,  31

- list_of_tuples2 |a|b|c|
   100,,300
   400,500,600

- list_of_tuples3 |a|b|c|
   100.0,,300.0
   400.0,500.0,600.0

___END
'''
    lconf_validate_one_section_str(lconf_section_raw_str)
    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=True)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)

    ok_(isinstance(lconf_obj, LconfRoot), msg=None)
    ok_(isinstance(lconf_obj['list_of_color_tuples'], LconfListOT), msg=None)
    ok_(isinstance(lconf_obj['list_of_tuples2'], LconfListOT), msg=None)
    ok_(isinstance(lconf_obj['list_of_tuples3'], LconfListOT), msg=None)

    eq_(lconf_obj['list_of_color_tuples'][0], ('forestgreen', -1, 139, 34),
        msg=None)
    eq_(lconf_obj['list_of_tuples2'][0], (100, -1, 300), msg=None)
    eq_(lconf_obj['list_of_tuples3'][0], (100.0, -1.0, 300.0), msg=None)

    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=False)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
def test_lconf_prepare_default_obj__parse_section_lines_ok1():
    """ Tests: test_lconf_prepare_default_obj__parse_section_lines_ok1
   """
    print(
        '::: TEST: test_lconf_prepare_default_obj__parse_section_lines_ok1()')

    lconf_section__template_obj = Root([
        ('keyvalue_mapping',
         KVMap([
             ('#1',
              '# Comment-Line:  Key-Value-Mapping items: `Key :: Value Pairs`'
              ),
             ('mapping1_key1', 'default'),
             ('mapping1_key2', 'default'),
             ('mapping1_key3', 'default'),
         ])),
        ('keyvalue_mapping2', KVMap([
            ('mapping2_key1', 'default'),
        ])),
        ('keyvalue_mapping3', KVMap([
            ('mapping3_key1', 'default'),
        ])),
    ])

    lconf_section_raw_str = r'''___SECTION :: Test Example1

# Comment: Key-Value-Mapping
. keyvalue_mapping
   mapping1_key1 :: Something
   mapping1_key2 :: Something2
   mapping1_key3 :: Something3

# Comment: empty Key-Value-Mapping: uses all default values similar if it would not be defined
. keyvalue_mapping2
___END
'''
    lconf_validate_one_section_str(lconf_section_raw_str)
    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=True)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=False)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)

    ok_(isinstance(lconf_obj, LconfRoot), msg=None)
    ok_(isinstance(lconf_obj['keyvalue_mapping'], LconfKVMap), msg=None)
    eq_(lconf_obj['keyvalue_mapping']['mapping1_key1'], 'Something', msg=None)
    eq_(lconf_obj['keyvalue_mapping']['mapping1_key3'], 'Something3', msg=None)
    eq_(lconf_obj['keyvalue_mapping'].key_order,
        ['mapping1_key1', 'mapping1_key2', 'mapping1_key3'],
        msg=None)

    ok_(isinstance(lconf_obj['keyvalue_mapping2'], LconfKVMap), msg=None)
    eq_(lconf_obj['keyvalue_mapping2']['mapping2_key1'], 'default', msg=None)

    ok_(isinstance(lconf_obj['keyvalue_mapping3'], LconfKVMap), msg=None)
    eq_(lconf_obj['keyvalue_mapping3']['mapping3_key1'], 'default', msg=None)

    section_lines, section_name = lconf_section_splitlines(
        lconf_section_raw_str, validate_first_line=False)
    default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj,
                                                  with_comments=True)
    lconf_obj = lconf_parse_section_lines(default_lconf_obj, section_lines,
                                          section_name,
                                          lconf_section__template_obj)
def main():
   # ---------------------------------- EXAMPLE 4 a ---------------------------------- #

   # EXAMPLE 4 a: ONLY VALIDATE
   lconf_validate_one_section_str(lconf_section__example_4a_lconf_section_raw_str)

   # EXAMPLE 4 a: ONLY PREPARE DEFAULT OBJ
   lconf_default_obj = lconf_prepare_default_obj(lconf_section__example_4a__template_obj, with_comments=False)
   print('\n\n============== EXAMPLE 4 a: ONLY PREPARE DEFAULT OBJ ==============\n')
   print(lconf_default_obj)

   # EXAMPLE 4 a: VALIDATE, PREPARE, PARSE:
   # validate a `LCONF-Section string` and prepare a default lconf obj from the template obj and parse the LCONF-Section
   print('\n\n============== EXAMPLE 4 a: VALIDATE, PREPARE, PARSE ==============\n')
   lconf_parse_obj = lconf_prepare_and_parse_section(
      lconf_section__example_4a_lconf_section_raw_str,
      lconf_section__example_4a__template_obj,
      with_comments=True,
      validate=True
   )
   print(lconf_parse_obj)

   # EXAMPLE 4 a: EXTRACT KNOWN SECTION, VALIDATE, PREPARE, PARSE: this is also useful to extract from files
   lconf_parse_obj = lconf_parse_section_extract_by_name(
      lconf_section__example_4a_lconf_section_raw_str,
      'EXAMPLE 4 a',
      lconf_section__example_4a__template_obj,
      with_comments=True,
      validate=True
   )
   print(
      '\n\n============== EXAMPLE 4 a: EXTRACT KNOWN SECTION, VALIDATE, PREPARE, PARSE: also for files ==============\n')
   print(lconf_parse_obj)

   # EXAMPLE 4 a: ACCESS The Section-INFO
   print('\n\n============== EXAMPLE 4 a: ACCESS The Section-INFO ==============\n')
   print('  lconf_parse_obj.key_order: ', lconf_parse_obj.key_order)
   print('  lconf_parse_obj.section_name: ', lconf_parse_obj.section_name)
   print('  lconf_parse_obj.is_parsed: ', lconf_parse_obj.is_parsed)
   print('  lconf_parse_obj.has_comments: ', lconf_parse_obj.has_comments)

   # EXAMPLE 4 a: EMIT DEFAULT OBJ
   lconf_section_emitted_default_obj_str = lconf_emit_default_obj(
      lconf_section__example_4a__template_obj,
      'EMITTED EXAMPLE 4 a',
      onelinelists=LCONF_DEFAULT,
      with_comments=True
   )
   print('\n\n============== EXAMPLE 4 a: EMIT DEFAULT OBJ ==============\n')
   print(lconf_section_emitted_default_obj_str)

   # EXAMPLE: EMIT PARSED LCONF OBJ
   lconf_parse_obj = lconf_parse_section_extract_by_name(
      lconf_section__example_4a_lconf_section_raw_str,
      'EXAMPLE 4 a',
      lconf_section__example_4a__template_obj,
      with_comments=True,
      validate=True
   )
   lconf_section_emitted_parsed_obj_str = lconf_emit(lconf_parse_obj, onelinelists=LCONF_DEFAULT)

   print('\n\n============== EXAMPLE 4 a: EMIT PARSED LCONF OBJ ==============\n')
   print(lconf_section_emitted_parsed_obj_str)

   # EXAMPLE 4 a: EMIT TO JSON
   lconf_parse_obj = lconf_parse_section_extract_by_name(
      lconf_section__example_4a_lconf_section_raw_str,
      'EXAMPLE 4 a',
      lconf_section__example_4a__template_obj,
      with_comments=False,
      validate=True
   )
   result_ordered_native_type = lconf_to_ordered_native_type(lconf_parse_obj)
   dump_json = json_dumps(result_ordered_native_type, indent=3)

   print('\n\n============== EXAMPLE 4 a: EMIT TO ORDERED JSON ==============\n')
   print(dump_json)

   # EXAMPLE: EMIT TO YAML
   if has_yaml:
      lconf_parse_obj = lconf_parse_section_extract_by_name(
         lconf_section__example_4a_lconf_section_raw_str,
         'EXAMPLE 4 a',
         lconf_section__example_4a__template_obj,
         with_comments=False,
         validate=True
      )
      result_native_type = lconf_to_native_type(lconf_parse_obj)
      dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True)

      print('\n\n============== EXAMPLE 4 a: EMIT TO YAML ==============\n')
      print(dump_yaml)


   # ---------------------------------- EXAMPLE 4 b ---------------------------------- #

   # EXAMPLE 4 b: ONLY VALIDATE
   lconf_validate_one_section_str(lconf_section__example_4b_lconf_section_raw_str)

   # EXAMPLE 4 b: ONLY PREPARE DEFAULT OBJ
   lconf_default_obj = lconf_prepare_default_obj(lconf_section__example_4b__template_obj, with_comments=False)
   print('\n\n============== EXAMPLE 4 b: ONLY PREPARE DEFAULT OBJ ==============\n')
   print(lconf_default_obj)

   # EXAMPLE 4 b: VALIDATE, PREPARE, PARSE:
   # validate a `LCONF-Section string` and prepare a default lconf obj from the template obj and parse the LCONF-Section
   print('\n\n============== EXAMPLE 4 b: VALIDATE, PREPARE, PARSE ==============\n')
   lconf_parse_obj = lconf_prepare_and_parse_section(
      lconf_section__example_4b_lconf_section_raw_str,
      lconf_section__example_4b__template_obj,
      with_comments=True,
      validate=True
   )
   print(lconf_parse_obj)

   # EXAMPLE 4 b: EXTRACT KNOWN SECTION, VALIDATE, PREPARE, PARSE: this is also useful to extract from files
   lconf_parse_obj = lconf_parse_section_extract_by_name(
      lconf_section__example_4b_lconf_section_raw_str,
      'EXAMPLE 4 b',
      lconf_section__example_4b__template_obj,
      with_comments=True,
      validate=True
   )
   print(
      '\n\n============== EXAMPLE 4 b: EXTRACT KNOWN SECTION, VALIDATE, PREPARE, PARSE: also for files ==============\n')
   print(lconf_parse_obj)

   # EXAMPLE 4 b: ACCESS The Section-INFO
   print('\n\n============== EXAMPLE 4 b: ACCESS The Section-INFO ==============\n')
   print('  lconf_parse_obj.key_order: ', lconf_parse_obj.key_order)
   print('  lconf_parse_obj.section_name: ', lconf_parse_obj.section_name)
   print('  lconf_parse_obj.is_parsed: ', lconf_parse_obj.is_parsed)
   print('  lconf_parse_obj.has_comments: ', lconf_parse_obj.has_comments)

   # EXAMPLE 4 b: EMIT DEFAULT OBJ
   lconf_section_emitted_default_obj_str = lconf_emit_default_obj(
      lconf_section__example_4b__template_obj,
      'EMITTED EXAMPLE 4 b',
      onelinelists=LCONF_DEFAULT,
      with_comments=True
   )
   print('\n\n============== EXAMPLE 4 b: EMIT DEFAULT OBJ ==============\n')
   print(lconf_section_emitted_default_obj_str)

   # EXAMPLE: EMIT PARSED LCONF OBJ
   lconf_parse_obj = lconf_parse_section_extract_by_name(
      lconf_section__example_4b_lconf_section_raw_str,
      'EXAMPLE 4 b',
      lconf_section__example_4b__template_obj,
      with_comments=True,
      validate=True
   )
   lconf_section_emitted_parsed_obj_str = lconf_emit(lconf_parse_obj, onelinelists=LCONF_DEFAULT)

   print('\n\n============== EXAMPLE 4 b: EMIT PARSED LCONF OBJ ==============\n')
   print(lconf_section_emitted_parsed_obj_str)

   # EXAMPLE 4 b: EMIT TO JSON
   lconf_parse_obj = lconf_parse_section_extract_by_name(
      lconf_section__example_4b_lconf_section_raw_str,
      'EXAMPLE 4 b',
      lconf_section__example_4b__template_obj,
      with_comments=False,
      validate=True
   )
   result_ordered_native_type = lconf_to_ordered_native_type(lconf_parse_obj)
   dump_json = json_dumps(result_ordered_native_type, indent=3)

   print('\n\n============== EXAMPLE 4 b: EMIT TO ORDERED JSON ==============\n')
   print(dump_json)

   # EXAMPLE: EMIT TO YAML
   if has_yaml:
      lconf_parse_obj = lconf_parse_section_extract_by_name(
         lconf_section__example_4b_lconf_section_raw_str,
         'EXAMPLE 4 b',
         lconf_section__example_4b__template_obj,
         with_comments=False,
         validate=True
      )
      result_native_type = lconf_to_native_type(lconf_parse_obj)
      dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True)

      print('\n\n============== EXAMPLE 4 b: EMIT TO YAML ==============\n')
      print(dump_yaml)
def main():
    pass

    # EXAMPLE: ONLY VALIDATE
    lconf_validate_one_section_str(
        lconf_section__base_example_lconf_section_raw_str)

    # EXAMPLE: ONLY PREPARE DEFAULT OBJ
    lconf_default_obj = lconf_prepare_default_obj(
        lconf_section__base_example_template_obj, with_comments=False)
    print(
        '\n\n============== EXAMPLE: ONLY PREPARE DEFAULT OBJ ==============\n'
    )
    print(lconf_default_obj)

    # EXAMPLE: VALIDATE, PREPARE, PARSE:
    # validate a `LCONF-Section string` and prepare a default lconf obj from the template obj and parse the LCONF-Section
    print(
        '\n\n============== EXAMPLE: VALIDATE, PREPARE, PARSE ==============\n'
    )
    lconf_parse_obj = lconf_prepare_and_parse_section(
        lconf_section__base_example_lconf_section_raw_str,
        lconf_section__base_example_template_obj,
        with_comments=True,
        validate=True)
    print(lconf_parse_obj)

    # EXAMPLE: EXTRACT KNOWN SECTION, VALIDATE, PREPARE, PARSE: this is also useful to extract from files
    lconf_parse_obj = lconf_parse_section_extract_by_name(
        lconf_section__base_example_lconf_section_raw_str,
        'BaseEXAMPLE',
        lconf_section__base_example_template_obj,
        with_comments=True,
        validate=True)
    print(
        '\n\n============== EXAMPLE: EXTRACT KNOWN SECTION, VALIDATE, PREPARE, PARSE: also for files ==============\n'
    )
    print(lconf_parse_obj)

    # EXAMPLE: ACCESS The Section-INFO
    print(
        '\n\n============== EXAMPLE: ACCESS The Section-INFO ==============\n')
    print(('  lconf_parse_obj.key_order: ', lconf_parse_obj.key_order))
    print(('  lconf_parse_obj.key_empty_replacementvalue: ',
           lconf_parse_obj.key_empty_replacementvalue))
    print(('  lconf_parse_obj.section_name: ', lconf_parse_obj.section_name))
    print(('  lconf_parse_obj.is_parsed: ', lconf_parse_obj.is_parsed))
    print(('  lconf_parse_obj.has_comments: ', lconf_parse_obj.has_comments))

    # EXAMPLE: EMIT DEFAULT OBJ
    lconf_section_emitted_default_obj_str = lconf_emit_default_obj(
        lconf_section__base_example_template_obj,
        'EMITTED BaseEXAMPLE',
        onelinelists=LCONF_DEFAULT,
        with_comments=True)
    print('\n\n============== EXAMPLE: EMIT DEFAULT OBJ (==============\n')
    print(lconf_section_emitted_default_obj_str)

    # EXAMPLE: EMIT PARSED LCONF OBJ
    lconf_parse_obj = lconf_parse_section_extract_by_name(
        lconf_section__base_example_lconf_section_raw_str,
        'BaseEXAMPLE',
        lconf_section__base_example_template_obj,
        with_comments=True,
        validate=True)
    lconf_section_emitted_parsed_obj_str = lconf_emit(
        lconf_parse_obj, onelinelists=LCONF_DEFAULT, empty_key_value_pair=True)

    print(
        '\n\n============== EXAMPLE: EMIT PARSED LCONF OBJ (empty_key_value_pair=True) ==============\n'
    )
    print(lconf_section_emitted_parsed_obj_str)

    lconf_section_emitted_parsed_obj_str = lconf_emit(
        lconf_parse_obj,
        onelinelists=LCONF_DEFAULT,
        empty_key_value_pair=False)
    print(
        '\n\n============== EXAMPLE: EMIT PARSED LCONF OBJ (empty_key_value_pair=False) ==============\n'
    )
    print(lconf_section_emitted_parsed_obj_str)

    # EXAMPLE: EMIT TO JSON
    lconf_parse_obj = lconf_parse_section_extract_by_name(
        lconf_section__base_example_lconf_section_raw_str,
        'BaseEXAMPLE',
        lconf_section__base_example_template_obj,
        with_comments=False,
        validate=True)
    result_ordered_native_type = lconf_to_ordered_native_type(lconf_parse_obj)
    # 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'
    dump_json = json_dumps(result_ordered_native_type, indent=3)

    print('\n\n============== EXAMPLE: EMIT TO ORDERED JSON ==============\n')
    print(dump_json)

    # EXAMPLE: EMIT TO YAML
    if has_yaml:
        lconf_parse_obj = lconf_parse_section_extract_by_name(
            lconf_section__base_example_lconf_section_raw_str,
            'BaseEXAMPLE',
            lconf_section__base_example_template_obj,
            with_comments=False,
            validate=True)
        result_native_type = lconf_to_native_type(lconf_parse_obj)
        #  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'
        dump_yaml = yaml_dump(result_native_type, indent=3, allow_unicode=True)

        print('\n\n============== EXAMPLE: EMIT TO YAML ==============\n')
        print(dump_yaml)
def test_lconf_prepare_default_obj__baseexample_ok():
   """ Tests: test_lconf_prepare_default_obj__baseexample_ok
   """
   print('::: TEST: test_lconf_prepare_default_obj__baseexample_ok()')

   lconf_section__template_obj = get_lconf_section__base_example_template_obj()

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)

   eq_(default_lconf_obj.key_empty_replacementvalue, {'key7value_pair': -94599.5, 'key1value_pair': 'NOT-DEFINED'}, msg=None)
   eq_(
      default_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_(default_lconf_obj['key10value_mapping'].key_empty_replacementvalue, {}, msg=None)
   eq_(
      default_lconf_obj['key10value_mapping'].key_order,
      [
         'mapping10_key1',
         'mapping10_key2',
         'mapping10_key3',
         'mapping10_key4_list',
         'mapping10_key5_list',
         'mapping10_key6_list',
         'mapping10_key7_list'
      ],
      msg=None
   )

   eq_(default_lconf_obj['key1value_pair'], 'NOT-DEFINED', msg=None)
   eq_(default_lconf_obj['key7value_pair'], -94599.5, msg=None)

   eq_(default_lconf_obj['key10value_mapping']['mapping10_key7_list'].column_names, ('name', 'b', 'c'), msg=None)
   eq_(default_lconf_obj['key11value_mapping']['mapping11_key2_mapping'].key_empty_replacementvalue, {}, msg=None)
   eq_(
      default_lconf_obj['key11value_mapping']['mapping11_key2_mapping'].key_order,
      [
         'mapping11_key2_nested_mapping_key1',
         'mapping11_key2_nested_mapping_key2_block_identifier',
         'mapping11_key2_nested_mapping_key3',
         'mapping11_key2_nested_mapping_key4_list'
      ],
      msg=None
   )

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=True)
   eq_(
      default_lconf_obj.key_order,
      [
         '#1',
         '#2a',
         '#2b',
         'key1value_pair',
         '#3',
         'key2value_pair',
         '#4',
         'key3value_pair',
         'key4value_pair',
         'key5value_pair',
         'key6value_pair',
         '#5a',
         '#5b',
         'key7value_pair',
         'key8value_pair',
         'key9value_pair',
         '#6',
         '#7',
         'key10value_mapping',
         '#16',
         '#17',
         'key11value_mapping',
         '#28',
         '#29',
         'key12list',
         '#30',
         '#31',
         'key13value_pairlist',
         '#32',
         '#33',
         'key14list_of_color_tuples',
         '#34',
         '#35',
         'key15value_pairlist',
         '#36',
         '#37',
         'key16value_pairlist',
         '#38',
         '#39',
         'key17list_of_tuples',
         '#40',
         '#41',
         'RepeatedBlk1',
      ],
      msg=None
   )
   eq_(default_lconf_obj['key1value_pair'], 'NOT-DEFINED', msg=None)
   eq_(default_lconf_obj['key7value_pair'], -94599.5, msg=None)

   eq_(default_lconf_obj['key10value_mapping']['mapping10_key7_list'].column_names, ('name', 'b', 'c'), msg=None)
   eq_(default_lconf_obj['key11value_mapping']['mapping11_key2_mapping'].key_empty_replacementvalue, {}, msg=None)
Exemple #60
0
def test_lconf_parse_section_ok2():
   """ Tests: test_lconf_parse_section_ok2
   """
   print('::: TEST: test_lconf_parse_section_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()

   default_lconf_obj = lconf_prepare_default_obj(lconf_section__template_obj, with_comments=False)
   lconf_obj = lconf_parse_section(default_lconf_obj, lconf_section_raw_str, lconf_section__template_obj, validate=True)

   ok_(isinstance(lconf_obj, LconfRoot), msg=None)
   ok_(isinstance(lconf_obj['key10value_mapping'], LconfKVMap), msg=None)
   ok_(isinstance(lconf_obj['key1value_pair'], str), msg=None)
   ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key4_list'], LconfKVList), msg=None)
   ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key5_list'], LconfKVList), msg=None)
   ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key6_list'], LconfListOT), msg=None)
   ok_(isinstance(lconf_obj['key10value_mapping']['mapping10_key7_list'], LconfListOT), msg=None)
   ok_(isinstance(lconf_obj['key11value_mapping'], LconfKVMap), msg=None)
   ok_(isinstance(lconf_obj['key11value_mapping']['mapping11_key2_mapping'], LconfKVMap), msg=None)
   ok_(isinstance(
      lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key2_block_identifier'],
      LconfBlkI),
      msg=None)
   ok_(isinstance(
      lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key2_block_identifier'][
         'sky_blue_blk_name1'],
      LconfBlk),
      msg=None)
   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)
   ok_(isinstance(
      lconf_obj['key11value_mapping']['mapping11_key2_mapping']['mapping11_key2_nested_mapping_key1'],
      datetime),
      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)

   ok_(isinstance(lconf_obj['key14list_of_color_tuples'], LconfListOT), 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)

   ok_(isinstance(lconf_obj['RepeatedBlk1'], LconfBlkI), 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)