Fix linting and type errors for CI
- Use X | None syntax instead of Optional[X] (UP045) - Sort imports in dashboard app (I001) - Remove unnecessary UTF-8 encoding argument (UP012) - Add 'from err' to exception re-raises (B904) - Remove unused imports in integration tests (F401) - Fix useless expression in test (B018) - Cast **1.5 result to float in LDO model (mypy no-any-return) - Use functools.partial instead of lambda in server (mypy misc)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"""Command-line interface for py_dvt_ate."""
|
"""Command-line interface for py_dvt_ate."""
|
||||||
|
|
||||||
from typing import Annotated, Optional
|
from typing import Annotated
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ def version_callback(value: bool) -> None:
|
|||||||
@app.callback()
|
@app.callback()
|
||||||
def main(
|
def main(
|
||||||
version: Annotated[
|
version: Annotated[
|
||||||
Optional[bool],
|
bool | None,
|
||||||
typer.Option(
|
typer.Option(
|
||||||
"--version",
|
"--version",
|
||||||
"-v",
|
"-v",
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import streamlit as st
|
|||||||
|
|
||||||
from py_dvt_ate.simulation.physics.engine import PhysicsEngine
|
from py_dvt_ate.simulation.physics.engine import PhysicsEngine
|
||||||
|
|
||||||
|
|
||||||
# History buffer size for charts
|
# History buffer size for charts
|
||||||
HISTORY_SIZE = 500
|
HISTORY_SIZE = 500
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from functools import partial
|
||||||
from typing import Protocol, runtime_checkable
|
from typing import Protocol, runtime_checkable
|
||||||
|
|
||||||
__all__ = ["InstrumentServer", "SCPIDevice"]
|
__all__ = ["InstrumentServer", "SCPIDevice"]
|
||||||
@@ -132,8 +133,9 @@ class InstrumentServer:
|
|||||||
self._running = True
|
self._running = True
|
||||||
|
|
||||||
for port, instrument in self._instruments.items():
|
for port, instrument in self._instruments.items():
|
||||||
|
handler = partial(self._handle_client, instrument=instrument, port=port)
|
||||||
server = await asyncio.start_server(
|
server = await asyncio.start_server(
|
||||||
lambda r, w, inst=instrument, p=port: self._handle_client(r, w, inst, p),
|
handler,
|
||||||
self._host,
|
self._host,
|
||||||
port,
|
port,
|
||||||
)
|
)
|
||||||
@@ -216,7 +218,7 @@ class InstrumentServer:
|
|||||||
|
|
||||||
# Send response with newline terminator
|
# Send response with newline terminator
|
||||||
if response:
|
if response:
|
||||||
writer.write(f"{response}\n".encode("utf-8"))
|
writer.write(f"{response}\n".encode())
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
logger.debug("Port %d sent: %s", port, response)
|
logger.debug("Port %d sent: %s", port, response)
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class LDOModel:
|
|||||||
# Temperature ratio (reference is approximately 300K ≈ 27°C)
|
# Temperature ratio (reference is approximately 300K ≈ 27°C)
|
||||||
temp_ratio = t_kelvin / 300.0
|
temp_ratio = t_kelvin / 300.0
|
||||||
|
|
||||||
return self._params.dropout_voltage * (temp_ratio**1.5)
|
return float(self._params.dropout_voltage * (temp_ratio**1.5))
|
||||||
|
|
||||||
def is_in_dropout(self, junction_temperature: float) -> bool:
|
def is_in_dropout(self, junction_temperature: float) -> bool:
|
||||||
"""Check if the LDO is in dropout at current operating point.
|
"""Check if the LDO is in dropout at current operating point.
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ class ThermalChamberSim(BaseInstrument):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
setpoint = float(command.arguments[0])
|
setpoint = float(command.arguments[0])
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
raise ValueError(f"Invalid temperature value: {command.arguments[0]}")
|
raise ValueError(f"Invalid temperature value: {command.arguments[0]}") from err
|
||||||
|
|
||||||
self._setpoint = setpoint
|
self._setpoint = setpoint
|
||||||
if self._physics_engine is not None:
|
if self._physics_engine is not None:
|
||||||
|
|||||||
@@ -94,8 +94,8 @@ class PowerSupplySim(BaseInstrument):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
voltage = float(command.arguments[0])
|
voltage = float(command.arguments[0])
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
raise ValueError(f"Invalid voltage value: {command.arguments[0]}")
|
raise ValueError(f"Invalid voltage value: {command.arguments[0]}") from err
|
||||||
|
|
||||||
if voltage < 0:
|
if voltage < 0:
|
||||||
raise ValueError("Voltage cannot be negative")
|
raise ValueError("Voltage cannot be negative")
|
||||||
@@ -127,8 +127,8 @@ class PowerSupplySim(BaseInstrument):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
current = float(command.arguments[0])
|
current = float(command.arguments[0])
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
raise ValueError(f"Invalid current value: {command.arguments[0]}")
|
raise ValueError(f"Invalid current value: {command.arguments[0]}") from err
|
||||||
|
|
||||||
if current < 0:
|
if current < 0:
|
||||||
raise ValueError("Current limit cannot be negative")
|
raise ValueError("Current limit cannot be negative")
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ from py_dvt_ate.instruments.transport import InstrumentServer
|
|||||||
from py_dvt_ate.simulation.physics.engine import PhysicsEngine
|
from py_dvt_ate.simulation.physics.engine import PhysicsEngine
|
||||||
from py_dvt_ate.simulation.server import ServerConfig, SimulationServer
|
from py_dvt_ate.simulation.server import ServerConfig, SimulationServer
|
||||||
from py_dvt_ate.simulation.virtual.chamber import ThermalChamberSim
|
from py_dvt_ate.simulation.virtual.chamber import ThermalChamberSim
|
||||||
from py_dvt_ate.simulation.virtual.multimeter import MultimeterSim
|
|
||||||
from py_dvt_ate.simulation.virtual.power_supply import PowerSupplySim
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio(loop_scope="function")
|
@pytest.mark.asyncio(loop_scope="function")
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class TestThermalState:
|
|||||||
|
|
||||||
# Should not raise
|
# Should not raise
|
||||||
hash(state)
|
hash(state)
|
||||||
{state} # Can be added to a set
|
_ = {state} # Can be added to a set
|
||||||
|
|
||||||
|
|
||||||
class TestElectricalState:
|
class TestElectricalState:
|
||||||
|
|||||||
Reference in New Issue
Block a user