Skip to content

Commit fc6d4b7

Browse files
Eclips4cmaloney
andauthored
pythongh-129192: Use EnvironmentVarGuard to restore environment variables (python#129193)
Co-authored-by: Cody Maloney <[email protected]>
1 parent 67d804b commit fc6d4b7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Lib/test/test_zipfile/test_core.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1801,17 +1801,17 @@ def test_write_with_source_date_epoch(self):
18011801
self.assertAlmostEqual(z_time, g_time, delta=1)
18021802

18031803
def test_write_without_source_date_epoch(self):
1804-
if 'SOURCE_DATE_EPOCH' in os.environ:
1805-
del os.environ['SOURCE_DATE_EPOCH']
1804+
with os_helper.EnvironmentVarGuard() as env:
1805+
del env['SOURCE_DATE_EPOCH']
18061806

1807-
with zipfile.ZipFile(TESTFN, "w") as zf:
1808-
zf.writestr("test_no_source_date_epoch.txt", "Testing without SOURCE_DATE_EPOCH")
1807+
with zipfile.ZipFile(TESTFN, "w") as zf:
1808+
zf.writestr("test_no_source_date_epoch.txt", "Testing without SOURCE_DATE_EPOCH")
18091809

1810-
with zipfile.ZipFile(TESTFN, "r") as zf:
1811-
zip_info = zf.getinfo("test_no_source_date_epoch.txt")
1812-
current_time = time.localtime()[:6]
1813-
for z_time, c_time in zip(zip_info.date_time, current_time):
1814-
self.assertAlmostEqual(z_time, c_time, delta=1)
1810+
with zipfile.ZipFile(TESTFN, "r") as zf:
1811+
zip_info = zf.getinfo("test_no_source_date_epoch.txt")
1812+
current_time = time.localtime()[:6]
1813+
for z_time, c_time in zip(zip_info.date_time, current_time):
1814+
self.assertAlmostEqual(z_time, c_time, delta=1)
18151815

18161816
def test_close(self):
18171817
"""Check that the zipfile is closed after the 'with' block."""

0 commit comments

Comments
 (0)