示例#1
0
def test_lconf_structure_classes23_expect_failure():
    """ Tests: test_lconf_structure_classes23_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes23_expect_failure()')

    obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33')])
    obj_.replace_column_names(('a', 'b', 'b'))
示例#2
0
def test_lconf_structure_classes24_expect_failure():
   """ Tests: test_lconf_structure_classes24_expect_failure
   """
   print('::: TEST: test_lconf_structure_classes24_expect_failure()')

   obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33'), ('111', '222', '333')])
   obj_.this_column_values('x')
示例#3
0
def test_lconf_structure_classes24_expect_failure():
    """ Tests: test_lconf_structure_classes24_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes24_expect_failure()')

    obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33'), ('111', '222', '333')])
    obj_.this_column_values('x')
示例#4
0
def test_lconf_structure_classes23_expect_failure():
   """ Tests: test_lconf_structure_classes23_expect_failure
   """
   print('::: TEST: test_lconf_structure_classes23_expect_failure()')

   obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33')])
   obj_.replace_column_names(('a', 'b', 'b'))
示例#5
0
def test_lconf_structure_classes21():
    """ Tests: test_lconf_structure_classes21
   """
    print('::: TEST: test_lconf_structure_classes21()')

    obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33')])
    eq_(obj_.column_names, ('a', 'b', 'c'), msg=None)

    obj_.replace_column_names(('new a', 'new b', 'new c'))
    eq_(obj_.column_names, ('new a', 'new b', 'new c'), msg=None)
    eq_(obj_[0], ('11', '22', '33'), msg=None)
示例#6
0
def test_lconf_structure_classes28():
   """ Tests: test_lconf_structure_classes28
   """
   print('::: TEST: test_lconf_structure_classes28()')

   obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33'), ('111', '222', '333')])
   values_column_a = obj_.this_column_values('a')

   obj_.replace_column_names(('new a', 'new b', 'new c'))
   eq_(obj_.column_names, ('new a', 'new b', 'new c'), msg=None)
   eq_(values_column_a, ['11', '111'], msg=None)
示例#7
0
def test_lconf_structure_classes21():
   """ Tests: test_lconf_structure_classes21
   """
   print('::: TEST: test_lconf_structure_classes21()')

   obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33')])
   eq_(obj_.column_names, ('a', 'b', 'c'), msg=None)

   obj_.replace_column_names(('new a', 'new b', 'new c'))
   eq_(obj_.column_names, ('new a', 'new b', 'new c'), msg=None)
   eq_(obj_[0], ('11', '22', '33'), msg=None)
示例#8
0
def test_lconf_structure_classes28():
    """ Tests: test_lconf_structure_classes28
   """
    print('::: TEST: test_lconf_structure_classes28()')

    obj_ = ListOT(('a', 'b', 'c'), [('11', '22', '33'), ('111', '222', '333')])
    values_column_a = obj_.this_column_values('a')

    obj_.replace_column_names(('new a', 'new b', 'new c'))
    eq_(obj_.column_names, ('new a', 'new b', 'new c'), msg=None)
    eq_(values_column_a, ['11', '111'], msg=None)
示例#9
0
def test_lconf_structure_classes18():
   """ Tests: test_lconf_structure_classes18
   """
   print('::: TEST: test_lconf_structure_classes18()')

   obj_ = ListOT(('a', 'b'), [('11', '22')], column_replace_missing=('-1', '-1'))
   obj_.set_class__dict__item('mydata', 'new value')
   eq_(obj_.mydata, 'new value', msg=None)

   eq_(obj_.column_names, ('a', 'b'), msg=None)
   eq_(obj_.column_names_idx_lookup, {'a': 0, 'b': 1}, msg=None)
   eq_(obj_.column_names_counted, 2, msg=None)
   eq_(obj_.column_replace_missing, ('-1', '-1'), msg=None)
示例#10
0
def test_lconf_structure_classes18():
    """ Tests: test_lconf_structure_classes18
   """
    print('::: TEST: test_lconf_structure_classes18()')

    obj_ = ListOT(('a', 'b'), [('11', '22')],
                  column_replace_missing=('-1', '-1'))
    obj_.set_class__dict__item('mydata', 'new value')
    eq_(obj_.mydata, 'new value', msg=None)

    eq_(obj_.column_names, ('a', 'b'), msg=None)
    eq_(obj_.column_names_idx_lookup, {'a': 0, 'b': 1}, msg=None)
    eq_(obj_.column_names_counted, 2, msg=None)
    eq_(obj_.column_replace_missing, ('-1', '-1'), msg=None)
示例#11
0
def test_lconf_structure_classes16_expect_failure():
    """ Tests: test_lconf_structure_classes16_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes16_expect_failure()')

    # noinspection PyRedundantParentheses
    obj_ = ListOT(('a', 'b'), [('11', '22')], column_replace_missing=('-1'))
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_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_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)
示例#15
0
             ),
            ('mapping10_key4_list', KVList(True, [555, 9999]), lconf_to_int),

            # `Key :: Value-List` or `Key-Value-List`: type: KVList: set default_is_oneline: False
            ('#10', ''),
            ('#11',
             '# Comment-Line:  Key-Value-Mapping item: `Key :: Value-List` or `Key-Value-List`'
             ),
            ('mapping10_key5_list', KVList(False, [555, 9999]), lconf_to_int),

            # `List-Of-Tuples`: type: ListOT: one transform function for all values
            ('#12', ''),
            ('#13',
             '# Comment-Line:  Key-Value-Mapping item: `List-Of-Tuples`'),
            ('mapping10_key6_list',
             ListOT(('x', 'y'), [(9999, 9999), (9999, 9999)]), lconf_to_int),

            # `List-Of-Tuples`: type: ListOT: for each column a separate transform function
            ('#14', ''),
            ('#15',
             '# Comment-Line:  Key-Value-Mapping item: `List-Of-Tuples`'),
            ('mapping10_key7_list',
             ListOT(('name', 'b', 'c'), [('something', 11, 1234),
                                         ('something2', 9999, 9999)]),
             (None, lconf_to_float, lconf_to_int)),
        ])),

    # `Key-Value-Mapping: type: KVMap
    ('#16', ''),
    ('#17', '# Comment-Line: below is a Main `Key-Value-Mapping`'),
    (
示例#16
0
def test_lconf_emit_ok9():
    """ Tests: test_lconf_emit_ok9
   """
    print('::: TEST: test_lconf_emit_ok9()')

    # 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'),
                []), (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')]),
         (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')]), lconf_to_float),
        ('#4', '# Comment-Line: using one transform function for all'),
        ('list_of_tuples4',
         ListOT(('a', 'b', 'c'), [('1.0', '2.0', '3.0'),
                                  ('44.0', '55.0', '66.0')])),
        ('#5', '# Comment-Line: using one transform function for all'),
        ('list_of_tuples5',
         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'))),
        ('#6', '# Comment-Line: using one transform function for all'),
        ('list_of_tuples6',
         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_to_float, lconf_to_float)),
    ])

    lconf_section_raw_str = r'''___SECTION :: TestExample
# Comment-Line: below is a Main `List-Of-Tuples` with 4 columns: |Color Name|Red|Green|Blue|
- list_of_color_tuples |Color Name|Red|Green|Blue|
   forestgreen,34,139,34
   brick,156,102,31
# Comment-Line: below is a Main `List-Of-Tuples` with 3 columns: |a|b|c|
- list_of_tuples2 |a|b|c|
   100,200,300
   400,500,600
# Comment-Line: using one transform function for all
- list_of_tuples3 |a|b|c|
   100.0,200.0,300.0
   400.0,500.0,600.0
# Comment-Line: using one transform function for all
- list_of_tuples4 |a|b|c|
   100.0,200.0,300.0
   400.0,500.0,600.0
# Comment-Line: using one transform function for all
- list_of_tuples5 |a|b|c|
   100.0,,300.0
   400.0,500.0,600.0
# Comment-Line: using one transform function for all
- list_of_tuples6 |a|b|c|
   100.0,,300.0
   400.0,500.0,600.0
___END'''

    lconf_obj = lconf_parse_section_extract_by_name(
        lconf_section_raw_str,
        'TestExample',
        lconf_section__template_obj,
        with_comments=True,
        validate=True)

    emit_result = lconf_emit(lconf_obj, onelinelists=LCONF_DEFAULT)

    reparsed_lconf_obj = lconf_parse_section_extract_by_name(
        emit_result,
        'TestExample',
        lconf_section__template_obj,
        with_comments=True,
        validate=True)

    eq_(lconf_obj, reparsed_lconf_obj, msg=None)
    re_emit_result = lconf_emit(reparsed_lconf_obj,
                                onelinelists=LCONF_DEFAULT,
                                empty_key_value_pair=True)
    eq_(emit_result, re_emit_result, msg=None)

    lconf_obj = lconf_parse_section_extract_by_name(
        lconf_section_raw_str,
        'TestExample',
        lconf_section__template_obj,
        with_comments=True,
        validate=True)

    emit_result = lconf_emit(lconf_obj,
                             onelinelists=LCONF_NO,
                             empty_key_value_pair=True)

    reparsed_lconf_obj = lconf_parse_section_extract_by_name(
        emit_result,
        'TestExample',
        lconf_section__template_obj,
        with_comments=True,
        validate=True)

    eq_(lconf_obj, reparsed_lconf_obj, msg=None)
    re_emit_result = lconf_emit(reparsed_lconf_obj,
                                onelinelists=LCONF_NO,
                                empty_key_value_pair=True)
    eq_(emit_result, re_emit_result, msg=None)

    lconf_obj = lconf_parse_section_extract_by_name(
        lconf_section_raw_str,
        'TestExample',
        lconf_section__template_obj,
        with_comments=True,
        validate=True)

    emit_result = lconf_emit(lconf_obj,
                             onelinelists=LCONF_YES,
                             empty_key_value_pair=True)

    reparsed_lconf_obj = lconf_parse_section_extract_by_name(
        emit_result,
        'TestExample',
        lconf_section__template_obj,
        with_comments=True,
        validate=True)

    eq_(lconf_obj, reparsed_lconf_obj, msg=None)
    re_emit_result = lconf_emit(reparsed_lconf_obj,
                                onelinelists=LCONF_YES,
                                empty_key_value_pair=True)
    eq_(emit_result, re_emit_result, msg=None)
示例#17
0
def test_lconf_structure_classes15_expect_failure():
    """ Tests: test_lconf_structure_classes15_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes15_expect_failure()')

    ListOT([], [('11', '22')])
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)
示例#19
0
def test_lconf_structure_classes17_expect_failure():
    """ Tests: test_lconf_structure_classes17_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes17_expect_failure()')

    obj_ = ListOT(('a', 'b'), [('11', '22')], column_replace_missing=('-1', ))
示例#20
0
def test_lconf_structure_classes14_expect_failure():
    """ Tests: test_lconf_structure_classes14_expect_failure
   """
    print('::: TEST: test_lconf_structure_classes14_expect_failure()')

    ListOT(['a', 'b'], ())
   ('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
      first :: John
      last :: Doe
      sex :: M
      age :: 39
      . past_salary
         year2012 :: 45000
         year2013 :: 62000
      - emails
         <*****@*****.**>