我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用six.moves.reload_module()。
def tearDown(self): super(PluginTestCase, self).tearDown() conf.HORIZON_CONFIG = self.old_horizon_config # Destroy our singleton and re-create it. base.HorizonSite._instance = None del base.Horizon base.Horizon = base.HorizonSite() # Reload the convenience references to Horizon stored in __init__ moves.reload_module(import_module("horizon")) # Re-register our original dashboards and panels. # This is necessary because autodiscovery only works on the first # import, and calling reload introduces innumerable additional # problems. Manual re-registration is the only good way for testing. for dash in self._discovered_dashboards: base.Horizon.register(dash) for panel in self._discovered_panels[dash]: dash.register(panel) self._reload_urls()
def tearDown(self): super(BaseHorizonTests, self).tearDown() # Restore our settings settings.HORIZON_CONFIG['default_dashboard'] = self.old_default_dash settings.HORIZON_CONFIG['dashboards'] = self.old_dashboards # Destroy our singleton and re-create it. base.HorizonSite._instance = None del base.Horizon base.Horizon = base.HorizonSite() # Reload the convenience references to Horizon stored in __init__ moves.reload_module(import_module("horizon")) # Re-register our original dashboards and panels. # This is necessary because autodiscovery only works on the first # import, and calling reload introduces innumerable additional # problems. Manual re-registration is the only good way for testing. self._discovered_dashboards.remove(Cats) self._discovered_dashboards.remove(Dogs) for dash in self._discovered_dashboards: base.Horizon.register(dash) for panel in self._discovered_panels[dash]: dash.register(panel)
def refresh_stevedore(namespace=None): """Trigger reload of entry points. Useful to have dynamic loading/unloading of stevedore modules. """ # NOTE(sheeprine): pkg_resources doesn't support reload on python3 due to # defining basestring which is still there on reload hence executing # python2 related code. try: del sys.modules['pkg_resources'].basestring except AttributeError: # python2, do nothing pass # Force working_set reload moves.reload_module(sys.modules['pkg_resources']) # Clear stevedore cache cache = extension.ExtensionManager.ENTRY_POINT_CACHE if namespace: if namespace in cache: del cache[namespace] else: cache.clear()
def setUp(self): super(ThemePreviewTests, self).setUp() urlresolvers.clear_url_caches() moves.reload_module(import_module(settings.ROOT_URLCONF)) base.Horizon.register(Developer) base.Horizon._urls()
def _reload_urls(self): """CLeans up URLs. Clears out the URL caches, reloads the root urls module, and re-triggers the autodiscovery mechanism for Horizon. Allows URLs to be re-calculated after registering new dashboards. Useful only for testing and should never be used on a live site. """ urlresolvers.clear_url_caches() moves.reload_module(import_module(settings.ROOT_URLCONF)) base.Horizon._urls()
def _reload_urls(self): """Clears out the URL caches, reloads the root urls module, and re-triggers the autodiscovery mechanism for Horizon. Allows URLs to be re-calculated after registering new dashboards. Useful only for testing and should never be used on a live site. """ urlresolvers.clear_url_caches() moves.reload_module(import_module(settings.ROOT_URLCONF)) base.Horizon._urls()
def test_all_public_methods_are_traced(self): profiler_opts.set_defaults(conf.CONF) self.config(enabled=True, group='profiler') classes = [ 'zun.compute.api.API', 'zun.compute.rpcapi.API', ] for clsname in classes: # give the metaclass and trace_cls() decorator a chance to patch # methods of the classes above six.reload_module( importutils.import_module(clsname.rsplit('.', 1)[0])) cls = importutils.import_class(clsname) for attr, obj in cls.__dict__.items(): # only public methods are traced if attr.startswith('_'): continue # only checks callables if not (inspect.ismethod(obj) or inspect.isfunction(obj)): continue # osprofiler skips static methods if isinstance(obj, staticmethod): continue self.assertTrue(getattr(obj, '__traced__', False), obj)
def reload_plugin(self, cls): """ Reloads a plugin. """ config = self.plugins[cls.__name__].config ctx = self.rmv_plugin(cls) module = reload_module(inspect.getmodule(cls)) self.add_plugin(getattr(module, cls.__name__), config, ctx)
def reload_module(name): if reload: if name in sys.modules: module = sys.modules.get(name) return reload(module) return None
def try_reload(): sys.path[0:0] = [config.compiledir] reload(lazylinker_ext) del sys.path[0]