Skip to content

Improve .model type hint #143

Open
Open
@dimaqq

Description

It seems that most charms' integration tests assume that ops_test.model is truthy (6592 call sites):

async def setup_env(ops_test: OpsTest):
    await ops_test.model.set_config(...)

And a few ensure that it's truthy (46 call sites):

async def test_integrate(ops_test: OpsTest):
    assert ops_test.model is not None
    await asyncio.gather(
        ops_test.model.integrate("mimir:s3", "s3"),
        ...
    )

I didn't find a single test that's conditional on the model being or not being there. We're tracking ~160 charming repos in https://github.com/tonyandrewmeyer/charm-analysis

Currently, it's typed so:

    @property
    def model(self) -> Optional[Model]:
        """Represents the current model."""
        current_state = self.current_alias and self._models.get(self.current_alias)
        return current_state.model if current_state else None

I'm proposing to type it as Model and raise if the model is not available.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions