File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 2929from packaging import version
3030
3131from .constants import DIFFUSERS_REQUEST_TIMEOUT
32+ from .deprecation_utils import deprecate
3233from .import_utils import (
3334 BACKENDS_MAPPING ,
3435 is_accelerate_available ,
6768global_rng = random .Random ()
6869
6970logger = get_logger (__name__ )
70- logger .warning (
71- "diffusers.utils.testing_utils' is deprecated and will be removed in a future version. "
72- "Determinism and device backend utilities have been moved to `diffusers.utils.torch_utils`. "
71+ deprecate (
72+ "diffusers.utils.testing_utils" ,
73+ "1.0.0" ,
74+ "diffusers.utils.testing_utils is deprecated and will be removed in a future version. "
75+ "Determinism and device backend utilities have been moved to `diffusers.utils.torch_utils`. " ,
7376)
7477_required_peft_version = is_peft_available () and version .parse (
7578 version .parse (importlib .metadata .version ("peft" )).base_version
Original file line number Diff line number Diff line change 1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16+ import importlib
1617import os
1718import unittest
19+ import warnings
1820
1921import pytest
2022
@@ -182,6 +184,25 @@ def test_deprecate_stacklevel(self):
182184 assert str (warning .warning ) == "This message is better!!!"
183185 assert "diffusers/tests/others/test_utils.py" in warning .filename
184186
187+ def test_deprecate_testing_utils_module (self ):
188+ import diffusers .utils .testing_utils
189+
190+ with warnings .catch_warnings (record = True ) as caught_warnings :
191+ warnings .simplefilter ("always" )
192+ importlib .reload (diffusers .utils .testing_utils )
193+
194+ deprecation_warnings = [w for w in caught_warnings if issubclass (w .category , FutureWarning )]
195+ assert len (deprecation_warnings ) >= 1 , "Expected at least one FutureWarning from diffusers.utils.testing_utils"
196+
197+ messages = [str (w .message ) for w in deprecation_warnings ]
198+ assert any ("diffusers.utils.testing_utils" in msg for msg in messages ), (
199+ f"Expected a deprecation warning mentioning 'diffusers.utils.testing_utils', got: { messages } "
200+ )
201+ assert any (
202+ "diffusers.utils.testing_utils is deprecated and will be removed in a future version." in msg
203+ for msg in messages
204+ ), f"Expected deprecation message substring not found, got: { messages } "
205+
185206
186207# Copied from https://github.com/huggingface/transformers/blob/main/tests/utils/test_expectations.py
187208class ExpectationsTester (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments