testsuite.utils
Miscellaneous helpers.
Attributes
Classes
Stub to replace colorama's Fore/Style when colors are disabled. |
|
Proxy for color management. |
|
Mode for working space cleanups. |
Functions
|
Return whether stream is a TTY. |
|
Turn enum alternatives into command-line arguments. |
|
Dump environment variables into a sourceable file. |
|
Prepend |
|
Traverse a directory hierarchy following symlinks in a safe way. |
Module Contents
- testsuite.utils.isatty(stream: IO[AnyStr]) bool
Return whether stream is a TTY.
This is a safe predicate: it works if stream is None or if it does not even support TTY detection: in these cases, be conservative (consider it’s not a TTY).
- class testsuite.utils.DummyColors
Stub to replace colorama’s Fore/Style when colors are disabled.
- __getattr__(name: str) str
- class testsuite.utils.ColorConfig(colors_enabled: bool | None = None)
Proxy for color management.
This embeds colorama’s Fore/Style, or DummyColors instances when colors are disabled.
- Fore: colorama.ansi.AnsiFore | DummyColors
- Style: colorama.ansi.AnsiStyle | DummyColors
- class testsuite.utils.CleanupMode(*args, **kwds)
Bases:
enum.EnumMode for working space cleanups.
- NONE
- PASSING
- ALL
- classmethod default() CleanupMode
- classmethod descriptions() Dict[CleanupMode, str]
- testsuite.utils.EnumType
- testsuite.utils.enum_to_cmdline_args_map(enum_cls: Type[EnumType]) Dict[str, EnumType]
Turn enum alternatives into command-line arguments.
This helps exposing enums for options on the command-line. This turns alternative names into lower case and replaces underscores with dashes.
- testsuite.utils.dump_environ(filename: str, env: e3.env.Env) None
Dump environment variables into a sourceable file.
- testsuite.utils.indent(text: str, prefix: str = ' ') str
Prepend
prefixto every line intext.- Parameters:
text – Text to transform.
prefix – String to prepend.
- testsuite.utils.safe_dir_walk(top: str) Iterator[tuple[str, list[str], list[str]]]
Traverse a directory hierarchy following symlinks in a safe way.
This is essentially a wrapper around os.walk() to safely follow symbolic links that keeps track of the directories traversed to avoid infinite recursion in case of symbolic link loops.