Ejemplo n.º 1
0
def test_create_element_stats():
    register_copy = copy(register)
    field10 = OrderedDict([('@id', 'ID10'), ('name', 'field10'),
                           ('bitOffset', '0'), ('bitWidth', '2'),
                           ('volatile', 'false')])
    field11 = OrderedDict([('@id', 'ID11'), ('name', 'field11'),
                           ('bitOffset', '2'), ('bitWidth', '4'),
                           ('volatile', 'true')])
    register_copy['field'] = [field10, field11]
    stats = defaultdict(int)
    create_element('register', register_copy, nameSpaces, stats=stats)
    expected_stats = {
        'reset': 1,
        'bitOffset': 2,
        'name': 3,
        'bitWidth': 2,
        'field.@id': 2,
        'register.@id': 1,
        'register': 1,
        'addressOffset': 1,
        'value': 1,
        'access': 1,
        'field': 2,
        'volatile': 2,
        'size': 1
    }
    nose.tools.eq_(stats, expected_stats)
Ejemplo n.º 2
0
def test_create_element_two_levels():
    register_copy = copy(register)
    field10 = OrderedDict([('@id', 'ID10'), ('name', 'field10'),
                           ('bitOffset', '0'), ('bitWidth', '2'),
                           ('volatile', 'false')])
    field11 = OrderedDict([('@id', 'ID11'), ('name', 'field11'),
                           ('bitOffset', '2'), ('bitWidth', '4'),
                           ('volatile', 'true')])
    register_copy['field'] = [field10, field11]
    el = create_element('register', register_copy, nameSpaces)
    expected = [
        Element(
            tag='field',
            attributes=OrderedDict([('id', 'ID10')]),
            path="/register-0,reg6/field-0,field10",
            value=[
                Element(tag='name',
                        path="/register-0,reg6/field-0,field10/name-0,",
                        value='field10'),
                Element(tag='bitOffset',
                        path="/register-0,reg6/field-0,field10/bitOffset-0,",
                        value='0'),
                Element(tag='bitWidth',
                        path="/register-0,reg6/field-0,field10/bitWidth-0,",
                        value='2'),
                Element(tag='volatile',
                        path="/register-0,reg6/field-0,field10/volatile-0,",
                        value='false')
            ]),
        Element(
            tag='field',
            attributes=OrderedDict([('id', 'ID11')]),
            path="/register-0,reg6/field-1,field11",
            value=[
                Element(tag='name',
                        path="/register-0,reg6/field-1,field11/name-0,",
                        value='field11'),
                Element(tag='bitOffset',
                        path="/register-0,reg6/field-1,field11/bitOffset-0,",
                        value='2'),
                Element(tag='bitWidth',
                        path="/register-0,reg6/field-1,field11/bitWidth-0,",
                        value='4'),
                Element(tag='volatile',
                        path="/register-0,reg6/field-1,field11/volatile-0,",
                        value='true')
            ])
    ]
    nose.tools.eq_(el.value[5:], expected)
Ejemplo n.º 3
0
def test_create_element_attribute_text_pass():
    value = OrderedDict([('text',
                          OrderedDict([('@attr', '42'),
                                       ('#text', 'root value')]))])
    el = create_element('root', value, nameSpaces)
    nose.tools.eq_(
        el,
        Element(tag='root',
                path="/root-0,",
                value=[
                    Element(tag='text',
                            attributes=OrderedDict([('attr', '42')]),
                            path="/root-0,/text-0,",
                            value='root value')
                ]))
Ejemplo n.º 4
0
def test_create_element_one_level():
    el = create_element('register', register, nameSpaces)
    register_element = Element(
        tag='register',
        attributes=OrderedDict([('id', 'ID6')]),
        path="/register-0,reg6",
        value=[
            Element(tag='name', path="/register-0,reg6/name-0,", value='reg6'),
            Element(tag='addressOffset',
                    path="/register-0,reg6/addressOffset-0,",
                    value='0'),
            Element(tag='size', path="/register-0,reg6/size-0,", value='2'),
            Element(tag='access',
                    path="/register-0,reg6/access-0,",
                    value='writeOnce'),
            Element(tag='reset',
                    path="/register-0,reg6/reset-0,",
                    value=[
                        Element(tag='value',
                                path="/register-0,reg6/reset-0,/value-0,",
                                value='0')
                    ])
        ])
    nose.tools.eq_(el, register_element)
Ejemplo n.º 5
0
def test_create_element_root_only():
    el = create_element('root', {}, nameSpaces)
    nose.tools.eq_(el, Element('root', value=[], path='/root-0,'))
Ejemplo n.º 6
0
def test_create_element_stats_simple_value_list():
    stats = defaultdict(int)
    test = OrderedDict([('multiple', [1, 2, 3])])
    create_element('test', test, nameSpaces, path='/', stats=stats)
    nose.tools.eq_(stats, {'multiple': 1, 'test': 1})