|
7 | 7 | import numpy as np
|
8 | 8 | import pytest
|
9 | 9 |
|
10 |
| -sys.modules.pop("bz2", None) # Remove 'bz2' from available modules for testing |
11 |
| -from pandas.compat import get_bz2_file |
12 |
| - |
13 | 10 | import pandas as pd
|
14 | 11 | from pandas import Series
|
15 | 12 | import pandas._testing as tm
|
|
18 | 15 | from pandas.util.version import Version
|
19 | 16 |
|
20 | 17 |
|
21 |
| -def test_bz2_nonimport(): |
22 |
| - assert "bz2" not in sys.modules |
23 |
| - msg = "bz2 module not available." |
24 |
| - with pytest.raises(RuntimeError, match=msg): |
25 |
| - get_bz2_file() |
26 |
| - |
27 |
| - |
28 | 18 | def test_get_callable_name():
|
29 | 19 | getname = com.get_callable_name
|
30 | 20 |
|
@@ -255,3 +245,19 @@ def test_str_size():
|
255 | 245 | ]
|
256 | 246 | result = subprocess.check_output(call).decode()[-4:-1].strip("\n")
|
257 | 247 | assert int(result) == int(expected)
|
| 248 | + |
| 249 | + |
| 250 | +def test_bz2_missing_import(): |
| 251 | + # Check whether bz2 missing import is handled correctly (issue #53857) |
| 252 | + code = ( |
| 253 | + "import pytest\n" |
| 254 | + "sys.modules.pop('bz2', None)\n" |
| 255 | + "import pandas\n" |
| 256 | + "assert 'bz2' not in sys.modules\n" |
| 257 | + "from pandas.compat import get_bz2_file\n" |
| 258 | + "msg = 'bz2 module not available.'\n" |
| 259 | + "with pytest.raises(RuntimeError, match=msg):\n" |
| 260 | + "\tget_bz2_file()" |
| 261 | + ) |
| 262 | + call = [sys.executable, "-c", code] |
| 263 | + subprocess.check_output(call) |
0 commit comments