Skip to content

Commit 66499d3

Browse files
committed
Implement a proper timestamp comparison with tolerance.
1 parent 5c09422 commit 66499d3

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/test/test_zipfile/test_core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,9 +1824,13 @@ def test_write_without_source_date_epoch(self):
18241824

18251825
with zipfile.ZipFile(TESTFN, "r") as zf:
18261826
zip_info = zf.getinfo("test_no_source_date_epoch.txt")
1827-
current_time = time.localtime()[:6]
1828-
for z_time, c_time in zip(zip_info.date_time, current_time):
1829-
self.assertAlmostEqual(z_time, c_time, delta=1)
1827+
self.assertTimestampAlmostEqual(time.localtime(), zip_info.date_time, tolerance=1)
1828+
1829+
def assertTimestampAlmostEqual(self, time1, time2, tolerance):
1830+
import datetime
1831+
dt1 = datetime.datetime(*time1[:6])
1832+
dt2 = datetime.datetime(*time2[:6])
1833+
self.assertLessEqual((dt1 - dt2).total_seconds(), tolerance)
18301834

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

0 commit comments

Comments
 (0)