SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > > site-packages > testfixtures


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11//site-packages/testfixtures

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
tests Directory - -
__init__.py File 1223 bytes April 17 2025 13:10:58.
comparison.py File 40081 bytes April 17 2025 13:10:58.
compat.py File 224 bytes April 17 2025 13:10:58.
components.py File 1337 bytes April 17 2025 13:10:58.
datetime.py File 25009 bytes April 17 2025 13:10:58.
django.py File 2954 bytes April 17 2025 13:10:58.
logcapture.py File 11013 bytes April 17 2025 13:10:58.
mock.py File 1234 bytes April 17 2025 13:10:58.
outputcapture.py File 4801 bytes April 17 2025 13:10:58.
popen.py File 10124 bytes April 17 2025 13:10:58.
replace.py File 12441 bytes April 17 2025 13:10:58.
resolve.py File 2103 bytes April 17 2025 13:10:58.
rmtree.py File 2584 bytes April 17 2025 13:10:58.
shouldraise.py File 3664 bytes April 17 2025 13:10:58.
shouldwarn.py File 2266 bytes April 17 2025 13:10:58.
sybil.py File 2334 bytes April 17 2025 13:10:58.
tempdirectory.py File 13196 bytes April 17 2025 13:10:58.
twisted.py File 4915 bytes April 17 2025 13:10:58.
utils.py File 2803 bytes April 17 2025 13:10:58.
version.txt File 6 bytes April 17 2025 13:10:58.

Reading File: //opt/cloudlinux/venv/lib64/python3.11//site-packages/testfixtures/sybil.py

import os
import re
import textwrap

from sybil import Region, Example, Document
from testfixtures import diff

FILEBLOCK_START = re.compile(r'^\.\.\s*topic::?\s*(.+)\b', re.MULTILINE)
FILEBLOCK_END = re.compile(r'(\n\Z|\n(?=\S))')
CLASS = re.compile(r'\s+:class:\s*(read|write)-file')


class FileBlock(object):
    def __init__(self, path, content, action):
        self.path, self.content, self.action = path, content, action


class FileParser(object):
    """
    A `Sybil <http://sybil.readthedocs.io>`__ parser that
    parses certain ReST sections to read and write files in the
    configured :class:`~testfixtures.TempDirectory`.

    :param name: This is the name of the :class:`~testfixtures.TempDirectory` to use
                 in the Sybil test namespace.

    """
    def __init__(self, name: str):
        self.name = name

    def __call__(self, document: Document):
        for start_match, end_match, source in document.find_region_sources(
            FILEBLOCK_START, FILEBLOCK_END
        ):
            lines = source.splitlines()
            class_ = CLASS.match(lines[1])
            if not class_:
                continue
            index = 3
            if lines[index].strip() == '::':
                index += 1
            source = textwrap.dedent('\n'.join(lines[index:])).lstrip()
            if source[-1] != '\n':
                source += '\n'

            parsed = FileBlock(
                path=start_match.group(1),
                content=source,
                action=class_.group(1)
            )

            yield Region(
                start_match.start(),
                end_match.end(),
                parsed,
                self.evaluate
            )

    def evaluate(self, example: Example):
        block: FileBlock = example.parsed
        dir = example.namespace[self.name]
        if block.action == 'read':
            actual = dir.read(block.path, 'ascii').replace(os.linesep, '\n')
            if actual != block.content:
                return diff(
                    block.content,
                    actual,
                    'File %r, line %i:' % (example.path, example.line),
                    'Reading from "%s":' % dir.as_string(block.path)
                )
        if block.action == 'write':
            dir.write(block.path, block.content, 'ascii')

SILENT KILLER Tool