try: predicate = meta3.get_meta('no such predicate', 'predicate')
except KeyError: assert True, 'Should have returned default'
else: assert predicate == 'predicate', 'Wrong default returned'

try: meta3['no such predicate']
except KeyError: pass
else: assert True, 'Still should have raised exception'

try: predicate = meta3.setdefault_meta('no such predicate', 'predicate')
except KeyError: assert True, 'Should have returned default'
else: assert predicate == 'predicate', 'Wrong default returned'

try: predicate = meta3['no such predicate']
except KeyError: assert True, 'Should have returned setdefault'
else: assert predicate == 'predicate', 'Incorrect value'

assert MetaDataProvider.get_subject_meta(first, 'absent') is None, (
    'Static method should have returned None')

assert MetaDataProvider.get_subject_meta(first, 'name') == 'shane', (
    'Should have found meta data')

state = MetaDataProvider.get_subject_meta_state(first)
assert (state.has_key('__meta') and
        state['__meta'] == first.__dict__['__meta']), (
            'Should have returned dict.')




Example #2
0
 def get_identifier(obj, default = None, create = False):
     uuid = MetaDataProvider.get_subject_meta(obj, 'identifier', default)
     if uuid is None and create:
         uuid = UniquelyIdentified(obj).identifier
     return uuid
Example #3
0
 def get_identifier(obj, default=None, create=False):
     uuid = MetaDataProvider.get_subject_meta(obj, 'identifier', default)
     if uuid is None and create:
         uuid = UniquelyIdentified(obj).identifier
     return uuid
Example #4
0
try:
    meta3['no such predicate']
except KeyError:
    pass
else:
    assert True, 'Still should have raised exception'

try:
    predicate = meta3.setdefault_meta('no such predicate', 'predicate')
except KeyError:
    assert True, 'Should have returned default'
else:
    assert predicate == 'predicate', 'Wrong default returned'

try:
    predicate = meta3['no such predicate']
except KeyError:
    assert True, 'Should have returned setdefault'
else:
    assert predicate == 'predicate', 'Incorrect value'

assert MetaDataProvider.get_subject_meta(
    first, 'absent') is None, ('Static method should have returned None')

assert MetaDataProvider.get_subject_meta(
    first, 'name') == 'shane', ('Should have found meta data')

state = MetaDataProvider.get_subject_meta_state(first)
assert (state.has_key('__meta') and state['__meta']
        == first.__dict__['__meta']), ('Should have returned dict.')