Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a5dadbd
ci: switch to individual files for type checking scenario tests.
tonyandrewmeyer Dec 13, 2025
8aed1fb
test: add type annotations for test_secrets.
tonyandrewmeyer Dec 13, 2025
4a15063
test: add type annotations to test_relations.
tonyandrewmeyer Dec 13, 2025
56c1b98
ci: remove unnecessary exclude.
tonyandrewmeyer Dec 13, 2025
796720b
test: add type annotations to test_juju_log
tonyandrewmeyer Dec 13, 2025
5d255f0
test: add type annotations for test_status.
tonyandrewmeyer Dec 13, 2025
0f5ca37
test: add type annotations to test_storage
tonyandrewmeyer Dec 13, 2025
ffa4e13
test: add type annotations to test_manager.
tonyandrewmeyer Dec 13, 2025
362feb7
test: add type annotations to test_ports.
tonyandrewmeyer Dec 13, 2025
dbce9c0
test: add type annotations to test_rubbish_events.
tonyandrewmeyer Dec 14, 2025
0f97dd7
test: add type annotaitons for test_pebble.
tonyandrewmeyer Dec 14, 2025
04ef78c
Update testing/tests/test_e2e/test_juju_log.py
tonyandrewmeyer Dec 14, 2025
be57cb5
fix: update the asserts to match the corrected layer values.
tonyandrewmeyer Dec 14, 2025
2eb63d2
fix: correct the call and type annotation, we're replacing a bound me…
tonyandrewmeyer Dec 14, 2025
55a7930
chore: remove -> None.
tonyandrewmeyer Dec 15, 2025
e243933
chore: remove scopes from type: ignore.
tonyandrewmeyer Dec 15, 2025
d58d19a
Merge origin/main.
tonyandrewmeyer Dec 16, 2025
effb48f
Post merge fixes.
tonyandrewmeyer Dec 16, 2025
7028747
Add generic type to avoid ignore.
tonyandrewmeyer Dec 18, 2025
19c2982
Reformat per review request.
tonyandrewmeyer Dec 18, 2025
f884387
Remove return type annotation per review request.
tonyandrewmeyer Dec 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,31 @@ convention = "google"
builtins-ignorelist = ["id", "min", "map", "range", "type", "TimeoutError", "ConnectionError", "Warning", "input", "format"]

[tool.pyright]
include = ["ops/*.py", "ops/_private/*.py", "test/*.py", "test/charms/*/src/*.py", "testing/src/*.py"]
exclude = ["tracing/*"]
include = ["ops/*.py", "ops/_private/*.py", "test/*.py", "test/charms/*/src/*.py", "testing/src/*.py", "testing/tests/*.py", "testing/tests/test_e2e/*.py"]
exclude = [
"tracing/*",
"testing/tests/helpers.py",
"testing/tests/test_charm_spec_autoload.py",
"testing/tests/test_consistency_checker.py",
"testing/tests/test_context_on.py",
"testing/tests/test_context.py",
"testing/tests/test_emitted_events_util.py",
"testing/tests/test_plugin.py",
"testing/tests/test_runtime.py",
"testing/tests/test_e2e/test_network.py",
"testing/tests/test_e2e/test_cloud_spec.py",
"testing/tests/test_e2e/test_play_assertions.py",
"testing/tests/test_e2e/test_vroot.py",
"testing/tests/test_e2e/__init__.py",
"testing/tests/test_e2e/test_resource.py",
"testing/tests/test_e2e/test_state.py",
"testing/tests/test_e2e/test_actions.py",
"testing/tests/test_e2e/test_config.py",
"testing/tests/test_e2e/test_event.py",
"testing/tests/test_e2e/test_deferred.py",
"testing/tests/test_e2e/test_stored_state.py",
"testing/tests/test_e2e/conftest.py",
]
extraPaths = ["testing", "tracing"]
pythonVersion = "3.10" # check no python > 3.10 features are used
pythonPlatform = "All"
Expand Down
2 changes: 1 addition & 1 deletion testing/src/scenario/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def services(self) -> dict[str, pebble.ServiceInfo]:
infos[name] = info
return infos

