/usr/lib/python3/dist-packages/twisted/python/test
NameSizeModeActions
__pycache__/-0755rm
deprecatedattributes.py5050644editdlrm
modules_helpers.py18050644editdlrm
pullpipe.py12710644editdlrm
test_appdirs.py10750644editdlrm
test_components.py258260644editdlrm
test_constants.py378240644editdlrm
test_deprecate.py420240644editdlrm
test_fakepwd.py151950644editdlrm
test_htmlizer.py12730644editdlrm
test_inotify.py37100644editdlrm
test_pydoctor.py62140644editdlrm
test_release.py419710644editdlrm
test_runtime.py79920644editdlrm
test_sendmsg.py102740644editdlrm
test_shellcomp.py211670644editdlrm
test_syslog.py51650644editdlrm
test_systemd.py62720644editdlrm
test_textattributes.py6620644editdlrm
test_tzhelper.py38000644editdlrm
test_url.py289600644editdlrm
test_urlpath.py102130644editdlrm
test_util.py348880644editdlrm
test_versions.py52380644editdlrm
test_win32.py20170644editdlrm
test_zippath.py33730644editdlrm
test_zipstream.py120790644editdlrm
__init__.py420644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/python/test/modules_helpers.py (1805B)
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Facilities for helping test code which interacts with Python's module system to load code. """ import sys from types import ModuleType from typing import Iterable, List, Tuple from twisted.python.filepath import FilePath class TwistedModulesMixin: """ A mixin for C{twisted.trial.unittest.SynchronousTestCase} providing useful methods for manipulating Python's module system. """ def replaceSysPath(self, sysPath: List[str]) -> None: """ Replace sys.path, for the duration of the test, with the given value. """ originalSysPath = sys.path[:] def cleanUpSysPath() -> None: sys.path[:] = originalSysPath self.addCleanup(cleanUpSysPath) # type: ignore[attr-defined] sys.path[:] = sysPath def replaceSysModules(self, sysModules: Iterable[Tuple[str, ModuleType]]) -> None: """ Replace sys.modules, for the duration of the test, with the given value. """ originalSysModules = sys.modules.copy() def cleanUpSysModules() -> None: sys.modules.clear() sys.modules.update(originalSysModules) self.addCleanup(cleanUpSysModules) # type: ignore[attr-defined] sys.modules.clear() sys.modules.update(sysModules) def pathEntryWithOnePackage(self, pkgname: str = "test_package") -> FilePath: """ Generate a L{FilePath} with one package, named C{pkgname}, on it, and return the L{FilePath} of the path entry. """ entry = FilePath(self.mktemp()) # type: ignore[attr-defined] pkg = entry.child("test_package") pkg.makedirs() pkg.child("__init__.py").setContent(b"") return entry