1313
1414def test_stream_shows_deprecation_warning ():
1515 """Test that stream() shows a deprecation warning."""
16- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
16+ with patch ("replicate.lib._stream .use" ) as mock_use :
1717 # Create a mock function that returns an iterator
1818 mock_function = Mock ()
1919 mock_function .return_value = iter (["Hello" , " " , "world" ])
@@ -24,8 +24,8 @@ def test_stream_shows_deprecation_warning():
2424 warnings .simplefilter ("always" )
2525
2626 client = Replicate (bearer_token = "test-token" )
27- result = list (
28- client .stream (
27+ _ = list ( # pyright: ignore[reportDeprecated]
28+ client .stream ( # pyright: ignore[reportDeprecated]
2929 "anthropic/claude-4.5-sonnet" ,
3030 input = {"prompt" : "Hello" },
3131 )
@@ -39,16 +39,13 @@ def test_stream_shows_deprecation_warning():
3939 # Verify the @deprecated decorator message appears
4040 # (there may be multiple warnings from different decorator levels)
4141 messages = [str (warning .message ) for warning in deprecation_warnings ]
42- expected_message = (
43- "replicate.stream() is deprecated. "
44- "Use replicate.use() with streaming=True instead"
45- )
42+ expected_message = "replicate.stream() is deprecated. Use replicate.use() with streaming=True instead"
4643 assert expected_message in messages
4744
4845
4946def test_stream_calls_use_with_streaming_true ():
5047 """Test that stream() internally calls use() with streaming=True."""
51- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
48+ with patch ("replicate.lib._stream .use" ) as mock_use :
5249 # Create a mock function that returns an iterator
5350 mock_function = Mock ()
5451 mock_function .return_value = iter (["Hello" , " " , "world" ])
@@ -59,8 +56,8 @@ def test_stream_calls_use_with_streaming_true():
5956 # Suppress deprecation warnings for this test
6057 with warnings .catch_warnings ():
6158 warnings .simplefilter ("ignore" , DeprecationWarning )
62- result = list (
63- client .stream (
59+ _ = list ( # pyright: ignore[reportDeprecated]
60+ client .stream ( # pyright: ignore[reportDeprecated]
6461 "anthropic/claude-4.5-sonnet" ,
6562 input = {"prompt" : "Hello" },
6663 )
@@ -70,15 +67,15 @@ def test_stream_calls_use_with_streaming_true():
7067 mock_use .assert_called_once ()
7168 call_args = mock_use .call_args
7269 assert call_args .kwargs ["streaming" ] is True
73- assert call_args .args [1 ] == "anthropic/claude-4.5-sonnet"
70+ assert call_args .args [0 ] == "anthropic/claude-4.5-sonnet"
7471
7572 # Verify the mock function was called with the input
7673 mock_function .assert_called_once_with (prompt = "Hello" )
7774
7875
7976def test_stream_returns_iterator ():
8077 """Test that stream() returns an iterator of strings."""
81- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
78+ with patch ("replicate.lib._stream .use" ) as mock_use :
8279 # Create a mock function that returns an iterator
8380 mock_function = Mock ()
8481 mock_function .return_value = iter (["Hello" , " " , "world" , "!" ])
@@ -89,7 +86,7 @@ def test_stream_returns_iterator():
8986 # Suppress deprecation warnings for this test
9087 with warnings .catch_warnings ():
9188 warnings .simplefilter ("ignore" , DeprecationWarning )
92- result = client .stream (
89+ result = client .stream ( # pyright: ignore[reportDeprecated]
9390 "anthropic/claude-4.5-sonnet" ,
9491 input = {"prompt" : "Say hello" },
9592 )
@@ -104,7 +101,7 @@ def test_stream_returns_iterator():
104101
105102def test_stream_works_same_as_use_with_streaming ():
106103 """Test that stream() produces the same output as use() with streaming=True."""
107- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
104+ with patch ("replicate.lib._stream .use" ) as mock_use :
108105 # Create a mock function that returns an iterator
109106 mock_function = Mock ()
110107 expected_output = ["Test" , " " , "output" ]
@@ -117,7 +114,7 @@ def test_stream_works_same_as_use_with_streaming():
117114 with warnings .catch_warnings ():
118115 warnings .simplefilter ("ignore" , DeprecationWarning )
119116 stream_output = list (
120- client .stream (
117+ client .stream ( # pyright: ignore[reportDeprecated]
121118 "test-model" ,
122119 input = {"prompt" : "test" },
123120 )
@@ -136,7 +133,7 @@ def test_stream_works_same_as_use_with_streaming():
136133
137134def test_module_level_stream_function ():
138135 """Test that the module-level replicate.stream() function works."""
139- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
136+ with patch ("replicate.lib._stream .use" ) as mock_use :
140137 # Create a mock function that returns an iterator
141138 mock_function = Mock ()
142139 mock_function .return_value = iter (["a" , "b" , "c" ])
@@ -146,7 +143,7 @@ def test_module_level_stream_function():
146143 with warnings .catch_warnings ():
147144 warnings .simplefilter ("ignore" , DeprecationWarning )
148145 result = list (
149- replicate .stream (
146+ replicate .stream ( # pyright: ignore[reportDeprecated]
150147 "test-model" ,
151148 input = {"prompt" : "test" },
152149 )
@@ -163,7 +160,7 @@ def test_module_level_stream_function():
163160@pytest .mark .asyncio
164161async def test_async_stream_shows_deprecation_warning ():
165162 """Test that async stream() shows a deprecation warning."""
166- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
163+ with patch ("replicate.lib._stream .use" ) as mock_use :
167164 # Create a mock async function that returns an async iterator
168165 async def async_gen ():
169166 yield "Hello"
@@ -180,7 +177,7 @@ async def async_gen():
180177
181178 client = AsyncReplicate (bearer_token = "test-token" )
182179 result = []
183- async for item in await client .stream (
180+ async for item in await client .stream ( # pyright: ignore[reportDeprecated]
184181 "anthropic/claude-4.5-sonnet" ,
185182 input = {"prompt" : "Hello" },
186183 ):
@@ -193,16 +190,13 @@ async def async_gen():
193190
194191 # Verify the @deprecated decorator message appears
195192 messages = [str (warning .message ) for warning in deprecation_warnings ]
196- expected_message = (
197- "replicate.stream() is deprecated. "
198- "Use replicate.use() with streaming=True instead"
199- )
193+ expected_message = "replicate.stream() is deprecated. Use replicate.use() with streaming=True instead"
200194 assert expected_message in messages
201195
202196
203197def test_deprecation_message_includes_example ():
204198 """Test that the detailed deprecation message includes a helpful example."""
205- with patch ("replicate.lib._predictions_use .use" ) as mock_use :
199+ with patch ("replicate.lib._stream .use" ) as mock_use :
206200 mock_function = Mock ()
207201 mock_function .return_value = iter ([])
208202 mock_use .return_value = mock_function
@@ -212,7 +206,7 @@ def test_deprecation_message_includes_example():
212206 with warnings .catch_warnings (record = True ) as w :
213207 warnings .simplefilter ("always" )
214208 list (
215- client .stream (
209+ client .stream ( # pyright: ignore[reportDeprecated]
216210 "anthropic/claude-4.5-sonnet" ,
217211 input = {"prompt" : "Hello" , "max_tokens" : 100 },
218212 )
0 commit comments