def imports(self): """ Imports modules and / or packages listed in the blok path""" from anyblok.blok import BlokManager from anyblok.registry import RegistryManager RegistryManager.init_blok(self.blok) b = BlokManager.get(self.blok) b.import_declaration_module()
def add_testCore(self, request, bloks_loaded): def reset(): EnvironmentManager.set('current_blok', None) del RegistryManager.loaded_bloks['testCore' + self._corename] request.addfinalizer(reset) RegistryManager.init_blok('testCore' + self._corename) EnvironmentManager.set('current_blok', 'testCore' + self._corename)
def init_env(self, request): def revert(): EnvironmentManager.set('current_blok', None) del RegistryManager.loaded_bloks['testModel'] request.addfinalizer(revert) RegistryManager.init_blok('testModel') EnvironmentManager.set('current_blok', 'testModel')
def init_env(self, request): def revert(): EnvironmentManager.set('current_blok', None) del RegistryManager.loaded_bloks['testCore'] RegistryManager.undeclare_core('test') request.addfinalizer(revert) RegistryManager.declare_core('test') RegistryManager.init_blok('testCore') EnvironmentManager.set('current_blok', 'testCore')
def test_init_blok(self): 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': []})
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': []})
def test_init_blok(self): RegistryManager.init_blok('newblok') is_exist = 'newblok' in RegistryManager.loaded_bloks assert is_exist for core in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query', 'InstrumentedList'): assert core in RegistryManager.loaded_bloks['newblok'][ 'Core'].keys() assert RegistryManager.loaded_bloks['newblok']['Core'][core] == [] assert RegistryManager.loaded_bloks['newblok']['Model'] == { 'registry_names': [] } assert RegistryManager.loaded_bloks['newblok']['Mixin'] == { 'registry_names': [] }
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) assert not RegistryManager.has_blok_property('myproperty') RegistryManager.add_or_replace_blok_property('myproperty', 2) assert RegistryManager.has_blok_property('myproperty') assert RegistryManager.get_blok_property('myproperty') == 2 RegistryManager.add_or_replace_blok_property('myproperty', 3) assert RegistryManager.get_blok_property('myproperty') == 3 RegistryManager.remove_blok_property('myproperty') assert not RegistryManager.has_blok_property('myproperty') finally: EnvironmentManager.set('current_blok', oldblok)
def test_add_entry(self): RegistryManager.declare_entry('Other') RegistryManager.init_blok('newblok') is_exist = 'newblok' in RegistryManager.loaded_bloks assert is_exist for entry in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query', 'InstrumentedList'): assert RegistryManager.loaded_bloks['newblok']['Core'][entry] == [] assert RegistryManager.loaded_bloks['newblok']['Model'] == { 'registry_names': [] } assert RegistryManager.loaded_bloks['newblok']['Mixin'] == { 'registry_names': [] } assert RegistryManager.loaded_bloks['newblok']['Other'] == { 'registry_names': [] }
def reload(self): """ Reload all the imports for this module :exception: ImportManagerException """ from anyblok.blok import BlokManager from anyblok.registry import RegistryManager from anyblok.environment import EnvironmentManager b = BlokManager.get(self.blok) if not hasattr(b, 'reload_declaration_module'): return try: EnvironmentManager.set('reload', True) RegistryManager.init_blok(self.blok) b.reload_declaration_module(reload_wraper) finally: EnvironmentManager.set('reload', False)
def reload(self): """ Reload all the imports for this module :exception: ImportManagerException """ from anyblok.blok import BlokManager from anyblok.registry import RegistryManager from anyblok.environment import EnvironmentManager b = BlokManager.get(self.blok) if not hasattr(b, 'reload_declaration_module'): return try: EnvironmentManager.set('reload', True) RegistryManager.init_blok(self.blok) b.reload_declaration_module(reload_module) finally: EnvironmentManager.set('reload', False)
def test_init_blok_with_other_entry(self): RegistryManager.declare_entry('Other') hasOther = 'Other' in RegistryManager.declared_entries assert hasOther RegistryManager.init_blok('newblok') is_exist = 'newblok' in RegistryManager.loaded_bloks assert is_exist for core in ('Base', 'SqlBase', 'SqlViewBase', 'Session', 'Query', 'InstrumentedList'): assert core in RegistryManager.loaded_bloks['newblok'][ 'Core'].keys() assert RegistryManager.loaded_bloks['newblok']['Core'][core] == [] assert RegistryManager.loaded_bloks['newblok']['Model'] == { 'registry_names': [] } assert RegistryManager.loaded_bloks['newblok']['Mixin'] == { 'registry_names': [] } assert RegistryManager.loaded_bloks['newblok']['Other'] == { 'registry_names': [] }
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)
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)
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 assert hasModel assert hasMixin assert hasOther cb = Model.assemble_callback hasModelCb = cb == RegistryManager.callback_assemble_entries['Model'] cb = callback hasOtherCb = cb == RegistryManager.callback_assemble_entries['Other'] assert hasModelCb assert hasOtherCb cb = Model.initialize_callback hasModelCb = cb == RegistryManager.callback_initialize_entries['Model'] cb = callback hasOtherCb = cb == RegistryManager.callback_initialize_entries['Other'] assert hasModelCb assert hasOtherCb RegistryManager.init_blok('newblok') is_exist = 'newblok' in RegistryManager.loaded_bloks assert is_exist 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'] assert hasCore assert hasModel assert hasMixin assert hasOther
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)
def setUpClass(cls): super(TestRegistryEntry, cls).setUpClass() RegistryManager.declare_entry('Other') RegistryManager.init_blok('testEntry') EnvironmentManager.set('current_blok', 'testEntry')
def setUpClass(cls): super(TestCoreInterfaceMixin, cls).setUpClass() RegistryManager.init_blok('testMixin') EnvironmentManager.set('current_blok', 'testMixin')
def setUpClass(cls): super(TestRegistryCore, cls).setUpClass() RegistryManager.declare_core('test') RegistryManager.init_blok('testCore') EnvironmentManager.set('current_blok', 'testCore')
def setUpClass(cls): super(TestCoreInterfaceCoreBase, cls).setUpClass() RegistryManager.init_blok('testCore' + cls._corename) EnvironmentManager.set('current_blok', 'testCore' + cls._corename)
def setUpClass(cls): super(TestModel, cls).setUpClass() RegistryManager.init_blok('testModel') EnvironmentManager.set('current_blok', 'testModel')