当前位置: 首页>>代码示例>>Python>>正文


Python RegistryManager.declare_entry方法代码示例

本文整理汇总了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
开发者ID:jssuzanne,项目名称:AnyBlok,代码行数:33,代码来源:declarations.py

示例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': []})
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:18,代码来源:test_registry_manager.py

示例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': []})
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:22,代码来源:test_registry_manager.py

示例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)
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:41,代码来源:test_registry_manager.py

示例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)
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:24,代码来源:test_registry_manager.py

示例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')
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:7,代码来源:test_registry_entry.py


注:本文中的anyblok.registry.RegistryManager.declare_entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。