Mpaa has uploaded a new change for review. https://gerrit.wikimedia.org/r/109600
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: I58cbf7130434245d018fedc173cb1b0da3401d78 --- M externals/httplib2 A tests/timestripper_tests.py 2 files changed, 70 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/00/109600/1 diff --git a/externals/httplib2 b/externals/httplib2 index df74529..d6c474d 160000 --- a/externals/httplib2 +++ b/externals/httplib2 -Subproject commit df7452960979951a639f3f9a6200336d3a264fd9 +Subproject commit d6c474df208e2594b4d08cd5df237eba477d8a7e diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py new file mode 100644 index 0000000..9d99a6c --- /dev/null +++ b/tests/timestripper_tests.py @@ -0,0 +1,70 @@ +# -*- 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 +from scripts.archivebot import TimeStripper, tzoneFixedOffset +import re +import datetime + + +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() -- To view, visit https://gerrit.wikimedia.org/r/109600 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I58cbf7130434245d018fedc173cb1b0da3401d78 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Mpaa <mpaa.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits