Skip to content

Commit

Permalink
Revert changes in wait_output and fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Aug 22, 2023
1 parent 9be8ab9 commit 33297a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ def _wait(self) -> int:
exit_code = change.tasks[0].data.get('exit-code', -1)
return exit_code

def wait_output(self) -> Tuple[Optional[AnyStr], Optional[AnyStr]]:
def wait_output(self) -> Tuple[AnyStr, Optional[AnyStr]]:
"""Wait for the process to finish and return tuple of (stdout, stderr).
If a timeout was specified to the :meth:`Client.exec` call, this waits
Expand Down Expand Up @@ -1350,7 +1350,7 @@ def wait_output(self) -> Tuple[Optional[AnyStr], Optional[AnyStr]]:

exit_code: int = self._wait()

out_value = typing.cast(AnyStr, out.getvalue()) if out is not None else None
out_value = typing.cast(AnyStr, out.getvalue())
err_value = typing.cast(AnyStr, err.getvalue()) if err is not None else None
if exit_code != 0:
raise ExecError[AnyStr](self._command, exit_code, out_value, err_value)
Expand Down
13 changes: 6 additions & 7 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@

@dataclasses.dataclass
class ExecArgs:
"""Represent arguments captured from the :meth:`ops.model.Container.exec` method call.
"""Represent arguments captured from the :meth:`ops.Container.exec` method call.
These arguments will be passed to the :class:`ops.testing.ExecHandler` handler function.
See :meth:`ops.model.Container.exec` for documentation of properties.
These arguments will be passed to the ``ops.testing.ExecHandler`` handler function.
See :meth:`ops.Container.exec` for documentation of properties.
"""
command: List[str]
environment: Dict[str, str]
Expand All @@ -134,7 +134,7 @@ class ExecResult:
"""Represents the result of a simulated process execution.
This class is typically used to return the output and exit code from the
:class:`ops.testing.ExecHandler` handler function.
``ops.testing.ExecHandler`` handler function.
"""
exit_code: int = 0
stdout: Union[str, bytes] = b""
Expand Down Expand Up @@ -1591,7 +1591,7 @@ def handle_exec(self,
"""Register a handler to simulate the pebble command execution.
This allows a test harness to simulate the behavior of running commands in a container.
When :meth:`ops.model.Container.exec` is triggered, the registered handler is used to
When :meth:`ops.Container.exec` is triggered, the registered handler is used to
simulate the process execution.
You can provide:
Expand All @@ -1613,7 +1613,7 @@ def handle_exec(self,
The execution handler receives the timeout value in ExecArgs. If needed, it can raise a
TimeoutError to inform the harness of a timeout occurrence.
If :meth:`ops.model.Container.exec` is called with ``combine_stderr=True``, the execution
If :meth:`ops.Container.exec` is called with ``combine_stderr=True``, the execution
handler should, if required, weave the simulated standard error into the standard output.
The harness checks the result and will raise an exception if stderr is non-empty.
Expand Down Expand Up @@ -2878,7 +2878,6 @@ def remove_path(self, path: str, *, recursive: bool = False):
file_path.unlink()

def _find_exec_handler(self, command: List[str]) -> Optional[ExecHandler]:
print(self._exec_handlers)
for command_prefix, handler in self._exec_handlers:
if tuple(command[:len(command_prefix)]) == command_prefix:
return handler
Expand Down

0 comments on commit 33297a9

Please sign in to comment.