2424from typing import Any , List , Mapping , Optional , Union
2525
2626import orjson
27+ from langsmith import expect
2728from pydantic import ValidationError as V2ValidationError
2829from serpyco_rs import SchemaValidationError
2930
4445 Type ,
4546)
4647from airbyte_cdk .sources import Source
48+ from airbyte_cdk .test .standard_tests .models .scenario import ExpectedOutcome
4749
4850
4951class EntrypointOutput :
@@ -157,7 +159,9 @@ def is_not_in_logs(self, pattern: str) -> bool:
157159
158160
159161def _run_command (
160- source : Source , args : List [str ], expecting_exception : bool = False
162+ source : Source ,
163+ args : list [str ],
164+ expected_outcome : ExpectedOutcome ,
161165) -> EntrypointOutput :
162166 log_capture_buffer = StringIO ()
163167 stream_handler = logging .StreamHandler (log_capture_buffer )
@@ -175,35 +179,39 @@ def _run_command(
175179 for message in source_entrypoint .run (parsed_args ):
176180 messages .append (message )
177181 except Exception as exception :
178- if not expecting_exception :
182+ if expected_outcome . expect_success () :
179183 print ("Printing unexpected error from entrypoint_wrapper" )
180184 print ("" .join (traceback .format_exception (None , exception , exception .__traceback__ )))
185+
181186 uncaught_exception = exception
182187
183188 captured_logs = log_capture_buffer .getvalue ().split ("\n " )[:- 1 ]
184189
185190 parent_logger .removeHandler (stream_handler )
186191
187- return EntrypointOutput (messages + captured_logs , uncaught_exception )
192+ return EntrypointOutput (messages + captured_logs , uncaught_exception = uncaught_exception )
188193
189194
190195def discover (
191196 source : Source ,
192197 config : Mapping [str , Any ],
193- expecting_exception : bool = False ,
198+ * ,
199+ expected_outcome : ExpectedOutcome = ExpectedOutcome .EXPECT_SUCCESS ,
194200) -> EntrypointOutput :
195201 """
196202 config must be json serializable
197- :param expecting_exception : By default if there is an uncaught exception, the exception will be printed out. If this is expected, please
198- provide expecting_exception=True so that the test output logs are cleaner
203+ :param expected_outcome : By default if there is an uncaught exception, the exception will be printed out. If this is expected, please
204+ provide `expected_outcome=ExpectedOutcome.EXPECT_FAILURE` so that the test output logs are cleaner
199205 """
200206
201207 with tempfile .TemporaryDirectory () as tmp_directory :
202208 tmp_directory_path = Path (tmp_directory )
203209 config_file = make_file (tmp_directory_path / "config.json" , config )
204210
205211 return _run_command (
206- source , ["discover" , "--config" , config_file , "--debug" ], expecting_exception
212+ source ,
213+ ["discover" , "--config" , config_file , "--debug" ],
214+ expected_outcome = expected_outcome ,
207215 )
208216
209217
@@ -212,13 +220,14 @@ def read(
212220 config : Mapping [str , Any ],
213221 catalog : ConfiguredAirbyteCatalog ,
214222 state : Optional [List [AirbyteStateMessage ]] = None ,
215- expecting_exception : bool = False ,
223+ * ,
224+ expected_outcome : ExpectedOutcome = ExpectedOutcome .EXPECT_SUCCESS ,
216225) -> EntrypointOutput :
217226 """
218227 config and state must be json serializable
219228
220- :param expecting_exception : By default if there is an uncaught exception, the exception will be printed out. If this is expected, please
221- provide expecting_exception=True so that the test output logs are cleaner
229+ :param expected_outcome : By default if there is an uncaught exception, the exception will be printed out. If this is expected, please
230+ provide `expected_outcome=ExpectedOutcome.EXPECT_FAILURE` so that the test output logs are cleaner.
222231 """
223232 with tempfile .TemporaryDirectory () as tmp_directory :
224233 tmp_directory_path = Path (tmp_directory )
@@ -245,7 +254,7 @@ def read(
245254 ]
246255 )
247256
248- return _run_command (source , args , expecting_exception )
257+ return _run_command (source , args , expected_outcome = expected_outcome )
249258
250259
251260def make_file (
0 commit comments