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

   obj_ = BlkI(-1, -1, Blk([('key', 'value')]))
   obj_.set_class__dict__item('mydata', 'new value')
   eq_(obj_.mydata, 'new value', msg=None)

   obj_.__reduce__()
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)
Exemple #3
0
def test_lconf_structure_classes4():
    """ Tests: test_lconf_structure_classes4
   """
    print('::: TEST: test_lconf_structure_classes4()')

    obj_ = BlkI(-1, -1, Blk([('key', 'value')]))
    obj_.set_class__dict__item('mydata', 'new value')
    eq_(obj_.mydata, 'new value', msg=None)

    obj_.__reduce__()
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)
Exemple #5
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)
Exemple #6
0
def test_lconf_structure_classes3_expect_failure():
    """ Tests: test_lconf_structure_classes3_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes3_expect_failure()')

    BlkI(-1, -1, Blk([]))
Exemple #7
0
def test_lconf_structure_classes2_expect_failure():
    """ Tests: test_lconf_structure_classes2_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes2_expect_failure()')

    BlkI(-1, -1, [('key', 'value')])
Exemple #8
0
def test_lconf_structure_classes27_expect_failure():
    """ Tests: test_lconf_structure_classes27_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes27_expect_failure()')

    obj_ = BlkI(-2, -2, Blk([('key', 'value')]))
                    # Repeated-Block-Identifier: type: BlkI: min_required_blocks: undefined (-1) max_required_blocks: 5
                    # With DummyBlock: type: Blk
                    ('#21', ''),
                    ('#22',
                     '# Comment-Line:  nested Key-Value-Mapping item: `Repeated-Block-Identifier`'
                     ),
                    ('mapping11_key2_nested_mapping_key2_block_identifier',
                     BlkI(
                         -1, 5,
                         Blk([
                             ('#23a',
                              '# Comment-Line:  Block items: `Key :: Value Pairs`'
                              ),
                             ('#23b',
                              '#       Using a Transform Function and using an `Empty-KeyValuePair-ReplacementValue` "0"'
                              ),
                             ('#23c',
                              '#               as default value an empty string is set'
                              ),
                             ('blk_item_red', '', lconf_to_int, 0),
                             ('blk_item_green', 0, lconf_to_int),
                             ('blk_item_blue', 0, lconf_to_int),
                         ]))),
                    ('#24', ''),
                    ('#25',
                     '# Comment-Line:  nested Key-Value-Mapping item: `Key :: Value Pairs`'
                     ),
                    ('mapping11_key2_nested_mapping_key3', ''),
                    ('#26', ''),
                    ('#27',
                     '# Comment-Line: nested Key-Value-Mapping item: `Key :: Value-List` or `Key-Value-List`'
    lconf_to_ordered_native_type,
    lconf_validate_one_section_str,
)
from LCONF.transform import lconf_to_int

lconf_section__example_5a__template_obj = Root([
    # Default Empty Line
    ('#1', ''),
    # Default Comment Line
    ('#2', '# Comment-Line: `Repeated-Block-Identifier`'),
    ('categories',
     BlkI(
         2, 2,
         Blk([
             ('#3', ''),
             ('#4', '# Comment-Line:  Block-Item `Key :: Value Pair`'),
             ('test1_name', ''),
             ('test1_score', -1, lconf_to_int),
             ('tests2_name', ''),
             ('tests2_score', -1, lconf_to_int),
         ]))),
])

lconf_section__example_5a_lconf_section_raw_str = r'''___SECTION :: EXAMPLE 5 a
# Repeated-Block-Identifier
* categories
   # using `Block-Names`
   PHP
      test1_name :: One
      test1_score :: 90
      tests2_name :: Two
      tests2_score :: 96
Exemple #11
0
   ('key12list', KVList(True, [])),
   ('key13value_pairlist', KVList(False, [])),
   ('key14value_pairlist', KVList(False, ['1', '2', '3'])),


   # Repeated Mapping-Block Identifier:
   ('RepeatedBlk1', BlkI(2, 5,
      Blk([
         # Block-Item `Key-Value-Mapping`
         ('MyKey1mapping', KVMap([
            ('blk_mapping_key1', ''),
            ('blk_mapping_key2', ''),
            ('blk_mapping_key3', ''),
         ])),

         ('MyKey2', ''),
         ('MyKey3', ''),
         ('MyKey4', ''),
         ('MyKey5list', KVList(True, [])),
         ('MyKey6list', KVList(False, ['1', '2', '3'])),
         ('MyKey7list', KVList(False, [])),
         ('MyKey8', ''),
      ])
   ))
])

example_lconf_section_str_no_comments = r'''___SECTION :: Example
key1value_pair :: value1
key2value_pair ::
key3value_pair :: 1234
key4value_pair :: True
)
from LCONF.transform import lconf_to_int


lconf_section__example_4a__template_obj = Root([
   # Default Empty Line
   ('#1', ''),
   ('registered_employees', 0, lconf_to_int),
   ('#2', '# Comment-Line: `Repeated-Block-Identifier`'),
   ('Employee', BlkI(-1, -1,
      Blk([
         ('first', ''),
         ('last', ''),
         ('sex', ''),
         ('age', ''),
         ('past_salary', KVMap([
            ('year2012', ''),
            ('year2013', -1, lconf_to_int),
         ])),
         ('emails', KVList(True, [])),
      ]),
   )),
   ('registered_customer', 0, lconf_to_int),
   ('#3', '# Comment-Line: `List-Of-Tuples`'),
   ('accounting', ListOT(('item1', 'item2', 'item3', 'item4'), [])),
])

lconf_section__example_4a_lconf_section_raw_str = r'''___SECTION :: EXAMPLE 4 a
registered_employees :: 28594
* Employee
   Person1