PHP 8.2.30
Preview: components.py Size: 1.31 KB
//opt/cloudlinux/venv/lib/python3.11/site-packages/testfixtures/components.py

"""
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!'
                )

Directory Contents

Dirs: 2 × Files: 20

Name Size Perms Modified Actions
tests DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
39.14 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
224 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.31 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
24.42 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.88 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
10.75 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.21 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
4.69 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
9.89 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
12.15 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.05 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.52 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.58 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.21 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.28 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
12.89 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
4.80 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.74 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
6 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.19 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).