How to use get_loaded_modules method in avocado

Best Python code snippet using avocado_python

_mc.py

Source:_mc.py Github

copy

Full Screen

...31 "unarchive_module",32]33def module_is_loaded(key):34 if isinstance(key, pymod.module.Module):35 return key in get_loaded_modules()36 elif os.path.isfile(key):37 return key in [m.filename for m in get_loaded_modules()]38 else:39 for module in get_loaded_modules():40 if module.name == key or module.fullname == key:41 return True42 return False43def get_loaded_modules():44 global _loaded_modules45 if _loaded_modules is None:46 tty.debug("Reading loaded modules")47 _loaded_modules = []48 lm_cellar = pymod.environ.get(49 pymod.names.loaded_module_cellar, default=[], serialized=True50 )51 for ar in lm_cellar:52 module = unarchive_module(ar)53 _loaded_modules.append(module)54 global _initial_loaded_modules55 _initial_loaded_modules = [m.fullname for m in _loaded_modules]56 # return copy so that no one else can modify the loaded modules57 return list(_loaded_modules)58def archive_module(module):59 ar = dict(60 fullname=module.fullname,61 filename=module.filename,62 family=module.family,63 opts=module.opts,64 acquired_as=module.acquired_as,65 refcount=module.refcount,66 modulepath=module.modulepath,67 )68 return ar69def unarchive_module(ar):70 path = ar.get("modulepath")71 if path and not pymod.modulepath.contains(path): # pragma: no cover72 pymod.mc.use(path)73 module = pymod.modulepath.get(ar["filename"])74 if module is None:75 raise pymod.error.ModuleNotFoundError(ar["fullname"])76 assert module.fullname == ar["fullname"]77 module.family = ar["family"]78 module.opts = ar["opts"]79 module.acquired_as = ar["acquired_as"]80 module.refcount = ar["refcount"]81 return module82def set_loaded_modules(modules):83 """Set environment variables for loaded module names and files"""84 global _loaded_modules85 _loaded_modules = modules86 assert all([m.acquired_as is not None for m in _loaded_modules])87 lm = [archive_module(m) for m in _loaded_modules]88 pymod.environ.set(pymod.names.loaded_module_cellar, lm, serialize=True)89 # The following are for compatibility with other module programs90 lm_names = [m.fullname for m in _loaded_modules]91 pymod.environ.set_path(pymod.names.loaded_modules, lm_names)92 lm_files = [m.filename for m in _loaded_modules]93 pymod.environ.set_path(pymod.names.loaded_module_files, lm_files)94def increment_refcount(module):95 module.refcount += 196def decrement_refcount(module):97 module.refcount -= 198def register_module(module):99 """Register the `module` to the list of loaded modules"""100 # Update the environment101 if not pymod.modulepath.contains(module.modulepath):102 raise pymod.error.InconsistentModuleStateError(module)103 if pymod.config.get("skip_add_devpack") and module.name.startswith(104 ("sems-devpack", "devpack")105 ):106 return107 loaded_modules = get_loaded_modules()108 if module not in loaded_modules:109 increment_refcount(module)110 loaded_modules.append(module)111 set_loaded_modules(loaded_modules)112 else:113 raise ModuleRegisteredError(module)114def unregister_module(module):115 """Unregister the `module` to the list of loaded modules"""116 # Don't use `get_loaded_modules` because the module we are unregistering117 # may no longer be available. `get_loaded_modules` makes some assumptions118 # that can be violated in certain situations. Like, for example, # when119 # "unusing" a directory on the MODULEPATH which has loaded modules.120 # Those modules are automaically unloaded since they are no longer121 # available.122 loaded_modules = get_loaded_modules()123 for (i, loaded) in enumerate(loaded_modules):124 if loaded.filename == module.filename:125 break126 else:127 raise ModuleNotRegisteredError(module)128 module.refcount = 0129 loaded_modules.pop(i)130 set_loaded_modules(loaded_modules)131def swapped_explicitly(old, new):132 _swapped_explicitly.append((old, new))133def swapped_on_version_change(old, new):134 _swapped_on_version_change.append((old, new))135def swapped_on_mp_change(old, new):136 _swapped_on_mp_change.append((old, new))137def unloaded_on_mp_change(old):138 _unloaded_on_mp_change.append(old)139def swapped_on_family_update(old, new):140 _swapped_on_family_update.append((old, new))141def format_changed_module_state():142 sio = StringIO()143 debug_mode = pymod.config.get("debug")144 if _loaded_modules is not None and pymod.config.get("verbose"):145 new_modules = [146 m for m in _loaded_modules if m.fullname not in _initial_loaded_modules147 ]148 if new_modules:149 sio.write("The following modules were @G{loaded}\n")150 for (i, m) in enumerate(new_modules):151 sio.write(" {0}) {1}\n".format(i + 1, m.fullname))152 sio.write("\n")153 # Report swapped154 if _swapped_explicitly:155 sio.write("The following modules have been @G{swapped}\n")156 for (i, (m1, m2)) in enumerate(_swapped_explicitly):157 a, b = m1.fullname, m2.fullname158 sio.write(" {0}) {1} => {2}\n".format(i + 1, a, b))159 sio.write("\n")160 # Report reloaded161 if _swapped_on_family_update: # pragma: no cover162 sio.write(163 "The following modules in the same family have "164 "been @G{updated with a version change}\n"165 )166 for (i, (m1, m2)) in enumerate(_swapped_on_family_update):167 a, b, fam = m1.fullname, m2.fullname, m1.family168 sio.write(" {0}) {1} => {2} ({3})\n".format(i + 1, a, b, fam))169 sio.write("\n")170 if _swapped_on_version_change:171 sio.write("The following modules have been @G{updated with a version change}\n")172 for (i, (m1, m2)) in enumerate(_swapped_on_version_change):173 a, b = m1.fullname, m2.fullname174 sio.write(" {0}) {1} => {2}\n".format(i + 1, a, b))175 sio.write("\n")176 # Report changes due to to change in modulepath177 if _unloaded_on_mp_change: # pragma: no cover178 lm_files = [_.filename for _ in get_loaded_modules()]179 unloaded = [_ for _ in _unloaded_on_mp_change if _.filename not in lm_files]180 sio.write(181 "The following modules have been @G{unloaded with a MODULEPATH change}\n"182 )183 for (i, m) in enumerate(unloaded):184 sio.write(" {0}) {1}\n".format(i + 1, m.fullname))185 sio.write("\n")186 if _swapped_on_mp_change:187 sio.write(188 "The following modules have been @G{updated with a MODULEPATH change}\n"189 )190 for (i, (m1, m2)) in enumerate(_swapped_on_mp_change):191 a, b = m1.fullname, m2.fullname192 if debug_mode: # pragma: no cover...

