Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Nov 18, 2024
1 parent f8d99bc commit 48b7034
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modal/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ async def create(
return obj

def _hydrate_metadata(self, handle_metadata: Optional[Message]):
self._stdout: _StreamReader[str] = StreamReader(
self._stdout: _StreamReader[str] = StreamReader[str](
api_pb2.FILE_DESCRIPTOR_STDOUT, self.object_id, "sandbox", self._client, by_line=True
)
self._stderr: _StreamReader[str] = StreamReader(
self._stderr: _StreamReader[str] = StreamReader[str](
api_pb2.FILE_DESCRIPTOR_STDERR, self.object_id, "sandbox", self._client, by_line=True
)
self._stdin = StreamWriter(self.object_id, "sandbox", self._client)
Expand Down Expand Up @@ -489,7 +489,7 @@ async def exec(
return _ContainerProcess(resp.exec_id, self._client, stdout=stdout, stderr=stderr, text=text, by_line=by_line)

@property
def stdout(self) -> _StreamReader:
def stdout(self) -> _StreamReader[str]:
"""
[`StreamReader`](/docs/reference/modal.io_streams#modalio_streamsstreamreader) for
the sandbox's stdout stream.
Expand All @@ -498,7 +498,7 @@ def stdout(self) -> _StreamReader:
return self._stdout

@property
def stderr(self) -> _StreamReader:
def stderr(self) -> _StreamReader[str]:
"""[`StreamReader`](/docs/reference/modal.io_streams#modalio_streamsstreamreader) for
the sandbox's stderr stream.
"""
Expand Down
11 changes: 11 additions & 0 deletions test/supports/type_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ async def async_block() -> None:
assert_type(should_also_be_str, str)
should_be_int = await instance.bar.local("bar")
assert_type(should_be_int, int)


# check sandboxes
sandbox = modal.Sandbox.create("dummy")
assert_type(sandbox.stdout.read(), str)

cmd = sandbox.exec("other")
assert_type(cmd.stdout.read(), str)

cmd2 = sandbox.exec("other_bin", text=False)
assert_type(cmd2.stdout.read(), bytes)

0 comments on commit 48b7034

Please sign in to comment.