Skip to content

Commit d8bc837

Browse files
committed
Add tests for error message
1 parent de32dd2 commit d8bc837

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/tslibs/test_timezones.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
timedelta,
44
timezone,
55
)
6+
import subprocess
7+
import sys
8+
import textwrap
69

710
import dateutil.tz
811
import pytest
@@ -16,6 +19,24 @@
1619
from pandas import Timestamp
1720

1821

22+
def test_no_timezone_data():
23+
# https://github.com/pandas-dev/pandas/pull/63335
24+
# Test error message when timezone data is not available.
25+
msg = "'No time zone found with key Europe/Brussels'"
26+
code = textwrap.dedent(
27+
f"""\
28+
import sys, zoneinfo, pandas as pd
29+
sys.modules['tzdata'] = None
30+
zoneinfo.reset_tzpath(['/path/to/nowhere'])
31+
try:
32+
pd.to_datetime('2012-01-01').tz_localize('Europe/Brussels')
33+
except zoneinfo.ZoneInfoNotFoundError as err:
34+
assert str(err) == "{msg}"
35+
"""
36+
)
37+
subprocess.check_call([sys.executable, "-c", code])
38+
39+
1940
def test_is_utc(utc_fixture):
2041
tz = timezones.maybe_get_tz(utc_fixture)
2142
assert timezones.is_utc(tz)

0 commit comments

Comments
 (0)