Skip to content

Commit 3126ac3

Browse files
committed
finish
1 parent c363f56 commit 3126ac3

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Lib/test/test_zipfile/_path/test_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def for_name(cls, name, archive):
667667
TODO: extract this functionality and re-use
668668
"""
669669
epoch = os.environ.get('SOURCE_DATE_EPOCH')
670-
get_time = int(epoch) if epoch is not None else time.time()
670+
get_time = int(epoch) if epoch else time.time()
671671
self = cls(filename=name, date_time=time.gmtime(get_time)[:6])
672672
self.compress_type = archive.compression
673673
self.compress_level = archive.compresslevel

Lib/test/test_zipfile/test_core.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,15 +1781,19 @@ def test_writestr_extended_local_header_issue1202(self):
17811781
orig_zip.writestr(zinfo, data)
17821782

17831783
def test_write_with_source_date_epoch(self):
1784-
os.environ['SOURCE_DATE_EPOCH'] = "1727351057"
1784+
# Set the SOURCE_DATE_EPOCH environment variable to a specific timestamp
1785+
os.environ['SOURCE_DATE_EPOCH'] = "1727440508"
17851786

17861787
with zipfile.ZipFile(TESTFN, "w") as zf:
17871788
zf.writestr("test_source_date_epoch.txt", "Testing SOURCE_DATE_EPOCH")
17881789

17891790
with zipfile.ZipFile(TESTFN, "r") as zf:
17901791
zip_info = zf.getinfo("test_source_date_epoch.txt")
17911792
get_time = time.gmtime(int(os.environ['SOURCE_DATE_EPOCH']))[:6]
1792-
self.assertAlmostEqual(zip_info.date_time, get_time, delta=1)
1793+
# Compare each element of the date_time tuple
1794+
# Allow for a 1-second difference
1795+
for z_time, g_time in zip(zip_info.date_time, get_time):
1796+
self.assertAlmostEqual(z_time, g_time, delta=1)
17931797

17941798
def test_write_without_source_date_epoch(self):
17951799
if 'SOURCE_DATE_EPOCH' in os.environ:
@@ -1800,7 +1804,9 @@ def test_write_without_source_date_epoch(self):
18001804

18011805
with zipfile.ZipFile(TESTFN, "r") as zf:
18021806
zip_info = zf.getinfo("test_no_source_date_epoch.txt")
1803-
self.assertEqual(zip_info.date_time, time.gmtime()[:6])
1807+
current_time = time.gmtime()[:6]
1808+
for z_time, c_time in zip(zip_info.date_time, current_time):
1809+
self.assertAlmostEqual(z_time, c_time, delta=1)
18041810

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

Lib/zipfile/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,7 @@ def writestr(self, zinfo_or_arcname, data,
19041904
if isinstance(data, str):
19051905
data = data.encode("utf-8")
19061906
if not isinstance(zinfo_or_arcname, ZipInfo):
1907+
# gh-91279: Set the SOURCE_DATE_EPOCH to a specific timestamp
19071908
epoch = os.environ.get('SOURCE_DATE_EPOCH')
19081909
get_time = int(epoch) if epoch else time.time()
19091910
zinfo = ZipInfo(filename=zinfo_or_arcname,

0 commit comments

Comments
 (0)