|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import sys |
4 | 3 | import itertools
|
| 4 | +import pathlib |
5 | 5 | import pickle
|
| 6 | +import sys |
6 | 7 |
|
7 | 8 | from typing import Any
|
8 | 9 | from unittest.mock import patch, Mock
|
@@ -478,6 +479,22 @@ def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm):
|
478 | 479 | assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
|
479 | 480 |
|
480 | 481 |
|
| 482 | +def test_warn_external(recwarn): |
| 483 | + _api.warn_external("oops") |
| 484 | + assert len(recwarn) == 1 |
| 485 | + if sys.version_info[:2] >= (3, 12): |
| 486 | + # With Python 3.12, we let Python figure out the stacklevel using the |
| 487 | + # `skip_file_prefixes` argument, which cannot exempt tests, so just confirm |
| 488 | + # the filename is not in the package. |
| 489 | + basedir = pathlib.Path(__file__).parents[2] |
| 490 | + assert not recwarn[0].filename.startswith((str(basedir / 'matplotlib'), |
| 491 | + str(basedir / 'mpl_toolkits'))) |
| 492 | + else: |
| 493 | + # On older Python versions, we manually calculated the stacklevel, and had an |
| 494 | + # exception for our own tests. |
| 495 | + assert recwarn[0].filename == __file__ |
| 496 | + |
| 497 | + |
481 | 498 | def test_warn_external_frame_embedded_python():
|
482 | 499 | with patch.object(cbook, "sys") as mock_sys:
|
483 | 500 | mock_sys._getframe = Mock(return_value=None)
|
@@ -784,12 +801,6 @@ def test_safe_first_element_pandas_series(pd):
|
784 | 801 | assert actual == 0
|
785 | 802 |
|
786 | 803 |
|
787 |
| -def test_warn_external(recwarn): |
788 |
| - _api.warn_external("oops") |
789 |
| - assert len(recwarn) == 1 |
790 |
| - assert recwarn[0].filename == __file__ |
791 |
| - |
792 |
| - |
793 | 804 | def test_array_patch_perimeters():
|
794 | 805 | # This compares the old implementation as a reference for the
|
795 | 806 | # vectorized one.
|
|
0 commit comments