Xqt 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. (after removal of Month() class)
Change-Id: I875116dc68d5247da762c7d064dce978217ece9c See-also-Change-Id: I58cbf7130434245d018fedc173cb1b0da3401d78 --- A tests/timestripper_tests.py 1 file changed, 72 insertions(+), 0 deletions(-)
Approvals: Xqt: Verified; Looks good to me, approved Pyfisch: Verified; Looks good to me, approved
diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py new file mode 100644 index 0000000..2cf56d8 --- /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 datetime +import re + +import pywikibot + +from utils import PywikibotTestCase, unittest + +from scripts.archivebot import TimeStripper, tzoneFixedOffset + + +class TestTimeStripper(unittest.TestCase): + """Test cases for Link objects""" + + def setUp(self): + site = pywikibot.Site('fr', 'wikipedia') + self.ts = TimeStripper(site) + + 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=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()
pywikibot-commits@lists.wikimedia.org