|
1 |
| -import os |
2 |
| -import platform |
3 |
| -from typing import TYPE_CHECKING |
4 | 1 | import warnings
|
5 | 2 |
|
6 | 3 | from pandas import errors
|
7 | 4 | import pytest
|
8 | 5 |
|
9 |
| -from tests import PD_LT_15 |
10 |
| - |
11 |
| -if TYPE_CHECKING or PD_LT_15: |
12 |
| - # TODO: Remove all imports below after switch to 1.5.x, these moved to pandas.errors |
13 |
| - from pandas.core.base import ( |
14 |
| - DataError, |
15 |
| - SpecificationError, |
16 |
| - ) |
17 |
| - from pandas.core.common import ( |
18 |
| - SettingWithCopyError, |
19 |
| - SettingWithCopyWarning, |
20 |
| - ) |
21 |
| - from pandas.core.computation.engines import NumExprClobberingError |
22 |
| - from pandas.core.computation.ops import UndefinedVariableError |
23 |
| - from pandas.core.indexing import IndexingError |
24 |
| - |
25 |
| - from pandas.io.clipboard import ( |
26 |
| - PyperclipException, |
27 |
| - PyperclipWindowsException, |
28 |
| - ) |
29 |
| - from pandas.io.formats.css import CSSWarning |
30 |
| - from pandas.io.pytables import ( |
31 |
| - AttributeConflictWarning, |
32 |
| - ClosedFileError, |
33 |
| - IncompatibilityWarning, |
34 |
| - PossibleDataLossError, |
35 |
| - ) |
36 |
| - from pandas.io.sql import DatabaseError |
37 |
| - from pandas.io.stata import ( |
38 |
| - CategoricalConversionWarning, |
39 |
| - InvalidColumnName, |
40 |
| - PossiblePrecisionLoss, |
41 |
| - ValueLabelTypeMismatch, |
42 |
| - ) |
43 |
| -else: |
44 |
| - from pandas.errors import ( |
45 |
| - AttributeConflictWarning, |
46 |
| - CategoricalConversionWarning, |
47 |
| - ClosedFileError, |
48 |
| - CSSWarning, |
49 |
| - DatabaseError, |
50 |
| - DataError, |
51 |
| - IncompatibilityWarning, |
52 |
| - IndexingError, |
53 |
| - InvalidColumnName, |
54 |
| - NumExprClobberingError, |
55 |
| - PossibleDataLossError, |
56 |
| - PossiblePrecisionLoss, |
57 |
| - PyperclipException, |
58 |
| - PyperclipWindowsException, |
59 |
| - SettingWithCopyError, |
60 |
| - SettingWithCopyWarning, |
61 |
| - SpecificationError, |
62 |
| - UndefinedVariableError, |
63 |
| - ValueLabelTypeMismatch, |
64 |
| - ) |
65 |
| - |
66 |
| -WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower() |
| 6 | +from tests import WINDOWS |
67 | 7 |
|
68 | 8 |
|
69 | 9 | def test_abstract_method_error() -> None:
|
@@ -160,96 +100,96 @@ def test_unsupported_function_call() -> None:
|
160 | 100 |
|
161 | 101 |
|
162 | 102 | def test_data_error() -> None:
|
163 |
| - with pytest.raises(DataError): |
164 |
| - raise DataError() |
| 103 | + with pytest.raises(errors.DataError): |
| 104 | + raise errors.DataError() |
165 | 105 |
|
166 | 106 |
|
167 | 107 | def test_specification_error() -> None:
|
168 |
| - with pytest.raises(SpecificationError): |
169 |
| - raise SpecificationError() |
| 108 | + with pytest.raises(errors.SpecificationError): |
| 109 | + raise errors.SpecificationError() |
170 | 110 |
|
171 | 111 |
|
172 | 112 | def test_setting_with_copy_error() -> None:
|
173 |
| - with pytest.raises(SettingWithCopyError): |
174 |
| - raise SettingWithCopyError() |
| 113 | + with pytest.raises(errors.SettingWithCopyError): |
| 114 | + raise errors.SettingWithCopyError() |
175 | 115 |
|
176 | 116 |
|
177 | 117 | def test_setting_with_copy_warning() -> None:
|
178 |
| - with pytest.warns(SettingWithCopyWarning): |
179 |
| - warnings.warn("", SettingWithCopyWarning) |
| 118 | + with pytest.warns(errors.SettingWithCopyWarning): |
| 119 | + warnings.warn("", errors.SettingWithCopyWarning) |
180 | 120 |
|
181 | 121 |
|
182 | 122 | def test_numexpr_clobbering_error() -> None:
|
183 |
| - with pytest.raises(NumExprClobberingError): |
184 |
| - raise NumExprClobberingError() |
| 123 | + with pytest.raises(errors.NumExprClobberingError): |
| 124 | + raise errors.NumExprClobberingError() |
185 | 125 |
|
186 | 126 |
|
187 | 127 | def test_undefined_variable_error() -> None:
|
188 |
| - with pytest.raises(UndefinedVariableError): |
189 |
| - raise UndefinedVariableError("x") |
| 128 | + with pytest.raises(errors.UndefinedVariableError): |
| 129 | + raise errors.UndefinedVariableError("x") |
190 | 130 |
|
191 | 131 |
|
192 | 132 | def test_indexing_error() -> None:
|
193 |
| - with pytest.raises(IndexingError): |
194 |
| - raise IndexingError() |
| 133 | + with pytest.raises(errors.IndexingError): |
| 134 | + raise errors.IndexingError() |
195 | 135 |
|
196 | 136 |
|
197 | 137 | def test_pyperclip_exception() -> None:
|
198 |
| - with pytest.raises(PyperclipException): |
199 |
| - raise PyperclipException() |
| 138 | + with pytest.raises(errors.PyperclipException): |
| 139 | + raise errors.PyperclipException() |
200 | 140 |
|
201 | 141 |
|
202 |
| -@pytest.mark.skipif(not PD_LT_15 or not WINDOWS, reason="Feature moved in 1.5.0") |
| 142 | +@pytest.mark.skipif(not WINDOWS, reason="Windows only") |
203 | 143 | def test_pyperclip_windows_exception() -> None:
|
204 |
| - with pytest.raises(PyperclipWindowsException): |
205 |
| - raise PyperclipWindowsException("message") |
| 144 | + with pytest.raises(errors.PyperclipWindowsException): |
| 145 | + raise errors.PyperclipWindowsException("message") |
206 | 146 |
|
207 | 147 |
|
208 | 148 | def test_css_warning() -> None:
|
209 |
| - with pytest.warns(CSSWarning): |
210 |
| - warnings.warn("", CSSWarning) |
| 149 | + with pytest.warns(errors.CSSWarning): |
| 150 | + warnings.warn("", errors.CSSWarning) |
211 | 151 |
|
212 | 152 |
|
213 | 153 | def test_possible_data_loss_error() -> None:
|
214 |
| - with pytest.raises(PossibleDataLossError): |
215 |
| - raise PossibleDataLossError() |
| 154 | + with pytest.raises(errors.PossibleDataLossError): |
| 155 | + raise errors.PossibleDataLossError() |
216 | 156 |
|
217 | 157 |
|
218 | 158 | def test_closed_file_error() -> None:
|
219 |
| - with pytest.raises(ClosedFileError): |
220 |
| - raise ClosedFileError() |
| 159 | + with pytest.raises(errors.ClosedFileError): |
| 160 | + raise errors.ClosedFileError() |
221 | 161 |
|
222 | 162 |
|
223 | 163 | def test_incompatibility_warning() -> None:
|
224 |
| - with pytest.warns(IncompatibilityWarning): |
225 |
| - warnings.warn("", IncompatibilityWarning) |
| 164 | + with pytest.warns(errors.IncompatibilityWarning): |
| 165 | + warnings.warn("", errors.IncompatibilityWarning) |
226 | 166 |
|
227 | 167 |
|
228 | 168 | def test_attribute_conflict_warning() -> None:
|
229 |
| - with pytest.warns(AttributeConflictWarning): |
230 |
| - warnings.warn("", AttributeConflictWarning) |
| 169 | + with pytest.warns(errors.AttributeConflictWarning): |
| 170 | + warnings.warn("", errors.AttributeConflictWarning) |
231 | 171 |
|
232 | 172 |
|
233 | 173 | def test_database_error() -> None:
|
234 |
| - with pytest.raises(DatabaseError): |
235 |
| - raise DatabaseError() |
| 174 | + with pytest.raises(errors.DatabaseError): |
| 175 | + raise errors.DatabaseError() |
236 | 176 |
|
237 | 177 |
|
238 | 178 | def test_possible_precision_loss() -> None:
|
239 |
| - with pytest.warns(PossiblePrecisionLoss): |
240 |
| - warnings.warn("", PossiblePrecisionLoss) |
| 179 | + with pytest.warns(errors.PossiblePrecisionLoss): |
| 180 | + warnings.warn("", errors.PossiblePrecisionLoss) |
241 | 181 |
|
242 | 182 |
|
243 | 183 | def test_value_label_type_mismatch() -> None:
|
244 |
| - with pytest.warns(ValueLabelTypeMismatch): |
245 |
| - warnings.warn("", ValueLabelTypeMismatch) |
| 184 | + with pytest.warns(errors.ValueLabelTypeMismatch): |
| 185 | + warnings.warn("", errors.ValueLabelTypeMismatch) |
246 | 186 |
|
247 | 187 |
|
248 | 188 | def test_invalid_column_name() -> None:
|
249 |
| - with pytest.warns(InvalidColumnName): |
250 |
| - warnings.warn("", InvalidColumnName) |
| 189 | + with pytest.warns(errors.InvalidColumnName): |
| 190 | + warnings.warn("", errors.InvalidColumnName) |
251 | 191 |
|
252 | 192 |
|
253 | 193 | def test_categorical_conversion_warning() -> None:
|
254 |
| - with pytest.warns(CategoricalConversionWarning): |
255 |
| - warnings.warn("", CategoricalConversionWarning) |
| 194 | + with pytest.warns(errors.CategoricalConversionWarning): |
| 195 | + warnings.warn("", errors.CategoricalConversionWarning) |
0 commit comments