11from __future__ import annotations
22
3- import os
43from unittest .mock import MagicMock , patch
54
65from pyspark .sql import DataFrame , SparkSession
@@ -84,13 +83,17 @@ def mock_config(mock_spark):
8483@pytest .fixture
8584def reset_client ():
8685 """Reset the client singletons (and the shared Spark session) between tests."""
86+ from datacustomcode .client import config as client_config
87+
8788 Client ._instance = None
8889 StreamingClient ._instance = None
8990 _BaseClient ._shared_spark = None
91+ client_config .streaming_source = None
9092 yield
9193 Client ._instance = None
9294 StreamingClient ._instance = None
9395 _BaseClient ._shared_spark = None
96+ client_config .streaming_source = None
9497
9598
9699class TestClient :
@@ -298,29 +301,29 @@ def test_read_dlo_deltas(self, reset_client, mock_spark):
298301 reader .read_dlo_deltas .return_value = mock_df
299302
300303 client = StreamingClient (reader = reader , writer = writer )
301- # The streaming source is resolved by the runtime and recorded from the
302- # env var it sets; the caller passes no name.
303- with patch .dict (
304- "os.environ" , {"BYOC_STREAMING_SOURCE_NAME" : "Account_std__dll" }
305- ):
304+
305+ with patch ("datacustomcode.client.config" ) as mock_config :
306+ mock_config .streaming_source = "Account_std__dll"
306307 result = client .read_dlo_deltas ()
307308
308309 reader .read_dlo_deltas .assert_called_once_with ()
309310 assert result is mock_df
310311 assert "Account_std__dll" in client ._data_layer_history [DataCloudObjectType .DLO ]
311312
312- def test_read_dlo_deltas_without_source_env_raises (self , reset_client , mock_spark ):
313- """Delta reads require the runtime source env var; absence fails fast."""
313+ def test_read_dlo_deltas_without_configured_source_raises (
314+ self , reset_client , mock_spark
315+ ):
316+ """Delta reads require a configured streaming source; absence fails fast."""
314317 reader = MagicMock (spec = BaseDataCloudReader )
315318 writer = MagicMock (spec = BaseDataCloudWriter )
316319
317320 client = StreamingClient (reader = reader , writer = writer )
318- with patch . dict ( "os.environ" , {}, clear = False ) :
319- os . environ . pop ( "BYOC_STREAMING_SOURCE_NAME" , None )
321+ with patch ( "datacustomcode.client.config" ) as mock_config :
322+ mock_config . streaming_source = None
320323 with pytest .raises (RuntimeError ) as exc_info :
321324 client .read_dlo_deltas ()
322325
323- assert "BYOC_STREAMING_SOURCE_NAME " in str (exc_info .value )
326+ assert "permissions.read " in str (exc_info .value )
324327 reader .read_dlo_deltas .assert_not_called ()
325328
326329 def test_read_dmo_deltas (self , reset_client , mock_spark ):
@@ -330,9 +333,8 @@ def test_read_dmo_deltas(self, reset_client, mock_spark):
330333 reader .read_dmo_deltas .return_value = mock_df
331334
332335 client = StreamingClient (reader = reader , writer = writer )
333- with patch .dict (
334- "os.environ" , {"BYOC_STREAMING_SOURCE_NAME" : "Account_model__dlm" }
335- ):
336+ with patch ("datacustomcode.client.config" ) as mock_config :
337+ mock_config .streaming_source = "Account_model__dlm"
336338 result = client .read_dmo_deltas ()
337339
338340 reader .read_dmo_deltas .assert_called_once_with ()
@@ -384,7 +386,8 @@ def test_streaming_read_write_flow(self, reset_client, mock_spark):
384386
385387 client = StreamingClient (reader = reader , writer = writer )
386388
387- with patch .dict ("os.environ" , {"BYOC_STREAMING_SOURCE_NAME" : "source_dll" }):
389+ with patch ("datacustomcode.client.config" ) as mock_config :
390+ mock_config .streaming_source = "source_dll"
388391 df = client .read_dlo_deltas ()
389392 client .write_dlo_deltas ("target_dll" , df )
390393
0 commit comments