Skip to content

Commit

Permalink
gh-129192: Use EnvironmentVarGuard to restore environment variables (
Browse files Browse the repository at this point in the history
…#129193)

Co-authored-by: Cody Maloney <cmaloney@theoreticalchaos.com>
  • Loading branch information
Eclips4 and cmaloney authored Jan 22, 2025
1 parent 67d804b commit fc6d4b7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Lib/test/test_zipfile/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,17 +1801,17 @@ def test_write_with_source_date_epoch(self):
self.assertAlmostEqual(z_time, g_time, delta=1)

def test_write_without_source_date_epoch(self):
if 'SOURCE_DATE_EPOCH' in os.environ:
del os.environ['SOURCE_DATE_EPOCH']
with os_helper.EnvironmentVarGuard() as env:
del env['SOURCE_DATE_EPOCH']

with zipfile.ZipFile(TESTFN, "w") as zf:
zf.writestr("test_no_source_date_epoch.txt", "Testing without SOURCE_DATE_EPOCH")
with zipfile.ZipFile(TESTFN, "w") as zf:
zf.writestr("test_no_source_date_epoch.txt", "Testing without SOURCE_DATE_EPOCH")

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

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

0 comments on commit fc6d4b7

Please sign in to comment.