jenkins-bot has submitted this change and it was merged.
Change subject: Fix timestamp tests if month changes
......................................................................
Fix timestamp tests if month changes
On the last and first day of a month, simply adding a day or subtracting
a day will cause the day to go out of bounds. So if the month changes,
it's probably the last or first day of a month.
Bug: T76285
Change-Id: Ibeb12f4f911c0bc9d40a92ca718464a90082f428
---
M tests/timestamp_tests.py
1 file changed, 9 insertions(+), 2 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/timestamp_tests.py b/tests/timestamp_tests.py
index c3e0c2b..a2dd8b8 100644
--- a/tests/timestamp_tests.py
+++ b/tests/timestamp_tests.py
@@ -7,6 +7,7 @@
#
__version__ = '$Id$'
+import calendar
import datetime
from pywikibot import Timestamp as T
@@ -55,7 +56,10 @@
def test_add_timedelta(self):
t1 = T.utcnow()
t2 = t1 + datetime.timedelta(days=1)
- self.assertEqual(t1.day + 1, t2.day)
+ if t1.month != t2.month:
+ self.assertEqual(1, t2.day)
+ else:
+ self.assertEqual(t1.day + 1, t2.day)
self.assertIsInstance(t2, T)
def test_add_timedate(self):
@@ -74,7 +78,10 @@
def test_sub_timedelta(self):
t1 = T.utcnow()
t2 = t1 - datetime.timedelta(days=1)
- self.assertEqual(t1.day - 1, t2.day)
+ if t1.month != t2.month:
+ self.assertEqual(calendar.monthrange(t2.year, t2.month)[1], t2.day)
+ else:
+ self.assertEqual(t1.day - 1, t2.day)
self.assertIsInstance(t2, T)
def test_sub_timedate(self):
--
To view, visit
https://gerrit.wikimedia.org/r/176501
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibeb12f4f911c0bc9d40a92ca718464a90082f428
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>