ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.110 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/opt/alt/python37/lib/python3.7/site-packages/testfixtures/ |
Upload File : |
# Copyright (c) 2010-2011 Simplistix Ltd
# See license.txt for license details.
import atexit
import warnings
from zope.component import getSiteManager
from zope.component.registry import Components
class TestComponents:
"""
A helper for providing a sterile registry when testing
with :mod:`zope.component`.
Instantiation will install an empty registry that will be returned
by :func:`zope.component.getSiteManager`.
"""
instances = set()
atexit_setup = False
def __init__(self):
self.registry = Components('Testing')
self.old = 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!'
)