LogCliRunner¶
- class lsst.daf.butler.cli.utils.LogCliRunner(charset: str = 'utf-8', env: Mapping[str, str | None] | None = None, echo_stdin: bool = False, mix_stderr: bool = True)¶
- Bases: - CliRunner- A test runner to use when the logging system will be initialized by code under test, calls CliLog.resetLog(), which undoes any logging setup that was done with the CliLog interface. - lsst.log modules can not be set back to an uninitialized state (python logging modules can be set back to NOTSET), instead they are set to - CliLog.defaultLsstLogLevel.- Methods Summary - Given a command object it will return the default program name for it. - invoke(*args, **kwargs)- Invokes a command in an isolated environment. - isolated_filesystem([temp_dir])- A context manager that creates a temporary directory and changes the current working directory to it. - isolation([input, env, color])- A context manager that sets up the isolation for invoking of a command line tool. - make_env([overrides])- Returns the environment overrides for invoking a script. - Methods Documentation - get_default_prog_name(cli: BaseCommand) str¶
- Given a command object it will return the default program name for it. The default is the - nameattribute or- "root"if not set.
 - invoke(*args: Any, **kwargs: Any) Result¶
- Invokes a command in an isolated environment. The arguments are forwarded directly to the command line script, the - extrakeyword arguments are passed to the- main()function of the command.- This returns a - Resultobject.- Parameters:
- cli – the command to invoke 
- 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 - shlex.split().
- input – the input data for - sys.stdin.
- env – the environment overrides. 
- catch_exceptions – Whether to catch any other exceptions than - SystemExit.
- extra – the keyword arguments to pass to - main().
- color – whether the output should contain color codes. The application can still override this explicitly. 
 
 - Changed in version 8.0: The result object has the - return_valueattribute with the value returned from the invoked command.- Changed in version 4.0: Added the - colorparameter.- Changed in version 3.0: Added the - catch_exceptionsparameter.- Changed in version 3.0: The result object has the - exc_infoattribute with the traceback if available.
 - isolated_filesystem(temp_dir: str | PathLike[str] | None = None) Iterator[str]¶
- A context manager that creates a temporary directory and changes the current working directory to it. This isolates tests that affect the contents of the CWD to prevent them from interfering with each other. - Parameters:
- temp_dir – Create the temporary directory under this directory. If given, the created directory is not removed when exiting. 
 - Changed in version 8.0: Added the - temp_dirparameter.
 - isolation(input: str | bytes | IO[Any] | None = None, env: Mapping[str, str | None] | None = None, color: bool = False) Iterator[Tuple[BytesIO, BytesIO | None]]¶
- 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.environwith 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 - invoke()method.- Parameters:
- input – the input stream to put into sys.stdin. 
- env – the environment overrides as dictionary. 
- color – whether the output should contain color codes. The application can still override this explicitly. 
 
 - Changed in version 8.0: - stderris opened with- errors="backslashreplace"instead of the default- "strict".- Changed in version 4.0: Added the - colorparameter.