Command-line arguments and standard input and output as a service
(Effect's Stdio).
StdioService holds the arguments, whether each standard stream is a
terminal, sinks writing to standard output and error, and standard input as
a byte stream::
io = yield from Stdio()
yield from stream.make("hello\n").run(io.stdout())layer is the process's (sys.argv[1:], sys.stdin / stdout /
stderr, read when used, so a replaced sys.stdout is seen);
layer_test builds one for tests from the parts a test cares about.
Values#
| Attribute | Type | Description |
|---|---|---|
live | StdioService | The process's arguments and standard streams. Reads and writes run on a worker thread; an interrupted read leaves its thread waiting for input. |
layer | Layer[Stdio] | The live |
Types#
| Type | Definition | Description |
|---|---|---|
Output | type Output = Sink[None, str | bytes, Never, PlatformError] |
Classes#
Functions#
layer_test#
layer_test(*, args=None, stdout=_drain, stderr=_drain, stdin=None, stdin_is_terminal=None, stdout_is_terminal=None, stderr_is_terminal=None) -> Layer[Stdio]A Stdio for tests: no arguments, output drained, empty input and
no terminals, unless given.
| Parameter | Type | Description |
|---|---|---|
args | Effect[tuple[str, ...]] | None = None | |
stdout | OutputSink = _drain | |
stderr | OutputSink = _drain | |
stdin | Stream[bytes, PlatformError] | None = None | |
stdin_is_terminal | Effect[bool] | None = None | |
stdout_is_terminal | Effect[bool] | None = None | |
stderr_is_terminal | Effect[bool] | None = None |
Returns Layer[Stdio]
def layer_test(
*,
args: Effect[tuple[str, ...]] | None = None,
stdout: OutputSink = _drain,
stderr: OutputSink = _drain,
stdin: Stream[bytes, PlatformError] | None = None,
stdin_is_terminal: Effect[bool] | None = None,
stdout_is_terminal: Effect[bool] | None = None,
stderr_is_terminal: Effect[bool] | None = None,
) -> Layer[Stdio]:
"""A ``Stdio`` for tests: no arguments, output drained, empty input and
no terminals, unless given."""
return layer_succeed(
Stdio,
StdioService(
args=succeed(()) if args is None else args,
stdout=stdout,
stderr=stderr,
stdin=stream_.empty if stdin is None else stdin,
stdin_is_terminal=_false() if stdin_is_terminal is None else stdin_is_terminal,
stdout_is_terminal=_false() if stdout_is_terminal is None else stdout_is_terminal,
stderr_is_terminal=_false() if stderr_is_terminal is None else stderr_is_terminal,
),
)