diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2024-02-06 13:08:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 13:08:56 (GMT) |
commit | d7334e2c2012defaf7aae920d6a56689464509d1 (patch) | |
tree | f0aa2f7425f7fefd043a636b46a85ef1e487c69e /Lib/test/test_zoneinfo | |
parent | 1a10437a14b13100bdf41cbdab819c33258deb65 (diff) | |
download | cpython-d7334e2c2012defaf7aae920d6a56689464509d1.zip cpython-d7334e2c2012defaf7aae920d6a56689464509d1.tar.gz cpython-d7334e2c2012defaf7aae920d6a56689464509d1.tar.bz2 |
gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning (GH-106234)
Diffstat (limited to 'Lib/test/test_zoneinfo')
-rw-r--r-- | Lib/test/test_zoneinfo/test_zoneinfo.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index 18eab5b..8414721 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -20,7 +20,7 @@ from functools import cached_property from test.support import MISSING_C_DOCSTRINGS from test.test_zoneinfo import _support as test_support from test.test_zoneinfo._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase -from test.support.import_helper import import_module +from test.support.import_helper import import_module, CleanImport lzma = import_module('lzma') py_zoneinfo, c_zoneinfo = test_support.get_modules() @@ -1720,13 +1720,26 @@ class TzPathTest(TzPathUserMixin, ZoneInfoTestBase): with self.subTest("warning", path_var=path_var): # Note: Per PEP 615 the warning is implementation-defined # behavior, other implementations need not warn. - with self.assertWarns(self.module.InvalidTZPathWarning): + with self.assertWarns(self.module.InvalidTZPathWarning) as w: self.module.reset_tzpath() + self.assertEqual(w.warnings[0].filename, __file__) tzpath = self.module.TZPATH 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 CleanImport("zoneinfo", "zoneinfo._tzpath"): + with self.assertWarns(RuntimeWarning) as w: + import zoneinfo + InvalidTZPathWarning = zoneinfo.InvalidTZPathWarning + self.assertIsInstance(w.warnings[0].message, InvalidTZPathWarning) + # It should represent the current file: + self.assertEqual(w.warnings[0].filename, __file__) + def test_reset_tzpath_kwarg(self): self.module.reset_tzpath(to=[f"{DRIVE}/a/b/c"]) |