OpenQuizz
Une application de gestion des contenus pédagogiques
CliRunner Class Reference
Inheritance diagram for CliRunner:
Collaboration diagram for CliRunner:

Public Member Functions

def __init__ (self, charset=None, env=None, echo_stdin=False, mix_stderr=True)
 
def get_default_prog_name (self, cli)
 
def make_env (self, overrides=None)
 
def isolation (self, input=None, env=None, color=False)
 
def invoke (self, cli, args=None, input=None, env=None, catch_exceptions=True, color=False, **extra)
 
def isolated_filesystem (self)
 

Data Fields

 charset
 
 env
 
 echo_stdin
 
 mix_stderr
 

Detailed Description

The CLI runner provides functionality to invoke a Click command line
script for unittesting purposes in a isolated environment.  This only
works in single-threaded systems without any concurrency as it changes the
global interpreter state.

:param charset: the character set for the input and output data.  This is
                UTF-8 by default and should not be changed currently as
                the reporting to Click only works in Python 2 properly.
:param env: a dictionary with environment variables for overriding.
:param echo_stdin: if this is set to `True`, then reading from stdin writes
                   to stdout.  This is useful for showing examples in
                   some circumstances.  Note that regular prompts
                   will automatically echo the input.
:param mix_stderr: if this is set to `False`, then stdout and stderr are
                   preserved as independent streams.  This is useful for
                   Unix-philosophy apps that have predictable stdout and
                   noisy stderr, such that each may be measured
                   independently

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  charset = None,
  env = None,
  echo_stdin = False,
  mix_stderr = True 
)

Member Function Documentation

◆ get_default_prog_name()

def get_default_prog_name (   self,
  cli 
)
Given a command object it will return the default program name
for it.  The default is the `name` attribute or ``"root"`` if not
set.

◆ invoke()

def invoke (   self,
  cli,
  args = None,
  input = None,
  env = None,
  catch_exceptions = True,
  color = False,
**  extra 
)
Invokes a command in an isolated environment.  The arguments are
forwarded directly to the command line script, the `extra` keyword
arguments are passed to the :meth:`~clickpkg.Command.main` function of
the command.

This returns a :class:`Result` object.

.. versionadded:: 3.0
   The ``catch_exceptions`` parameter was added.

.. versionchanged:: 3.0
   The result object now has an `exc_info` attribute with the
   traceback if available.

.. versionadded:: 4.0
   The ``color`` parameter was added.

:param cli: the command to invoke
:param args: the arguments to invoke. It may be given as an iterable
     or a string. When given as string it will be interpreted
     as a Unix shell command. More details at
     :func:`shlex.split`.
:param input: the input data for `sys.stdin`.
:param env: the environment overrides.
:param catch_exceptions: Whether to catch any other exceptions than
                 ``SystemExit``.
:param extra: the keyword arguments to pass to :meth:`main`.
:param color: whether the output should contain color codes. The
      application can still override this explicitly.

◆ isolated_filesystem()

def isolated_filesystem (   self)
A context manager that creates a temporary folder and changes
the current working directory to it for isolated filesystem tests.

◆ isolation()

def isolation (   self,
  input = None,
  env = None,
  color = False 
)
A context manager that sets up the isolation for invoking of a
command line tool.  This sets up stdin with the given input data
and `os.environ` with the overrides from the given dictionary.
This also rebinds some internals in Click to be mocked (like the
prompt functionality).

This is automatically done in the :meth:`invoke` method.

.. versionadded:: 4.0
   The ``color`` parameter was added.

:param input: the input stream to put into sys.stdin.
:param env: the environment overrides as dictionary.
:param color: whether the output should contain color codes. The
      application can still override this explicitly.

◆ make_env()

def make_env (   self,
  overrides = None 
)
Returns the environment overrides for invoking a script.

Field Documentation

◆ charset

charset

◆ echo_stdin

echo_stdin

◆ env

env

◆ mix_stderr

mix_stderr

The documentation for this class was generated from the following file: