8000 gh-106233: Fix stacklevel in `zoneinfo.InvalidTZPathWarning` by sobolevn · Pull Request #106234 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning #106234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review
  • Loading branch information
sobolevn committed Feb 6, 2024
commit 0a2800ed7e8f1a78a5ae0e9f01889b0a1cf379c4
35 changes: 21 additions & 14 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import struct
import tempfile
import unittest
import warnings
from datetime import date, datetime, time, timedelta, timezone
from functools import cached_property

Expand Down Expand Up @@ -1718,19 +1717,6 @@ def test_env_variable_relative_paths(self):
for input_paths, expected_paths in test_cases:
path_var = os.pathsep.join(input_paths)
with self.python_tzpath_context(path_var):
with self.subTest("module-level warning", path_var=path_var):
with CleanImport("zoneinfo", "zoneinfo._tzpath"):
with warnings.catch_warnings(record=True) as wlog:
import zoneinfo
self.assertEqual(len(wlog), 1)
# Since we use import hacks, we cannot just use `isinstance`
self.assertEqual(
type(wlog[0].message).__qualname__,
"InvalidTZPathWarning",
)
# It should represent the current file:
self.assertEqual(wlog[0].filename, __file__)

with self.subTest("warning", path_var=path_var):
# Note: Per PEP 615 the warning is implementation-defined
# behavior, other implementations need not warn.
Expand All @@ -1742,6 +1728,27 @@ def test_env_variable_relative_paths(self):
with self.subTest("filtered", path_var=path_var):
self.assertSequenceEqual(tzpath, expected_paths)

def test_env_variable_relative_paths_warning_location(self):
path_var = "path/to/somewhere"

with self.python_tzpath_context(path_var):
with self.subTest("module-level warning"):
with CleanImport("zoneinfo", "zoneinfo._tzpath"):
with self.assertWarns(RuntimeWarning) as w:
import zoneinfo
# Since we use import hacks, we cannot just use `isinstance`
self.assertEqual(
type(w.warnings[0].message).__qualname__,
"InvalidTZPathWarning",
)
# It should represent the current file:
self.assertEqual(w.warnings[0].filename, __file__)

with self.subTest("warning"):
with self.assertWarns(self.module.InvalidTZPathWarning) as w:
self.module.reset_tzpath()
self.assertEqual(w.warnings[0].filename, __file__)

def test_reset_tzpath_kwarg(self):
self.module.reset_tzpath(to=[f"{DRIVE}/a/b/c"])

Expand Down
0