""" Helpers for working with Zope and its components. """ import atexit import warnings from typing import Set from zope.component import getSiteManager from zope.interface.registry import Components class TestComponents: """ A helper for providing a sterile registry when testing with ``zope.component``. Instantiation will install an empty registry that will be returned by :func:`zope.component.getSiteManager`. """ __test__: bool = False instances: Set['TestComponents'] = set() atexit_setup: bool = False def __init__(self): self.registry: Components = Components('Testing') self.old: Components = getSiteManager.sethook(lambda: self.registry) self.instances.add(self) if not self.__class__.atexit_setup: atexit.register(self.atexit) self.__class__.atexit_setup = True def uninstall(self): """ Remove the sterile registry and replace it with the one that was in place before this :class:`TestComponents` was instantiated. """ getSiteManager.sethook(self.old) self.instances.remove(self) @classmethod def atexit(cls): if cls.instances: warnings.warn( 'TestComponents instances not uninstalled by shutdown!' )
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
tests | Folder | 0755 |
|
|
__init__.py | File | 1.19 KB | 0644 |
|
comparison.py | File | 39.14 KB | 0644 |
|
compat.py | File | 224 B | 0644 |
|
components.py | File | 1.31 KB | 0644 |
|
datetime.py | File | 24.42 KB | 0644 |
|
django.py | File | 2.88 KB | 0644 |
|
logcapture.py | File | 10.75 KB | 0644 |
|
mock.py | File | 1.21 KB | 0644 |
|
outputcapture.py | File | 4.69 KB | 0644 |
|
popen.py | File | 9.89 KB | 0644 |
|
replace.py | File | 12.15 KB | 0644 |
|
resolve.py | File | 2.05 KB | 0644 |
|
rmtree.py | File | 2.52 KB | 0644 |
|
shouldraise.py | File | 3.58 KB | 0644 |
|
shouldwarn.py | File | 2.21 KB | 0644 |
|
sybil.py | File | 2.28 KB | 0644 |
|
tempdirectory.py | File | 12.89 KB | 0644 |
|
twisted.py | File | 4.8 KB | 0644 |
|
utils.py | File | 2.74 KB | 0644 |
|
version.txt | File | 6 B | 0644 |
|