Exemple #1
0
 def __new__(klass, context):
     adapter = super(UniquelyIdentified, klass).__new__(klass)
     meta_context = IMetaDataProvider(context)
     uuid = meta_context.setdefault_meta('identifier', UUID())
     identifier_registry.setdefault(uuid, context)
     adapter.initialize(meta_context)
     return adapter
Exemple #2
0
 def __new__(klass, context):
     adapter = super(UniquelyIdentified, klass).__new__(klass)
     meta_context = IMetaDataProvider(context)
     uuid = meta_context.setdefault_meta('identifier', UUID())
     identifier_registry.setdefault(uuid, context)
     adapter.initialize(meta_context)
     return adapter
meta3.add_meta('Test', 'test')
assert meta2.get_meta('Test') == 'test', 'Changes not reflected.'

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

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
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')