canonical / operator

Pure Python framework for writing Juju charms
Apache License 2.0
246 stars 119 forks source link

Pass charm type to Context.manager #1444

Open Batalex opened 6 days ago

Batalex commented 6 days ago

Hi,

When I am writing tests using the new testing framework formerly known as scenario, I find myself adding a line like this:

    with ctx(ctx.on.start(), state_in) as manager:
        charm = cast(KafkaCharm, manager.charm)  #  <-- This line...
        assert not charm.broker.healthy  # <-- ...gives me autocomplete and type checker validation

In larger code bases, this boilerplate adds up to numerous lines.

With a few tweaks to Context and Manager, we can make them variadic types and get this nice user experience:

Capture d’écran du 2024-10-31 17-27-55

If that's something you are interested in, I can open a PR. Have a look at my branch on ops-scenario, and let me know what you think!

tonyandrewmeyer commented 6 days ago

If that's something you are interested in, I can open a PR. Have a look at my branch on ops-scenario, and let me know what you think!

That would be great, thanks!