Skip to content

Commit 06b71db

Browse files
committed
lint
1 parent 67af5ac commit 06b71db

21 files changed

+135
-113
lines changed

src/runloop_api_client/sdk/async_blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ async def create_devbox(
101101
blueprint_id=self._id,
102102
**params,
103103
)
104-
return AsyncDevbox(self._client, devbox_view.id)
104+
return AsyncDevbox(self._client, devbox_view)

src/runloop_api_client/sdk/async_scenario_run.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import os
66
from typing import Union, Optional
7-
from functools import cached_property
87
from typing_extensions import Unpack, override
98

109
from ..types import ScenarioRunView
@@ -68,16 +67,16 @@ def devbox_id(self) -> str:
6867
"""
6968
return self._devbox_id
7069

71-
@cached_property
72-
def devbox(self) -> AsyncDevbox:
73-
"""The devbox instance for this scenario run.
70+
async def get_devbox(self) -> AsyncDevbox:
71+
"""Get the devbox instance for this scenario run.
7472
7573
Use this to interact with the devbox environment during the scenario run.
7674
7775
:return: AsyncDevbox instance
7876
:rtype: AsyncDevbox
7977
"""
80-
return AsyncDevbox(self._client, self._devbox_id)
78+
devbox_view = await self._client.devboxes.retrieve(self._devbox_id)
79+
return AsyncDevbox(self._client, devbox_view)
8180