Full Screen

Full Screen

module_reloader.py

Source:module_reloader.py Github

copy

Full Screen

...14from maya import cmds15VERBOSE = True16ANKI_PLUGINS = ['AnkiMenu.py']17ANKI_PACKAGES = ['ankimaya', 'ankiutils', 'ankisdk']18def get_loaded_modules(packages, ignore_this=True):19 """20 By looking in sys.modules, this function will return a21 list of all the modules that are currently loaded from22 the list of packages that was provided.23 """24 loaded_modules = []25 for name, mod in sys.modules.items():26 if mod is None:27 # this appears in sys.modules but is not a loaded object28 continue29 if ignore_this and name == __name__:30 # ignore this module31 continue32 for package in packages:33 if name.startswith(package):34 loaded_modules.append(name)35 if VERBOSE:36 print("Before reloading: {0} -> {1}".format(name, mod))37 break38 return loaded_modules39def reload_plugins(plugins=ANKI_PLUGINS):40 for plugin in plugins:41 if cmds.pluginInfo(plugin, query=True, loaded=True):42 cmds.unloadPlugin(plugin)43 try:44 cmds.loadPlugin(plugin)45 except RuntimeError:46 cmds.warning("Failed to load plugin: {0}".format(plugin))47 else:48 print("Reloaded {0}".format(plugin))49def reload_modules(packages=ANKI_PACKAGES):50 loaded_modules = get_loaded_modules(packages)51 for name in loaded_modules:52 del sys.modules[name]53 for name in loaded_modules:54 importlib.import_module(name)55 if VERBOSE:...

Full Screen

Full Screen

swap.py

Source:swap.py Github

copy

Full Screen

...15 load = PymodCommand("load")16 swap = PymodCommand("swap")17 mock_modulepath(modules_path.one)18 load("a")19 loaded = "".join(_.fullname for _ in pymod.mc.get_loaded_modules())20 assert loaded == "a"21 swap("a", "b")22 loaded = "".join(_.fullname for _ in pymod.mc.get_loaded_modules())...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful