Return a new copy of the test._crossinterp_definitions module. The module's __name__ matches the "module" arg, which is either a str or a module. If the "module" arg is a module then the just-loaded defs are also copied into that module. Note that the new module is not added t
(module=None)
| 314 | |
| 315 | |
| 316 | def load_defs(module=None): |
| 317 | """Return a new copy of the test._crossinterp_definitions module. |
| 318 | |
| 319 | The module's __name__ matches the "module" arg, which is either |
| 320 | a str or a module. |
| 321 | |
| 322 | If the "module" arg is a module then the just-loaded defs are also |
| 323 | copied into that module. |
| 324 | |
| 325 | Note that the new module is not added to sys.modules. |
| 326 | """ |
| 327 | if module is None: |
| 328 | modname = DEFS.__name__ |
| 329 | elif isinstance(module, str): |
| 330 | modname = module |
| 331 | module = None |
| 332 | else: |
| 333 | modname = module.__name__ |
| 334 | # Create the new module and populate it. |
| 335 | defs = import_helper.create_module(modname) |
| 336 | defs.__file__ = DEFS.__file__ |
| 337 | exec(DEFS_TEXT, defs.__dict__) |
| 338 | # Copy the defs into the module arg, if any. |
| 339 | if module is not None: |
| 340 | for name, value in defs.__dict__.items(): |
| 341 | if name.startswith('_'): |
| 342 | continue |
| 343 | assert not hasattr(module, name), (name, getattr(module, name)) |
| 344 | setattr(module, name, value) |
| 345 | return defs |
| 346 | |
| 347 | |
| 348 | @contextlib.contextmanager |
no test coverage detected
searching dependent graphs…