8281
async def get_info(
8382
self,

src/runloop_api_client/sdk/async_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ async def create_devbox(
122122
snapshot_id=self._id,
123123
**params,
124124
)
125-
return AsyncDevbox(self._client, devbox_view.id)
125+
return AsyncDevbox(self._client, devbox_view)

src/runloop_api_client/sdk/blueprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ def create_devbox(
101101
blueprint_id=self._id,
102102
**params,
103103
)
104-
return Devbox(self._client, devbox_view.id)
104+
return Devbox(self._client, devbox_view)

src/runloop_api_client/sdk/scenario_run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def devbox(self) -> Devbox:
7777
:return: Devbox instance
7878
:rtype: Devbox
7979
"""
80-
return Devbox(self._client, self._devbox_id)
80+
devbox_view = self._client.devboxes.retrieve(self._devbox_id)
81+
return Devbox(self._client, devbox_view)
8182

8283
def get_info(
8384
self,

src/runloop_api_client/sdk/snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ def create_devbox(
122122
snapshot_id=self._id,
123123
**params,
124124
)
125-
return Devbox(self._client, devbox_view.id)
125+
return Devbox(self._client, devbox_view)

tests/sdk/async_devbox/test_core.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pytest
1313

14-
from tests.sdk.conftest import MockDevboxView
14+
from tests.sdk.conftest import MockDevboxView, mock_devbox_view
1515
from runloop_api_client.sdk import AsyncDevbox
1616
from runloop_api_client.lib.polling import PollingConfig
1717
from runloop_api_client.sdk.async_devbox import (
@@ -26,20 +26,20 @@ class TestAsyncDevbox:
2626

2727
def test_init(self, mock_async_client: AsyncMock) -> None:
2828
"""Test AsyncDevbox initialization."""
29-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
29+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
3030
assert devbox.id == "dbx_123"
3131

3232
def test_repr(self, mock_async_client: AsyncMock) -> None:
3333
"""Test AsyncDevbox string representation."""
34-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
34+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
3535
assert repr(devbox) == "<AsyncDevbox id='dbx_123'>"
3636

3737
@pytest.mark.asyncio
3838
async def test_context_manager_enter_exit(self, mock_async_client: AsyncMock, devbox_view: MockDevboxView) -> None:
3939
"""Test context manager behavior with successful shutdown."""
4040
mock_async_client.devboxes.shutdown = AsyncMock(return_value=devbox_view)
4141

42-
async with AsyncDevbox(mock_async_client, "dbx_123") as devbox:
42+
async with AsyncDevbox(mock_async_client, mock_devbox_view()) as devbox:
4343
assert devbox.id == "dbx_123"
4444

4545
call_kwargs = mock_async_client.devboxes.shutdown.call_args[1]
@@ -51,7 +51,7 @@ async def test_context_manager_exception_handling(self, mock_async_client: Async
5151
mock_async_client.devboxes.shutdown = AsyncMock(side_effect=RuntimeError("Shutdown failed"))
5252

5353
with pytest.raises(ValueError, match="Test error"):
54-
async with AsyncDevbox(mock_async_client, "dbx_123"):
54+
async with AsyncDevbox(mock_async_client, mock_devbox_view()):
5555
raise ValueError("Test error")
5656

5757
# Shutdown should be called even when body raises exception
@@ -62,7 +62,7 @@ async def test_get_info(self, mock_async_client: AsyncMock, devbox_view: MockDev
6262
"""Test get_info method."""
6363
mock_async_client.devboxes.retrieve = AsyncMock(return_value=devbox_view)
6464

65-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
65+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
6666
result = await devbox.get_info(
6767
extra_headers={"X-Custom": "value"},
6868
extra_query={"param": "value"},
@@ -85,7 +85,7 @@ async def test_await_running(self, mock_async_client: AsyncMock, devbox_view: Mo
8585
mock_async_client.devboxes.await_running = AsyncMock(return_value=devbox_view)
8686
polling_config = PollingConfig(timeout_seconds=60.0)
8787

88-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
88+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
8989
result = await devbox.await_running(polling_config=polling_config)
9090

9191
assert result == devbox_view
@@ -100,7 +100,7 @@ async def test_await_suspended(self, mock_async_client: AsyncMock, devbox_view:
100100
mock_async_client.devboxes.await_suspended = AsyncMock(return_value=devbox_view)
101101
polling_config = PollingConfig(timeout_seconds=60.0)
102102

103-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
103+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
104104
result = await devbox.await_suspended(polling_config=polling_config)
105105

106106
assert result == devbox_view
@@ -114,7 +114,7 @@ async def test_shutdown(self, mock_async_client: AsyncMock, devbox_view: MockDev
114114
"""Test shutdown method."""
115115
mock_async_client.devboxes.shutdown = AsyncMock(return_value=devbox_view)
116116

117-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
117+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
118118
result = await devbox.shutdown(
119119
extra_headers={"X-Custom": "value"},
120120
extra_query={"param": "value"},
@@ -138,7 +138,7 @@ async def test_suspend(self, mock_async_client: AsyncMock, devbox_view: MockDevb
138138
"""Test suspend method."""
139139
mock_async_client.devboxes.suspend = AsyncMock(return_value=devbox_view)
140140

141-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
141+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
142142
result = await devbox.suspend(
143143
extra_headers={"X-Custom": "value"},
144144
extra_query={"param": "value"},
@@ -164,7 +164,7 @@ async def test_resume(self, mock_async_client: AsyncMock, devbox_view: MockDevbo
164164
mock_async_client.devboxes.await_running = AsyncMock(return_value=devbox_view)
165165
polling_config = PollingConfig(timeout_seconds=60.0)
166166

167-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
167+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
168168
result = await devbox.resume(
169169
polling_config=polling_config,
170170
extra_headers={"X-Custom": "value"},
@@ -193,7 +193,7 @@ async def test_resume_async(self, mock_async_client: AsyncMock, devbox_view: Moc
193193
"""Test resume_async method."""
194194
mock_async_client.devboxes.resume = AsyncMock(return_value=devbox_view)
195195

196-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
196+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
197197
result = await devbox.resume_async(
198198
extra_headers={"X-Custom": "value"},
199199
extra_query={"param": "value"},
@@ -217,7 +217,7 @@ async def test_keep_alive(self, mock_async_client: AsyncMock) -> None:
217217
"""Test keep_alive method."""
218218
mock_async_client.devboxes.keep_alive = AsyncMock(return_value=object())
219219

220-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
220+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
221221
result = await devbox.keep_alive(
222222
extra_headers={"X-Custom": "value"},
223223
extra_query={"param": "value"},
@@ -245,7 +245,7 @@ async def test_snapshot_disk(self, mock_async_client: AsyncMock) -> None:
245245
mock_async_client.devboxes.snapshot_disk_async = AsyncMock(return_value=snapshot_data)
246246
mock_async_client.devboxes.disk_snapshots.await_completed = AsyncMock(return_value=snapshot_status)
247247

248-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
248+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
249249
polling_config = PollingConfig(timeout_seconds=60.0)
250250
snapshot = await devbox.snapshot_disk(
251251
name="test-snapshot",
@@ -274,7 +274,7 @@ async def test_snapshot_disk_async(self, mock_async_client: AsyncMock) -> None:
274274
snapshot_data = SimpleNamespace(id="snp_123")
275275
mock_async_client.devboxes.snapshot_disk_async = AsyncMock(return_value=snapshot_data)
276276

277-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
277+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
278278
snapshot = await devbox.snapshot_disk_async(
279279
name="test-snapshot",
280280
metadata={"key": "value"},
@@ -296,7 +296,7 @@ async def test_close(self, mock_async_client: AsyncMock, devbox_view: MockDevbox
296296
"""Test close method calls shutdown."""
297297
mock_async_client.devboxes.shutdown = AsyncMock(return_value=devbox_view)
298298

299-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
299+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
300300
await devbox.close()
301301

302302
mock_async_client.devboxes.shutdown.assert_called_once()
@@ -305,21 +305,21 @@ async def test_close(self, mock_async_client: AsyncMock, devbox_view: MockDevbox
305305

306306
def test_cmd_property(self, mock_async_client: AsyncMock) -> None:
307307
"""Test cmd property returns AsyncCommandInterface."""
308-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
308+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
309309
cmd = devbox.cmd
310310
assert isinstance(cmd, AsyncCommandInterface)
311311
assert cmd._devbox is devbox
312312

313313
def test_file_property(self, mock_async_client: AsyncMock) -> None:
314314
"""Test file property returns AsyncFileInterface."""
315-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
315+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
316316
file_interface = devbox.file
317317
assert isinstance(file_interface, AsyncFileInterface)
318318
assert file_interface._devbox is devbox
319319

320320
def test_net_property(self, mock_async_client: AsyncMock) -> None:
321321
"""Test net property returns AsyncNetworkInterface."""
322-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
322+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
323323
net = devbox.net
324324
assert isinstance(net, AsyncNetworkInterface)
325325
assert net._devbox is devbox

tests/sdk/async_devbox/test_edge_cases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import httpx
1111
import pytest
1212

13+
from tests.sdk.conftest import mock_devbox_view
1314
from runloop_api_client.sdk import AsyncDevbox
1415

1516

@@ -21,6 +22,6 @@ async def test_async_network_error(self, mock_async_client: AsyncMock) -> None:
2122
"""Test handling of network errors in async."""
2223
mock_async_client.devboxes.retrieve = AsyncMock(side_effect=httpx.NetworkError("Connection failed"))
2324

24-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
25+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
2526
with pytest.raises(httpx.NetworkError):
2627
await devbox.get_info()

tests/sdk/async_devbox/test_interfaces.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import httpx
1313
import pytest
1414

15-
from tests.sdk.conftest import MockExecutionView
15+
from tests.sdk.conftest import MockExecutionView, mock_devbox_view
1616
from runloop_api_client.sdk import AsyncDevbox
1717

1818

@@ -27,7 +27,7 @@ async def test_exec_without_callbacks(
2727
mock_async_client.devboxes.execute_async = AsyncMock(return_value=execution_view)
2828
mock_async_client.devboxes.executions.await_completed = AsyncMock(return_value=execution_view)
2929

30-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
30+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
3131
result = await devbox.cmd.exec("echo hello")
3232

3333
assert result.exit_code == 0
@@ -61,7 +61,7 @@ async def test_exec_with_stdout_callback(self, mock_async_client: AsyncMock, moc
6161

6262
stdout_calls: list[str] = []
6363

64-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
64+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
6565
result = await devbox.cmd.exec("echo hello", stdout=stdout_calls.append)
6666

6767
assert result.exit_code == 0
@@ -81,7 +81,7 @@ async def test_exec_async_returns_execution(
8181
mock_async_client.devboxes.execute_async = AsyncMock(return_value=execution_async)
8282
mock_async_client.devboxes.executions.stream_stdout_updates = AsyncMock(return_value=mock_async_stream)
8383

84-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
84+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
8585
execution = await devbox.cmd.exec_async("long-running command")
8686

8787
assert execution.execution_id == "exn_123"
@@ -97,7 +97,7 @@ async def test_read(self, mock_async_client: AsyncMock) -> None:
9797
"""Test file read."""
9898
mock_async_client.devboxes.read_file_contents = AsyncMock(return_value="file content")
9999

100-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
100+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
101101
result = await devbox.file.read(file_path="/path/to/file")
102102

103103
assert result == "file content"
@@ -109,7 +109,7 @@ async def test_write_string(self, mock_async_client: AsyncMock) -> None:
109109
execution_detail = SimpleNamespace()
110110
mock_async_client.devboxes.write_file_contents = AsyncMock(return_value=execution_detail)
111111

112-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
112+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
113113
result = await devbox.file.write(file_path="/path/to/file", contents="content")
114114

115115
assert result == execution_detail
@@ -121,7 +121,7 @@ async def test_write_bytes(self, mock_async_client: AsyncMock) -> None:
121121
execution_detail = SimpleNamespace()
122122
mock_async_client.devboxes.write_file_contents = AsyncMock(return_value=execution_detail)
123123

124-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
124+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
125125
result = await devbox.file.write(file_path="/path/to/file", contents="content")
126126

127127
assert result == execution_detail
@@ -134,7 +134,7 @@ async def test_download(self, mock_async_client: AsyncMock) -> None:
134134
mock_response.read = AsyncMock(return_value=b"file content")
135135
mock_async_client.devboxes.download_file = AsyncMock(return_value=mock_response)
136136

137-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
137+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
138138
result = await devbox.file.download(path="/path/to/file")
139139

140140
assert result == b"file content"
@@ -146,7 +146,7 @@ async def test_upload(self, mock_async_client: AsyncMock, tmp_path: Path) -> Non
146146
execution_detail = SimpleNamespace()
147147
mock_async_client.devboxes.upload_file = AsyncMock(return_value=execution_detail)
148148

149-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
149+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
150150
# Create a temporary file for upload
151151
temp_file = tmp_path / "test_file.txt"
152152
temp_file.write_text("test content")
@@ -166,7 +166,7 @@ async def test_create_ssh_key(self, mock_async_client: AsyncMock) -> None:
166166
ssh_key_response = SimpleNamespace(public_key="ssh-rsa ...")
167167
mock_async_client.devboxes.create_ssh_key = AsyncMock(return_value=ssh_key_response)
168168

169-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
169+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
170170
result = await devbox.net.create_ssh_key(
171171
extra_headers={"X-Custom": "value"},
172172
extra_query={"param": "value"},
@@ -184,7 +184,7 @@ async def test_create_tunnel(self, mock_async_client: AsyncMock) -> None:
184184
tunnel_view = SimpleNamespace(tunnel_id="tunnel_123")
185185
mock_async_client.devboxes.create_tunnel = AsyncMock(return_value=tunnel_view)
186186

187-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
187+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
188188
result = await devbox.net.create_tunnel(
189189
port=8080,
190190
extra_headers={"X-Custom": "value"},
@@ -202,7 +202,7 @@ async def test_remove_tunnel(self, mock_async_client: AsyncMock) -> None:
202202
"""Test remove tunnel."""
203203
mock_async_client.devboxes.remove_tunnel = AsyncMock(return_value=object())
204204

205-
devbox = AsyncDevbox(mock_async_client, "dbx_123")
205+
devbox = AsyncDevbox(mock_async_client, mock_devbox_view())
206206
result = await devbox.net.remove_tunnel(
207207
port=8080,
208208
extra_headers={"X-Custom": "value"},

0 commit comments

Comments
 (0)