本文整理汇总了Python中anyblok.registry.RegistryManager.declare_entry方法的典型用法代码示例。如果您正苦于以下问题:Python RegistryManager.declare_entry方法的具体用法?Python RegistryManager.declare_entry怎么用?Python RegistryManager.declare_entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anyblok.registry.RegistryManager
的用法示例。
在下文中一共展示了RegistryManager.declare_entry方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapper
# 需要导入模块: from anyblok.registry import RegistryManager [as 别名]
# 或者: from anyblok.registry.RegistryManager import declare_entry [as 别名]
def wrapper(self):
from anyblok.registry import RegistryManager
name = self.__name__
if name in cls.declaration_types:
raise DeclarationsException(
"The declaration type %r is already defined" % name)
cls.declaration_types[name] = self
setattr(self, '__registry_name__', name)
setattr(self, '__declaration_type__', name)
setattr(cls, name, self)
if isAnEntry:
assemble_callback = initialize_callback = None
if assemble and hasattr(self, assemble):
assemble_callback = getattr(self, assemble)
if initialize and hasattr(self, initialize):
initialize_callback = getattr(self, initialize)
RegistryManager.declare_entry(
name, assemble_callback=assemble_callback,
initialize_callback=initialize_callback)
# All declaration type can need to be unload declarated values
if unload and hasattr(self, unload):
RegistryManager.declare_unload_callback(
name, getattr(self, unload))
return self
示例2: test_add_entry
# 需要导入模块: from anyblok.registry import RegistryManager [as 别名]
# 或者: from anyblok.registry.RegistryManager import declare_entry [as 别名]
def test_add_entry(self):
RegistryManager.declare_entry('Other')
RegistryManager.init_blok('newblok')
is_exist = 'newblok' in RegistryManager.loaded_bloks
self.assertEqual(is_exist, True)
for entry in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
'InstrumentedList'):
self.assertEqual(
RegistryManager.loaded_bloks['newblok']['Core'][entry], [])
self.assertEqual(RegistryManager.loaded_bloks['newblok']['Model'],
{'registry_names': []})
self.assertEqual(RegistryManager.loaded_bloks['newblok']['Mixin'],
{'registry_names': []})
self.assertEqual(RegistryManager.loaded_bloks['newblok']['Other'],
{'registry_names': []})
示例3: test_init_blok_with_other_entry
# 需要导入模块: from anyblok.registry import RegistryManager [as 别名]
# 或者: from anyblok.registry.RegistryManager import declare_entry [as 别名]
def test_init_blok_with_other_entry(self):
RegistryManager.declare_entry('Other')
hasOther = 'Other' in RegistryManager.declared_entries
self.assertEqual(hasOther, True)
RegistryManager.init_blok('newblok')
is_exist = 'newblok' in RegistryManager.loaded_bloks
self.assertEqual(is_exist, True)
for core in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query',
'InstrumentedList'):
self.assertIn(
core, RegistryManager.loaded_bloks['newblok']['Core'].keys())
self.assertEqual(
RegistryManager.loaded_bloks['newblok']['Core'][core], [])
self.assertEqual(RegistryManager.loaded_bloks['newblok']['Model'],
{'registry_names': []})
self.assertEqual(RegistryManager.loaded_bloks['newblok']['Mixin'],
{'registry_names': []})
self.assertEqual(RegistryManager.loaded_bloks['newblok']['Other'],
{'registry_names': []})
示例4: test_add_callback
# 需要导入模块: from anyblok.registry import RegistryManager [as 别名]
# 或者: from anyblok.registry.RegistryManager import declare_entry [as 别名]
def test_add_callback(self):
def callback():
pass
RegistryManager.declare_entry('Other', assemble_callback=callback,
initialize_callback=callback)
hasModel = 'Model' in RegistryManager.declared_entries
hasMixin = 'Mixin' in RegistryManager.declared_entries
hasOther = 'Other' in RegistryManager.declared_entries
self.assertEqual(hasModel, True)
self.assertEqual(hasMixin, True)
self.assertEqual(hasOther, True)
cb = Model.assemble_callback
hasModelCb = cb == RegistryManager.callback_assemble_entries['Model']
cb = callback
hasOtherCb = cb == RegistryManager.callback_assemble_entries['Other']
self.assertEqual(hasModelCb, True)
self.assertEqual(hasOtherCb, True)
cb = Model.initialize_callback
hasModelCb = cb == RegistryManager.callback_initialize_entries['Model']
cb = callback
hasOtherCb = cb == RegistryManager.callback_initialize_entries['Other']
self.assertEqual(hasModelCb, True)
self.assertEqual(hasOtherCb, True)
RegistryManager.init_blok('newblok')
is_exist = 'newblok' in RegistryManager.loaded_bloks
self.assertEqual(is_exist, True)
hasCore = 'Core' in RegistryManager.loaded_bloks['newblok']
hasModel = 'Model' in RegistryManager.loaded_bloks['newblok']
hasMixin = 'Mixin' in RegistryManager.loaded_bloks['newblok']
hasOther = 'Other' in RegistryManager.loaded_bloks['newblok']
self.assertEqual(hasCore, True)
self.assertEqual(hasModel, True)
self.assertEqual(hasMixin, True)
self.assertEqual(hasOther, True)
示例5: test_global_property
# 需要导入模块: from anyblok.registry import RegistryManager [as 别名]
# 或者: from anyblok.registry.RegistryManager import declare_entry [as 别名]
def test_global_property(self):
RegistryManager.declare_entry('Other')
blok = 'newblok'
RegistryManager.init_blok(blok)
try:
oldblok = EnvironmentManager.get('current_blok')
EnvironmentManager.set('current_blok', blok)
self.assertEqual(RegistryManager.has_blok_property('myproperty'),
False)
RegistryManager.add_or_replace_blok_property('myproperty', 2)
self.assertEqual(
RegistryManager.has_blok_property('myproperty'), True)
self.assertEqual(
RegistryManager.get_blok_property('myproperty'), 2)
RegistryManager.add_or_replace_blok_property('myproperty', 3)
self.assertEqual(
RegistryManager.get_blok_property('myproperty'), 3)
RegistryManager.remove_blok_property('myproperty')
self.assertEqual(RegistryManager.has_blok_property('myproperty'),
False)
finally:
EnvironmentManager.set('current_blok', oldblok)
示例6: setUpClass
# 需要导入模块: from anyblok.registry import RegistryManager [as 别名]
# 或者: from anyblok.registry.RegistryManager import declare_entry [as 别名]
def setUpClass(cls):
super(TestRegistryEntry, cls).setUpClass()
RegistryManager.declare_entry('Other')
RegistryManager.init_blok('testEntry')
EnvironmentManager.set('current_blok', 'testEntry')