Skip to content

Commit

Permalink
TST: Test bz2 non-import from subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jun 26, 2023
1 parent 1ab1045 commit 3ac3ced
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import numpy as np
import pytest

sys.modules.pop("bz2", None) # Remove 'bz2' from available modules for testing
from pandas.compat import get_bz2_file

import pandas as pd
from pandas import Series
import pandas._testing as tm
Expand All @@ -18,13 +15,6 @@
from pandas.util.version import Version


def test_bz2_nonimport():
assert "bz2" not in sys.modules
msg = "bz2 module not available."
with pytest.raises(RuntimeError, match=msg):
get_bz2_file()


def test_get_callable_name():
getname = com.get_callable_name

Expand Down Expand Up @@ -255,3 +245,19 @@ def test_str_size():
]
result = subprocess.check_output(call).decode()[-4:-1].strip("\n")
assert int(result) == int(expected)


def test_bz2_missing_import():
# Check whether bz2 missing import is handled correctly (issue #53857)
code = (
"import pytest\n"
"sys.modules.pop('bz2', None)\n"
"import pandas\n"
"assert 'bz2' not in sys.modules\n"
"from pandas.compat import get_bz2_file\n"
"msg = 'bz2 module not available.'\n"
"with pytest.raises(RuntimeError, match=msg):\n"
"\tget_bz2_file()"
)
call = [sys.executable, "-c", code]
subprocess.check_output(call)

0 comments on commit 3ac3ced

Please sign in to comment.