Skip to content

Commit

Permalink
chore: fix types for full status fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Nov 26, 2024
1 parent 2dce754 commit 6768777
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ ignore = [
# These are tentative
include = ["**/*.py"]
pythonVersion = "3.8.6"
typeCheckingMode = "strict"
useLibraryCodeForTypes = true
#typeCheckingMode = "strict"
#useLibraryCodeForTypes = true
reportGeneralTypeIssues = true

[tool.pytest.ini_options]
Expand Down
27 changes: 16 additions & 11 deletions tests/unit/test_wait_for_idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
# Licensed under the Apache V2, see LICENCE file for details.
from __future__ import annotations

# pyright: reportPrivateUsage=false
import copy
import json
from datetime import datetime, timedelta
from typing import Any
from unittest.mock import Mock

import pytest
from typing_extensions import reveal_type as reveal_type

from juju.application import Application
from juju.client._definitions import FullStatus
from juju.client._definitions import (
ApplicationStatus,
FullStatus,
MachineStatus,
UnitStatus,
)
from juju.client.facade import _convert_response
from juju.errors import JujuAgentError, JujuAppError, JujuMachineError, JujuUnitError
from juju.machine import Machine
Expand Down Expand Up @@ -344,8 +349,8 @@ def model_fake(resp: dict[str, Any]) -> ModelFake:
app = m._applications[name] = ApplicationFake(name, m)

fsapp = fs.applications[name]
assert fsapp
assert fsapp.status # DetailedStatus
assert isinstance(fsapp, ApplicationStatus)
assert fsapp.status
assert isinstance(fsapp.status.status, str)
assert isinstance(fsapp.status.info, str)
app.set_status(fsapp.status.status, fsapp.status.info)
Expand All @@ -354,16 +359,16 @@ def model_fake(resp: dict[str, Any]) -> ModelFake:
app._units.append(unit := UnitFake(uname, m))

fsunit = fsapp.units[uname]
assert fsunit
assert isinstance(fsunit, UnitStatus)

assert fsunit.agent_status # DetailedStatus
assert fsunit.agent_status
assert isinstance(fsunit.agent_status.status, str)
unit._agent_status = fsunit.agent_status.status

assert isinstance(fsunit.agent_status.info, str)
unit._agent_status_message = fsunit.agent_status.info

assert fsunit.workload_status # DetailedStatus
assert fsunit.workload_status
assert isinstance(fsunit.workload_status.status, str)
unit._workload_status = fsunit.workload_status.status

Expand All @@ -376,7 +381,7 @@ def model_fake(resp: dict[str, Any]) -> ModelFake:
for name, machine in fs.machines.items():
mac = m._machines[name] = MachineFake(name, m)
mac._id = name
assert machine
assert isinstance(machine, MachineStatus)
assert machine.instance_status
assert isinstance(machine.instance_status.status, str)
mac._status = machine.instance_status.status
Expand Down Expand Up @@ -479,7 +484,7 @@ async def test_model_fake(full_status_response: dict[str, Any]):
"""Self-test for model_fake helper"""
m = model_fake(full_status_response)

app = m._applications["hexanator"] # type: ignore[reportPrivateUsage]
app = m._applications["hexanator"]
assert len(app._units) == 1

u = app._units[0]
Expand All @@ -488,7 +493,7 @@ async def test_model_fake(full_status_response: dict[str, Any]):
assert u._workload_status == "active"
assert not u._workload_status_message

app = m._applications["grafana-agent-k8s"] # type: ignore[reportPrivateUsage]
app = m._applications["grafana-agent-k8s"]
assert len(app._units) == 1

u = app._units[0]
Expand All @@ -497,7 +502,7 @@ async def test_model_fake(full_status_response: dict[str, Any]):
assert u._workload_status == "blocked"
assert u._workload_status_message.startswith("Missing incoming")

app = m._applications["mysql-test-app"] # type: ignore[reportPrivateUsage]
app = m._applications["mysql-test-app"]
assert len(app._units) == 2

u = [u for u in app._units if u.name.endswith("/0")][0]
Expand Down

0 comments on commit 6768777

Please sign in to comment.