예제 #1
0
def test_key_store_add_value_pass():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('TestKey')
    ks.to_python(None, path='/', stores=stores)
    stores.keyStore.add_value('TestKey', '/', 'key_value', '/ads/cgfh')
    expected = {'TestKey:/': {'key_value': '/ads/cgfh'}}
    nose.tools.eq_(stores.keyStore.keys, expected)
예제 #2
0
def test_key_value_count_1_pass():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('TestKey')
    ks.to_python(None, path='/', stores=stores)
    stores.keyStore.add_value('TestKey', '/', 'TestKey0', '/ads/cgfh')
    actual = stores.keyStore.key_value_count('TestKey', '/')
    nose.tools.eq_(actual, 1)
예제 #3
0
def test_check_keys_single_key_build_no_value_pass():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('FieldKey')
    path = "/register-0,reg6"
    ks.build(path=path, stores=stores)
    ck = constraints.CheckKeys(key_names='FieldKey', level=1)
    field = Element('field', value='field22', path=path + '/field-2,field22')
    nose.tools.eq_(ck.build(path=field.path, stores=stores), 'FieldKey0')
예제 #4
0
def test_id_count_1_pass():
    stores = constraints.Stores()
    ks = constraints.ID()
    el = Element('test', path='/el42-0,', attributes=dict(id='ID42'))
    id_element = Element('id', path=el.path + '@id', value=el.attributes['id'])
    ks.to_python(id_element, stores=stores)
    actual = stores.idStore.id_count()
    nose.tools.eq_(actual, 1)
예제 #5
0
def test_match_id_pass():
    stores = constraints.Stores()
    path = '/root-0,'
    ck = constraints.ID()
    field = Element('field', value='field22', path=path + '/field-2,field22')
    ck.to_python(field, stores=stores)
    instance_path = stores.idStore.match_id('field22')
    nose.tools.eq_(instance_path, path + '/field-2,field22')
예제 #6
0
def test_check_keys_empty_value_fail():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('FieldKey')
    path = "/register-0,reg6"
    ks.to_python(None, path=path, stores=stores)
    ck = constraints.CheckKeys(key_names='FieldKey', level=1)
    field = Element('field', path=path + '/field-2,field22')
    ck.to_python(field, stores=stores)
예제 #7
0
def test_check_idref_single_pass():
    stores = constraints.Stores()
    cr = constraints.IDREF()
    cr.to_python('ID42', path='/ref-0,/for-0,/field-0,', stores=stores)
    expected = constraints.KeyRef(key_name='ID',
                                  key_value='ID42',
                                  ref_path='/ref-0,/for-0,/field-0,')
    nose.tools.eq_(stores.idrefStore.refs[0], expected)
예제 #8
0
def test_match_idref_to_id_single_pass():
    stores = constraints.Stores()
    ci = constraints.ID()
    cr = constraints.IDREF()
    ci.to_python('ID42', path='/field-0,@id', stores=stores)
    cr.to_python('ID42', path='/ref-0,/for-0,/field-0,', stores=stores)
    constraints.match_refs(stores)
    expected = {'/ref-0,/for-0,/field-0,': '/field-0,@id'}
    nose.tools.eq_(stores.idrefStore.targets, expected)
예제 #9
0
def test_key_name_two_keys_pass():
    ks = constraints.InitKeyStore('Key2')
    stores = constraints.Stores()
    root_path = '/root-0,'
    ks.to_python(None, path=root_path, stores=stores)
    u_name = constraints.KeyName(key_names='Key1 Key2'.split(), level=1)
    key_path = root_path + '/child-1,prefixed:name'
    actual = u_name.to_python('prefixed:name', path=key_path, stores=stores)
    nose.tools.eq_(actual, 'prefixed:name')
예제 #10
0
def test_check_keys_path_mismatch_fail():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('FieldKey')
    path = "/register-0,reg6"
    el = Element('reg', path=path)
    ks.to_python(el, path=path, stores=stores)
    ck = constraints.CheckKeys(key_names='FieldKey', level=1)
    field = Element('field', value='field22', path='/field-2,field22')
    ck.to_python(field, stores=stores)
예제 #11
0
def test_check_ids_add_id_pass():
    stores = constraints.Stores()
    ks = constraints.ID()
    el = Element('test', path='/el42-0,', attributes=dict(id='ID42'))
    id_element = Element('id', path=el.path + '@id', value=el.attributes['id'])
    ks.to_python(id_element, stores=stores)
    stores.idStore.add_id('key_value', '/ads/cgfh')
    expected = {'ID:/': {'key_value': '/ads/cgfh', 'ID42': '/el42-0,@id'}}
    nose.tools.eq_(stores.idStore.keys, expected)
예제 #12
0
def test_check_uniques_single_key_build_no_value_pass():
    stores = constraints.Stores()
    ks = constraints.InitUniqueStore('UniqueKey')
    path = "/register-0,reg6"
    ks.build(path=path, stores=stores)
    ck = constraints.CheckUniques(key_names='UniqueKey', level=1)
    field = Element('field', value='field22', path=path + '/field-2,field22')
    actual = ck.build(path=field.path, stores=stores)
    nose.tools.eq_(actual, 'UniqueKey0')
예제 #13
0
def test_check_uniques_single_key_pass():
    stores = constraints.Stores()
    ks = constraints.InitUniqueStore('FieldKey')
    path = "/register-0,reg6"
    ks.to_python(None, path=path, stores=stores)
    ck = constraints.CheckUniques(key_names='FieldKey', level=1)
    field = Element('field', value='field22', path=path + '/field-2,field22')
    actual = ck.to_python(field.value, path=field.path, stores=stores)
    nose.tools.eq_(actual, 'field22')
예제 #14
0
def test_check_keys_three_keys_build_no_value_pass():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('FieldKey')
    path = "/register-0,reg6"
    ks.build(path=path, stores=stores)
    ck = constraints.CheckKeys(
        key_names=['OtherKey', 'FieldKey', 'YetAnotherKey'], level=1)
    field = Element('field', value='field22', path=path + '/field-2,field22')
    actual = ck.build(path=field.path, stores=stores)
    nose.tools.eq_(actual, 'FieldKey0')
예제 #15
0
def test_check_keys_duplicate_value_fail():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('FieldKey')
    path = "/register-0,reg6"
    ks.to_python(None, path=path, stores=stores)
    ck = constraints.CheckKeys(key_names='FieldKey', level=1)
    field0 = Element('field', value='field22', path=path + '/field-2,field22')
    field1 = Element('field', value='field22', path=path + '/field-12,field22')
    nose.tools.eq_(ck.to_python(field0, stores=stores), 'field22')
    ck.to_python(field1, stores=stores)
예제 #16
0
def test_match_ref_pass():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('key_name')
    path = '/root-0,'
    ks.to_python(None, path=path, stores=stores)
    ck = constraints.CheckKeys(key_names=['OtherKey', 'key_name'], level=1)
    field = Element('field', value='field22', path=path + '/field-2,field22')
    ck.to_python(field.value, path=field.path, stores=stores)
    instance_path = stores.keyStore.match_ref('key_name', 'field22')
    nose.tools.eq_(instance_path, path + '/field-2,field22')
예제 #17
0
def test_check_uniques_empty_value_pass():
    stores = constraints.Stores()
    ks = constraints.InitUniqueStore('FieldKey')
    path = "/register-0,reg6"
    el = Element('reg', path=path)
    ks.to_python(el, stores=stores)
    ck = constraints.CheckUniques(key_names='FieldKey', level=1)
    field = Element('field', value=None, path=path + '/field-2,field22')
    nose.tools.eq_(ck.to_python(field.value, path=field.path, stores=stores),
                   None)
예제 #18
0
def test_setup_key_refs_store_build_no_value_pass():
    stores = constraints.Stores()
    ks = constraints.SetupKeyRefsStore('TestKeyRef')
    path = '/root-0,/test'
    el = Element('test', value='refName', path=path)
    ks.build(path=el.path, stores=stores)
    nose.tools.eq_(stores.refStore.refs, [
        constraints.KeyRef(key_name='TestKeyRef',
                           key_value='TestKeyRef0',
                           ref_path='/root-0,/test')
    ])
예제 #19
0
def test_init_key_store_two_keys_pass():
    stores = constraints.Stores()
    ks0 = constraints.InitKeyStore('TestKey')
    path = '/root-0,/test-0,'
    el = Element('test', path=path)
    ks0.to_python(el, path=el.path, stores=stores)
    ks1 = constraints.InitKeyStore('TestKey')
    path = '/root-0,/test-1,'
    ks1.to_python(None, path=path, stores=stores)
    expected = {'TestKey:/root-0,/test-1,': {}, 'TestKey:/root-0,/test-0,': {}}
    nose.tools.eq_(stores.keyStore.keys, expected)
예제 #20
0
def test_setup_key_refs_store_string_validator_pass():
    stores = constraints.Stores()
    ks = constraints.SetupKeyRefsStore('TestKeyRef',
                                       string_validator_instance=Name())
    path = '/root-0,/test'
    el = Element('test', value='refName', path=path)
    ks.to_python(el, stores=stores)
    nose.tools.eq_(stores.refStore.refs, [
        constraints.KeyRef(key_name='TestKeyRef',
                           key_value='refName',
                           ref_path='/root-0,/test')
    ])
예제 #21
0
def test_match_refs_value_not_found_fail():
    stores = constraints.Stores()
    root_element = Element('root', value=None, path='/component-0,test')
    ref_element = Element(
        'memoryMapRef',
        value='myMemoryMap',
        path='/component-0,test/busInterface-0,/memoryMapRef-0,@memoryMapRef')
    constraints.InitKeyStore('memoryMapKey').to_python(root_element,
                                                       path=root_element.path,
                                                       stores=stores)
    kr = constraints.SetupKeyRefsStore('memoryMapKey')
    kr.to_python(ref_element, stores=stores)
    constraints.match_refs(stores)
예제 #22
0
def test_check_keys_three_keys_pass():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('FieldKey')
    path = "/register-0,reg6"
    ks.to_python(None, path=path, stores=stores)
    ck = constraints.CheckKeys(
        key_names=['OtherKey', 'FieldKey', 'YetAnotherKey'], level=1)
    field = Element('field', value='field22', path=path + '/field-2,field22')
    expected = {
        'FieldKey:/register-0,reg6': {
            'field22': '/register-0,reg6/field-2,field22'
        }
    }
    ck.to_python(field, stores=stores)
    nose.tools.eq_(stores.keyStore.keys, expected)
예제 #23
0
def test_key_sub_class_name_two_keys_pass():
    class TestKeyName(constraints.KeyName):
        key_names = 'Key1 Key2'.split()
        refer_key_name = 'referKey'
        level = 1

    ks = constraints.InitKeyStore('Key2')
    stores = constraints.Stores()
    root_path = '/root-0,'
    ks.to_python(None, path=root_path, stores=stores)
    u_name = TestKeyName()
    key_path = root_path + '/child-1,prefixed:name'
    actual = u_name.to_python('prefixed:name', path=key_path, stores=stores)
    nose.tools.eq_(stores.refStore.refs, [
        constraints.KeyRef(key_name='referKey',
                           key_value='prefixed:name',
                           ref_path='/root-0,/child-1,prefixed:name')
    ])
예제 #24
0
def test_match_refs_pass():
    stores = constraints.Stores()
    root_element = Element('root', value=None, path='/component-0,test')
    key_element = Element(
        'name',
        value='myMemoryMap',
        path='/component-0,test/memoryMap-0,myMemoryMap/name-0,')
    ref_element = Element(
        'memoryMapRef',
        value='myMemoryMap',
        path='/component-0,test/busInterface-0,/memoryMapRef-0,@memoryMapRef')
    constraints.InitKeyStore('memoryMapKey').to_python(root_element,
                                                       stores=stores)
    constraints.CheckKeys(key_names='memoryMapKey',
                          level=2).to_python(key_element, stores=stores)
    kr = constraints.SetupKeyRefsStore('memoryMapKey')
    kr.to_python(ref_element, stores=stores)
    constraints.match_refs(stores)
    targets = {
        '/component-0,test/busInterface-0,/memoryMapRef-0,@memoryMapRef':
        '/component-0,test/memoryMap-0,myMemoryMap/name-0,'
    }
    nose.tools.eq_(stores.refStore.targets, targets)
예제 #25
0
def test_id_count_0_pass():
    stores = constraints.Stores()
    actual = stores.idStore.id_count()
    nose.tools.eq_(actual, 0)
예제 #26
0
def test_check_idref_single_build_no_value_two_calls_pass():
    stores = constraints.Stores()
    constraints.IDREF().build(stores=stores, path='/')
    actual = constraints.IDREF().build(stores=stores, path='/')
    nose.tools.eq_(actual, 'testId0')
예제 #27
0
def test_build_id_pass():
    stores = constraints.Stores()
    ks = constraints.ID()
    actual = ks.build(path='/', stores=stores)
    nose.tools.eq_(actual, 'testId0')
예제 #28
0
def test_match_ref_key_value_not_found_fail():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('key_name')
    ks.to_python(None, path='/', stores=stores)
    stores.keyStore.match_ref('key_name', 'field220')
예제 #29
0
def test_build_id1_pass():
    stores = constraints.Stores()
    ks = constraints.ID()
    ks.build(path='/', stores=stores)
    second = ks.build(path='/', stores=stores)
    nose.tools.eq_(second, 'testId1')
예제 #30
0
def test_match_ref_nonexistent_key_name_fail():
    stores = constraints.Stores()
    ks = constraints.InitKeyStore('key_name')
    ks.to_python(None, path='/', stores=stores)
    stores.keyStore.match_ref('key_name', 'field22')