def get_filesystem(self, ctx: Context) -> pathlib.Path:
def get_filesystem(self, ctx: Context[CharmBase]) -> pathlib.Path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this become ctx: Context[Any] in the other PR?

"""Simulated Pebble filesystem in this context.

Returns:
Expand Down
14 changes: 7 additions & 7 deletions testing/tests/test_e2e/test_juju_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
from scenario import Context
from scenario.state import JujuLogLine, State

from ops.charm import CharmBase, CollectStatusEvent
import ops

logger = logging.getLogger('testing logger')


@pytest.fixture(scope='function')
def mycharm():
class MyCharm(CharmBase):
class MyCharm(ops.CharmBase):
META: Mapping[str, Any] = {'name': 'mycharm'}

def __init__(self, framework):
def __init__(self, framework: ops.Framework):
super().__init__(framework)
for evt in self.on.events().values():
self.framework.observe(evt, self._on_event)
framework.observe(evt, self._on_event)

def _on_event(self, event):
if isinstance(event, CollectStatusEvent):
def _on_event(self, event: ops.EventBase):
if isinstance(event, ops.CollectStatusEvent):
return
print('foo!')
logger.warning('bar!')

return MyCharm


def test_juju_log(mycharm):
def test_juju_log(mycharm: Any):
ctx = Context(mycharm, meta=mycharm.META)
ctx.run(ctx.on.start(), State())
assert JujuLogLine(level='DEBUG', message='Emitting Juju event start.') in ctx.juju_log
Expand Down
28 changes: 14 additions & 14 deletions testing/tests/test_e2e/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@

import pytest
from scenario import Context, State
from scenario.context import AlreadyEmittedError, Manager
from scenario.context import Manager
from scenario.errors import AlreadyEmittedError

from ops import ActiveStatus
from ops.charm import CharmBase, CollectStatusEvent
import ops


@pytest.fixture(scope='function')
def mycharm():
class MyCharm(CharmBase):
class MyCharm(ops.CharmBase):
META: Mapping[str, Any] = {'name': 'mycharm'}
ACTIONS: Mapping[str, Any] = {'do-x': {}}

def __init__(self, framework):
def __init__(self, framework: ops.Framework):
super().__init__(framework)
for evt in self.on.events().values():
self.framework.observe(evt, self._on_event)
framework.observe(evt, self._on_event)

def _on_event(self, e):
if isinstance(e, CollectStatusEvent):
def _on_event(self, e: ops.EventBase):
if isinstance(e, ops.CollectStatusEvent):
return

self.unit.status = ActiveStatus(e.handle.kind)
self.unit.status = ops.ActiveStatus(e.handle.kind)

return MyCharm


def test_manager(mycharm):
def test_manager(mycharm: Any):
ctx = Context(mycharm, meta=mycharm.META)
with Manager(ctx, ctx.on.start(), State()) as manager:
assert isinstance(manager.charm, mycharm)
Expand All @@ -43,7 +43,7 @@ def test_manager(mycharm):
assert isinstance(state_out, State)


def test_manager_implicit(mycharm):
def test_manager_implicit(mycharm: Any):
ctx = Context(mycharm, meta=mycharm.META)
with Manager(ctx, ctx.on.start(), State()) as manager:
assert isinstance(manager.charm, mycharm)
Expand All @@ -53,23 +53,23 @@ def test_manager_implicit(mycharm):
assert manager._emitted


def test_manager_reemit_fails(mycharm):
def test_manager_reemit_fails(mycharm: Any):
ctx = Context(mycharm, meta=mycharm.META)
with Manager(ctx, ctx.on.start(), State()) as manager:
manager.run()
with pytest.raises(AlreadyEmittedError):
manager.run()


def test_context_manager(mycharm):
def test_context_manager(mycharm: Any):
ctx = Context(mycharm, meta=mycharm.META)
with ctx(ctx.on.start(), State()) as manager:
state_out = manager.run()
assert isinstance(state_out, State)
assert ctx.emitted_events[0].handle.kind == 'start'


def test_context_action_manager(mycharm):
def test_context_action_manager(mycharm: Any):
ctx = Context(mycharm, meta=mycharm.META, actions=mycharm.ACTIONS)
with ctx(ctx.on.action('do-x'), State()) as manager:
state_out = manager.run()
Expand Down
Loading