fix(micromate): is_open() called a property -- TypeError on every real transport
Hidden because the test double defined is_connected as a method; it is now a property, matching BaseTransport. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
8eab5f9479
commit
31181f64e6
3 files changed
+19
-4
No files matched your search
+4
-1
@@ -128,7 +128,10 @@ class MicromateClient:
|
||||
self._transport.disconnect()
|
||||
|
||||
def is_open(self) -> bool:
|
||||
return self._transport.is_connected()
|
||||
# `is_connected` is a PROPERTY on BaseTransport. Calling it raised
|
||||
# TypeError on every real transport; only a test double that defined
|
||||
# it as a method hid that.
|
||||
return bool(self._transport.is_connected)
|
||||
|
||||
def __enter__(self) -> "MicromateClient":
|
||||
self.open()
|
||||
|
||||
@@ -121,6 +121,7 @@ class ScriptedTransport:
|
||||
def disconnect(self) -> None:
|
||||
self._connected = False
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
return self._connected
|
||||
|
||||
@@ -408,7 +409,7 @@ def test_the_client_owns_the_transport():
|
||||
mm, t = client([])
|
||||
assert not mm.is_open()
|
||||
mm.open()
|
||||
assert mm.is_open() and t.is_connected()
|
||||
assert mm.is_open() and t.is_connected
|
||||
mm.close()
|
||||
assert not mm.is_open()
|
||||
|
||||
@@ -417,9 +418,9 @@ def test_context_manager_opens_and_closes():
|
||||
t = ScriptedTransport([frame(0xA4, POLL), frame(0xEA, SERIAL),
|
||||
frame(0xB6, STATE_IDLE), frame(0xBE, setup_response("x.mmb"))])
|
||||
with MicromateClient(t, recv_timeout=0.5) as mm:
|
||||
assert t.is_connected()
|
||||
assert t.is_connected
|
||||
assert mm.connect().serial == "UM12947"
|
||||
assert not t.is_connected()
|
||||
assert not t.is_connected
|
||||
|
||||
|
||||
# ── The Thor firmware line, on real bytes ─────────────────────────────────────
|
||||
@@ -536,3 +537,13 @@ def test_get_setup_verify_false_returns_the_corrupt_read():
|
||||
data[CONTENT + 5] = 0x05
|
||||
mm, _ = client([frame(0xE5, bytes(data))])
|
||||
assert mm.get_setup(verify=False).record_mode == 0x05
|
||||
|
||||
|
||||
def test_is_open_works_on_a_real_transport():
|
||||
"""`is_connected` is a PROPERTY on BaseTransport. is_open() used to call
|
||||
it, which raised TypeError on every real transport -- hidden because the
|
||||
test double defined it as a method."""
|
||||
from minimateplus.transport import TcpTransport
|
||||
|
||||
mm = MicromateClient(TcpTransport("127.0.0.1", port=9)) # never connected
|
||||
assert mm.is_open() is False
|
||||
@@ -52,6 +52,7 @@ class ScriptedTransport:
|
||||
def disconnect(self) -> None:
|
||||
self._connected = False
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
return self._connected
|
||||
|
||||
|
||||
Reference in new issue
Block a user