|
5 | 5 | from dataclasses import dataclass |
6 | 6 | from functools import partial |
7 | 7 | from pathlib import Path |
8 | | -from typing import Any, Iterator, List, Optional, cast |
| 8 | +from typing import Any, Iterator, List, Optional, Union, cast |
9 | 9 |
|
10 | 10 | import grpc |
11 | 11 | import pytest |
@@ -118,7 +118,7 @@ def define_environment(kind: str, **kwargs: Any) -> definitions.EnvironmentDefin |
118 | 118 |
|
119 | 119 | def run_request( |
120 | 120 | stub: definitions.IsolateStub, |
121 | | - request: definitions.BoundFunction, |
| 121 | + request: Union[definitions.BoundFunction, definitions.RunRequest], |
122 | 122 | *, |
123 | 123 | build_logs: Optional[List[Log]] = None, |
124 | 124 | bridge_logs: Optional[List[Log]] = None, |
@@ -270,6 +270,50 @@ def test_user_logs_immediate(stub: definitions.IsolateStub, monkeypatch: Any) -> |
270 | 270 | assert by_stream[LogLevel.STDERR] == "error error!" |
271 | 271 |
|
272 | 272 |
|
| 273 | +def test_no_stream_logs(stub: definitions.IsolateStub, monkeypatch: Any) -> None: |
| 274 | + inherit_from_local(monkeypatch) |
| 275 | + |
| 276 | + env_definition = define_environment("virtualenv", requirements=["pyjokes==0.6.0"]) |
| 277 | + request = definitions.RunRequest( |
| 278 | + function=definitions.BoundFunction( |
| 279 | + function=to_serialized_object( |
| 280 | + partial( |
| 281 | + exec, |
| 282 | + textwrap.dedent( |
| 283 | + """ |
| 284 | + import sys, pyjokes |
| 285 | + print(pyjokes.__version__) |
| 286 | + print("error error!", file=sys.stderr) |
| 287 | + """ |
| 288 | + ), |
| 289 | + ), |
| 290 | + method="dill", |
| 291 | + ), |
| 292 | + environments=[env_definition], |
| 293 | + ), |
| 294 | + metadata=definitions.TaskMetadata( |
| 295 | + logger_labels={}, |
| 296 | + # the default is True |
| 297 | + stream_logs=False, |
| 298 | + ), |
| 299 | + ) |
| 300 | + |
| 301 | + user_logs: List[Log] = [] |
| 302 | + build_logs: List[Log] = [] |
| 303 | + bridge_logs: List[Log] = [] |
| 304 | + run_request( |
| 305 | + stub, |
| 306 | + request, |
| 307 | + user_logs=user_logs, |
| 308 | + build_logs=build_logs, |
| 309 | + bridge_logs=bridge_logs, |
| 310 | + ) |
| 311 | + |
| 312 | + assert len(user_logs) == 0 |
| 313 | + assert len(build_logs) == 0 |
| 314 | + assert len(bridge_logs) == 0 |
| 315 | + |
| 316 | + |
273 | 317 | def test_unknown_environment(stub: definitions.IsolateStub, monkeypatch: Any) -> None: |
274 | 318 | inherit_from_local(monkeypatch) |
275 | 319 |
|
|
0 commit comments