Skip to content

Commit 6bc4e33

Browse files
committed
commit prev wip
1 parent 0fc90b4 commit 6bc4e33

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

airbyte_cdk/test/entrypoint_wrapper.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,19 @@ def is_not_in_logs(self, pattern: str) -> bool:
159159

160160
def _run_command(
161161
source: Source,
162-
args: list[str],
163-
expected_outcome: ExpectedOutcome,
162+
args: List[str],
163+
expecting_exception: bool | None = None, # Deprecated, use `expected_outcome` instead.
164+
*,
165+
expected_outcome: ExpectedOutcome | None = None
164166
) -> EntrypointOutput:
167+
"""Internal function to run a command with the AirbyteEntrypoint.
168+
169+
Note: Even though this function is private, some connectors do call it directly.
170+
171+
Note: The `expecting_exception` arg is now deprecated in favor of the tri-state
172+
`expected_outcome` arg. The old argument is supported (for now) for backwards compatibility.
173+
"""
174+
expected_outcome = expected_outcome or ExpectedOutcome.from_expecting_exception_bool(expecting_exception)
165175
log_capture_buffer = StringIO()
166176
stream_handler = logging.StreamHandler(log_capture_buffer)
167177
stream_handler.setLevel(logging.INFO)
@@ -194,8 +204,9 @@ def _run_command(
194204
def discover(
195205
source: Source,
196206
config: Mapping[str, Any],
207+
expecting_exception: bool | None = None, # Deprecated, use `expected_outcome` instead.
197208
*,
198-
expected_outcome: ExpectedOutcome = ExpectedOutcome.EXPECT_SUCCESS,
209+
expected_outcome: ExpectedOutcome | None = None,
199210
) -> EntrypointOutput:
200211
"""
201212
config must be json serializable
@@ -210,6 +221,7 @@ def discover(
210221
return _run_command(
211222
source,
212223
["discover", "--config", config_file, "--debug"],
224+
expecting_exception=expecting_exception, # Deprecated, but still supported.
213225
expected_outcome=expected_outcome,
214226
)
215227

@@ -219,8 +231,9 @@ def read(
219231
config: Mapping[str, Any],
220232
catalog: ConfiguredAirbyteCatalog,
221233
state: Optional[List[AirbyteStateMessage]] = None,
234+
expecting_exception: bool | None = None, # Deprecated, use `expected_outcome` instead.
222235
*,
223-
expected_outcome: ExpectedOutcome = ExpectedOutcome.EXPECT_SUCCESS,
236+
expected_outcome: ExpectedOutcome | None = None,
224237
) -> EntrypointOutput:
225238
"""
226239
config and state must be json serializable
@@ -253,7 +266,12 @@ def read(
253266
]
254267
)
255268

256-
return _run_command(source, args, expected_outcome=expected_outcome)
269+
return _run_command(
270+
source,
271+
args,
272+
expecting_exception=expecting_exception, # Deprecated, but still supported.
273+
expected_outcome=expected_outcome,
274+
)
257275

258276

259277
def make_file(

airbyte_cdk/test/utils/reading.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ def read_records(
2020
stream_name: str,
2121
sync_mode: SyncMode,
2222
state: Optional[List[AirbyteStateMessage]] = None,
23-
*,
2423
expecting_exception: bool | None = None, # Deprecated, use expected_outcome instead.
24+
*,
2525
expected_outcome: ExpectedOutcome | None = None,
2626
) -> EntrypointOutput:
2727
"""Read records from a stream."""
28-
if expecting_exception is not None and expected_outcome is not None:
29-
raise ValueError("Cannot set both expecting_exception and expected_outcome.")
30-
31-
if expected_outcome is None:
32-
expected_outcome = ExpectedOutcome.from_expecting_exception_bool(expecting_exception)
33-
3428
_catalog = catalog(stream_name, sync_mode)
35-
return read(source, config, _catalog, state, expected_outcome=expected_outcome)
29+
return read(
30+
source,
31+
config,
32+
_catalog,
33+
state,
34+
expecting_exception=expecting_exception, # Deprecated, for backward compatibility.
35+
expected_outcome=expected_outcome,
36+
)

0 commit comments

Comments
 (0)