Skip to content

Commit

Permalink
Minor fixes based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Aug 12, 2024
1 parent 71525f0 commit 5000836
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ def test_pebble_exec():
ctx.on.pebble_ready(container),
state_in,
)
assert ctx.exec_history[container.name].command == ['ls', '-ll']
assert ctx.exec_history[container.name].stdin == "..."
assert ctx.exec_history[container.name][0].command == ['ls', '-ll']
assert ctx.exec_history[container.name][0].stdin == "..."
```

Scenario will attempt to find the right `Exec` object by matching the provided
Expand Down
4 changes: 2 additions & 2 deletions scenario/context.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
import collections
import tempfile
from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union, cast

from ops import CharmBase, EventBase
from ops.testing import ExecArgs

from scenario.logger import logger as scenario_logger
from scenario.runtime import Runtime
Expand Down Expand Up @@ -451,7 +451,7 @@ def __init__(
self.juju_log: List["JujuLogLine"] = []
self.app_status_history: List["_EntityStatus"] = []
self.unit_status_history: List["_EntityStatus"] = []
self.exec_history = collections.defaultdict(list)
self.exec_history: Dict[str, List[ExecArgs]] = {}
self.workload_version_history: List[str] = []
self.removed_secret_revisions: List[int] = []
self.emitted_events: List[EventBase] = []
Expand Down
27 changes: 15 additions & 12 deletions scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,19 +844,22 @@ def exec(
stderr.write(handler.stderr)

args = ExecArgs(
command,
environment or {},
working_dir,
timeout,
user_id,
user,
group_id,
group,
stdin, # type:ignore # If None, will be replaced by proc_stdin.read() later.
encoding,
combine_stderr,
command=command,
environment=environment or {},
working_dir=working_dir,
timeout=timeout,
user_id=user_id,
user=user,
group_id=group_id,
group=group,
stdin=stdin, # type:ignore # If None, will be replaced by proc_stdin.read() later.
encoding=encoding,
combine_stderr=combine_stderr,
)
self._context.exec_history[self._container_name].append(args)
try:
self._context.exec_history[self._container_name].append(args)
except KeyError:
self._context.exec_history[self._container_name] = [args]

change_id = handler._run()
return cast(
Expand Down

0 comments on commit 5000836

Please sign in to comment.