From 287a6c08566a80a80ef65921ba55ecf35579c9d9 Mon Sep 17 00:00:00 2001 From: Arnab Bose Date: Fri, 10 Jan 2025 07:40:40 +0530 Subject: [PATCH] fix: A test that passed locally but not on git workflow Related to issue #6. --- src/code/snap_holder_test.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/code/snap_holder_test.py b/src/code/snap_holder_test.py index 79e0b77..0227f38 100644 --- a/src/code/snap_holder_test.py +++ b/src/code/snap_holder_test.py @@ -26,7 +26,8 @@ # For testing, we can access private methods. # pyright: reportPrivateUsage=false -NOW = datetime.datetime.strptime("20250130", r"%Y%m%d") +# UTC time. +_NOW = datetime.datetime(2025, 1, 30, hour=12, minute=0, second=0) class SnapHolderTest(unittest.TestCase): @@ -78,14 +79,14 @@ def test_filecontent(self): snap = snap_holder.Snapshot(snap_destination) self.assertEqual(snap.metadata._to_file_content(), {"snap_type": "UNKNOWN"}) - snap.set_ttl("1 hour", now=NOW) + snap.set_ttl("1 hour", now=_NOW) self.assertEqual( snap.metadata._to_file_content(), - {"snap_type": "UNKNOWN", "expiry": 1738179000.0}, + {"snap_type": "UNKNOWN", "expiry": 1738222200.0}, ) # Setting to empty string erases ttl. - snap.set_ttl("", now=NOW) + snap.set_ttl("", now=_NOW) self.assertEqual(snap.metadata._to_file_content(), {"snap_type": "UNKNOWN"}) def test_expired(self): @@ -93,16 +94,16 @@ def test_expired(self): snap_destination = os.path.join(dir, "root-20231122193630") snap = snap_holder.Snapshot(snap_destination) - self.assertFalse(snap.metadata.is_expired(NOW)) + self.assertFalse(snap.metadata.is_expired(_NOW)) - snap.set_ttl("1 h", now=NOW) - self.assertFalse(snap.metadata.is_expired(NOW)) + snap.set_ttl("1 h", now=_NOW) + self.assertFalse(snap.metadata.is_expired(_NOW)) - snap.metadata.expiry = NOW.timestamp() - 100 - self.assertTrue(snap.metadata.is_expired(NOW)) + snap.metadata.expiry = _NOW.timestamp() - 100 + self.assertTrue(snap.metadata.is_expired(_NOW)) - snap.metadata.expiry = NOW.timestamp() + 100 - self.assertFalse(snap.metadata.is_expired(NOW)) + snap.metadata.expiry = _NOW.timestamp() + 100 + self.assertFalse(snap.metadata.is_expired(_NOW)) if __name__ == "__main__":