Skip to content

Commit acc7316

Browse files
committed
TST: Add some proxy tests
1 parent d229c44 commit acc7316

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ norecursedirs = [
6969
"dist",
7070
"build",
7171
]
72-
addopts = "-ra --strict-markers"
72+
addopts = "-ra --strict-markers --basetemp=/tmp/pytest"
7373
markers = [
7474
"integration: Marks a test as an integration test",
7575
"onprem: Marks a test as valid only in an on-prem environment",

src/runrms/api/proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def __contains__(self, item: Any) -> Any:
279279
def __str__(self) -> str:
280280
"""Forward string conversion to worker."""
281281
if not self._path:
282-
return f"<RmsApiProxy connected to {self._zmq_address}"
282+
return f"<RmsApiProxy connected to {self._zmq_address}>"
283283

284284
request = Request(msg_type="call", path=[*self._path, "__str__"])
285285
response = self._send_request(request)
@@ -288,7 +288,7 @@ def __str__(self) -> str:
288288
def __repr__(self) -> str:
289289
"""Forward repr conversion to worker."""
290290
if not self._path:
291-
return f"<RmsApiProxy connected to {self._zmq_address}"
291+
return f"<RmsApiProxy connected to {self._zmq_address}>"
292292

293293
request = Request(msg_type="call", path=[*self._path, "__repr__"])
294294
response = self._send_request(request)

tests/test_api/test_proxy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def test_private_attr_raises(proxy_with_mocks: RmsApiProxy) -> None:
7373
_ = proxy_with_mocks._private
7474

7575

76+
def test_str_repr_on_root_proxy_gives_instance(proxy_with_mocks: RmsApiProxy) -> None:
77+
"""Str and repr print the root RmsApiProxy instance with its address."""
78+
assert str(proxy_with_mocks).startswith("<RmsApiProxy connected to ipc://")
79+
assert repr(proxy_with_mocks).startswith("<RmsApiProxy connected to ipc://")
80+
81+
7682
def test_version_special_case(
7783
proxy_with_mocks: RmsApiProxy, mock_socket: MagicMock
7884
) -> None:
@@ -497,6 +503,13 @@ def test_shutdown_sends_request(
497503
assert request.msg_type == "shutdown"
498504

499505

506+
def test_shutdown_on_child_proxy_raises(proxy_with_mocks: RmsApiProxy) -> None:
507+
"""Accessing attribute returns new proxy with extended path."""
508+
child = proxy_with_mocks.some_attr
509+
with pytest.raises(RuntimeError, match="Shutdown can only be called on root"):
510+
child._shutdown()
511+
512+
500513
def test_cleanup_closes_socket(
501514
proxy_with_mocks: RmsApiProxy, mock_socket: MagicMock
502515
) -> None:

0 commit comments

Comments
 (0)