|
1 | 1 | import pandas as pd
|
2 |
| -from pandas._testing._warnings import assert_produces_warning |
| 2 | +import pandas._testing as tm |
3 | 3 | from pandas.core.accessor import DataFrameAccessorLoader
|
4 | 4 |
|
5 | 5 |
|
| 6 | +def test_no_accessors(monkeypatch): |
| 7 | + # GH29076 |
| 8 | + |
| 9 | + # Mock entry_points |
| 10 | + def mock_entry_points(*, group): |
| 11 | + return [] |
| 12 | + |
| 13 | + # Patch entry_points in the correct module |
| 14 | + monkeypatch.setattr("pandas.core.accessor.entry_points", mock_entry_points) |
| 15 | + |
| 16 | + DataFrameAccessorLoader.load() |
| 17 | + |
| 18 | + |
6 | 19 | def test_load_dataframe_accessors(monkeypatch):
|
7 | 20 | # GH29076
|
8 | 21 | # Mocked EntryPoint to simulate a plugin
|
@@ -74,7 +87,7 @@ def mock_entry_points(*, group):
|
74 | 87 | monkeypatch.setattr("pandas.core.accessor.entry_points", mock_entry_points)
|
75 | 88 |
|
76 | 89 | # Check that the UserWarning is raised
|
77 |
| - with assert_produces_warning(UserWarning, match="duplicate_accessor") as record: |
| 90 | + with tm.assert_produces_warning(UserWarning, match="duplicate_accessor") as record: |
78 | 91 | DataFrameAccessorLoader.load()
|
79 | 92 |
|
80 | 93 | messages = [str(w.message) for w in record]
|
@@ -123,7 +136,7 @@ def mock_entry_points(*, group):
|
123 | 136 | monkeypatch.setattr("pandas.core.accessor.entry_points", mock_entry_points)
|
124 | 137 |
|
125 | 138 | # Check that no UserWarning is raised
|
126 |
| - with assert_produces_warning(None, check_stacklevel=False): |
| 139 | + with tm.assert_produces_warning(None, check_stacklevel=False): |
127 | 140 | DataFrameAccessorLoader.load()
|
128 | 141 |
|
129 | 142 | df = pd.DataFrame({"x": [1, 2, 3]})
|
@@ -185,7 +198,7 @@ def mock_entry_points(*, group):
|
185 | 198 | monkeypatch.setattr("pandas.core.accessor.entry_points", mock_entry_points)
|
186 | 199 |
|
187 | 200 | # Capture warnings
|
188 |
| - with assert_produces_warning(UserWarning, match="duplicate_accessor") as record: |
| 201 | + with tm.assert_produces_warning(UserWarning, match="duplicate_accessor") as record: |
189 | 202 | DataFrameAccessorLoader.load()
|
190 | 203 |
|
191 | 204 | messages = [str(w.message) for w in record]
|
|
0 commit comments