예제 #1
0
        "Simulate calls to :meth:`subprocess.Popen.terminate`"
        pass

    def kill(self):
        "Simulate calls to :meth:`subprocess.Popen.kill`"
        pass


set_command_params = """
:param stdout:
    A string representing the simulated content written by the process
    to the stdout pipe.
:param stderr:
    A string representing the simulated content written by the process
    to the stderr pipe.
:param returncode:
    An integer representing the return code of the simulated process.
:param pid:
    An integer representing the process identifier of the simulated
    process. This is useful if you have code the prints out the pids
    of running processes.
:param poll_count:
    Specifies the number of times :meth:`MockPopen.poll` can be
    called before :attr:`MockPopen.returncode` is set and returned
    by :meth:`MockPopen.poll`.
"""


# add the param docs, so we only have one copy of them!
extend_docstring(set_command_params, [MockPopen.set_command, MockPopen.set_default])
예제 #2
0
    def __init__(self, target, replacement, strict=True):
        self.target = target
        self.replacement = replacement
        self.strict = strict
        self._replacer = Replacer()

    def __enter__(self):
        return self._replacer(self.target, self.replacement, self.strict)

    def __exit__(self, exc_type, exc_val, exc_tb):
        self._replacer.restore()


replace_params_doc = """
:param target: A string containing the dotted-path to the
               object to be replaced. This path may specify a
               module in a package, an attribute of a module,
               or any attribute of something contained within
               a module.

:param replacement: The object to use as a replacement.

:param strict: When `True`, an exception will be raised if an
               attempt is made to replace an object that does
               not exist.
"""

# add the param docs, so we only have one copy of them!
extend_docstring(replace_params_doc,
                 [Replacer.__call__, Replacer.replace, replace, Replace])
예제 #3
0
        return MockPopenInstance(self, root_call, *args, **kw)


set_command_params = """
:param stdout:
    A string representing the simulated content written by the process
    to the stdout pipe.
:param stderr:
    A string representing the simulated content written by the process
    to the stderr pipe.
:param returncode:
    An integer representing the return code of the simulated process.
:param pid:
    An integer representing the process identifier of the simulated
    process. This is useful if you have code the prints out the pids
    of running processes.
:param poll_count:
    Specifies the number of times :meth:`MockPopen.poll` can be
    called before :attr:`MockPopen.returncode` is set and returned
    by :meth:`MockPopen.poll`.

If supplied, ``behaviour`` must be either a :class:`PopenBehaviour`
instance or a callable that takes the ``command`` string representing
the command to be simulated and the ``stdin`` for that command and
returns a :class:`PopenBehaviour` instance.
"""

# add the param docs, so we only have one copy of them!
extend_docstring(set_command_params,
                 [MockPopen.set_command, MockPopen.set_default])
예제 #4
0
    def __init__(self, target, replacement, strict=True):
        self.target = target
        self.replacement = replacement
        self.strict = strict
        self._replacer = Replacer()

    def __enter__(self):
        return self._replacer(self.target, self.replacement, self.strict)

    def __exit__(self, exc_type, exc_val, exc_tb):
        self._replacer.restore()

replace_params_doc = """
:param target: A string containing the dotted-path to the
               object to be replaced. This path may specify a
               module in a package, an attribute of a module,
               or any attribute of something contained within
               a module.

:param replacement: The object to use as a replacement.

:param strict: When `True`, an exception will be raised if an
               attempt is made to replace an object that does
               not exist.
"""

# add the param docs, so we only have one copy of them!
extend_docstring(replace_params_doc,
                 [Replacer.__call__, Replacer.replace, replace, Replace])