jenkins-bot has submitted this change and it was merged.
Change subject: (bug 58943) Archivebot: create unit tests for Timestripper
......................................................................
(bug 58943) Archivebot: create unit tests for Timestripper
Unit tests for Timestripper. Initialization moved to
def setUp to prevent import deadlocks.
Change-Id: I521cdd0f5258c41e7e4d77e89ff616ed789b7824
Original-Change-Id: I12414e24f048ab7919a66be6c9b41e5b8e8c0c13
---
A tests/timestripper_tests.py
1 file changed, 72 insertions(+), 0 deletions(-)
Approvals:
Mpaa: Looks good to me, but someone else must approve
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py
new file mode 100644
index 0000000..12e0ff9
--- /dev/null
+++ b/tests/timestripper_tests.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+"""
+Tests for archivebot.py/Timestripper.
+"""
+#
+# (C) Pywikipedia bot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+
+
+import pywikibot
+from utils import PywikibotTestCase, unittest
+import scripts.archivebot as ab
+import re
+import datetime
+
+
+class TestTimeStripper(unittest.TestCase):
+ """Test cases for Link objects"""
+
+ def setUp(self):
+ site = pywikibot.Site('fr', 'wikipedia')
+ self.months = ab.Months(site=site)
+ self.months.updateMonths(site=site)
+ self.ts = ab.TimeStripper()
+
+ def test_findmarker(self):
+ """Test that string which is not part of text is
found"""
+
+ txt = u'this is a string with a maker is @@@@already present'
+ self.assertEqual(self.ts.findmarker(txt, base=u'@@',
delta='@@'),
+ '@@@@@@')
+
+ def test_last_match_and_replace(self):
+ """Test that pattern matches the righmost item"""
+
+ txtWithMatch = u'this string has one 1998, 1999 and 3000 in it'
+ txtWithNoMatch = u'this string has no match'
+ pat = self.ts.yearR
+
+ self.assertEqual(self.ts.last_match_and_replace(txtWithMatch, pat),
+ (u'this string has one @@, @@ and 3000 in it',
+ {'year': u'1999'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
+ (txtWithNoMatch,
+ None)
+ )
+
+ def test_timestripper(self):
+ """Test that correct date is matched"""
+
+ txtMatch = u'3 février 2010 à 19:48 (CET) 7 février 2010 à 19:48 (CET)'
+ txtNoMatch = u'3 March 2010 19:48 (CET) 7 March 2010 19:48 (CET)'
+
+ res = datetime.datetime(2010, 2, 7, 19, 48,
+ tzinfo=ab.tzoneFixedOffset(60, 'Europe/Paris'))
+
+ self.assertEqual(self.ts.timestripper(txtMatch), res)
+ self.assertEqual(self.ts.timestripper(txtNoMatch), None)
+
+
+if __name__ == '__main__':
+ try:
+ try:
+ unittest.main()
+ except SystemExit:
+ pass
+ finally:
+ pywikibot.stopme()
--
To view, visit
https://gerrit.wikimedia.org/r/109422
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I521cdd0f5258c41e7e4d77e89ff616ed789b7824
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>