當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。