jenkins-bot has submitted this change and it was merged. Change subject: [IMPROV] TimeStripper: Deprecate findmarker duplicate ......................................................................
[IMPROV] TimeStripper: Deprecate findmarker duplicate The `findmarker` method in `TimeStripper` works exactly the same as the function in the module. This is deprecating the method in the class in favour of the module function. This is also introducing a new super class in the corresponding tests which will take care of creating the `TimeStripper` instance. Change-Id: Ia349e78e68d94fc6c6ceab75d8b679bbee48b2b7 --- M pywikibot/textlib.py M tests/timestripper_tests.py 2 files changed, 32 insertions(+), 24 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 54d20eb..f5c2888 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -39,6 +39,7 @@ from pywikibot.exceptions import InvalidTitle from pywikibot.family import Family from pywikibot.tools import ( + deprecated, DeprecatedRegex, OrderedDict, UnicodeType, @@ -1747,11 +1748,10 @@ self.tzinfo = tzoneFixedOffset(self.site.siteinfo['timeoffset'], self.site.siteinfo['timezone']) + @deprecated('module function') def findmarker(self, text, base=u'@@', delta='@'): """Find a string which is not part of text.""" - while base in text: - base += delta - return base + return findmarker(text, base, delta) def fix_digits(self, line): """Make non-latin digits like Persian to latin to parse.""" @@ -1772,7 +1772,7 @@ cnt += 1 if m: - marker = self.findmarker(txt) + marker = findmarker(txt) # month and day format might be identical (e.g. see bug 69315), # avoid to wipe out day, after month is matched. # replace all matches but the last two diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py index 61a20ab..4c5a9fc 100644 --- a/tests/timestripper_tests.py +++ b/tests/timestripper_tests.py @@ -13,28 +13,45 @@ from pywikibot.textlib import TimeStripper, tzoneFixedOffset -from tests.aspects import unittest, TestCase +from tests.aspects import ( + unittest, + TestCase, + DefaultSiteTestCase, + DeprecationTestCase, +) -class TestTimeStripperWithNoDigitsAsMonths(TestCase): +class TestTimeStripperCase(TestCase): - """Test cases for TimeStripper methods.""" - - family = 'wikipedia' - code = 'fr' + """Basic class to test the TimeStripper class.""" cached = True def setUp(self): """Set up test cases.""" - super(TestTimeStripperWithNoDigitsAsMonths, self).setUp() + super(TestTimeStripperCase, self).setUp() self.ts = TimeStripper(self.get_site()) + + +class DeprecatedTestTimeStripperCase(TestTimeStripperCase, DeprecationTestCase, + DefaultSiteTestCase): + + """Test deprecated parts of the TimeStripper class.""" 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='@@'), '@@@@@@') + self.assertOneDeprecation() + + +class TestTimeStripperWithNoDigitsAsMonths(TestTimeStripperCase): + + """Test cases for TimeStripper methods.""" + + family = 'wikipedia' + code = 'fr' def test_last_match_and_replace(self): """Test that pattern matches and removes items correctly.""" @@ -88,19 +105,12 @@ self.assertEqual(self.ts.timestripper(txtHourOutOfRange), None) -class TestTimeStripperWithDigitsAsMonths(TestCase): +class TestTimeStripperWithDigitsAsMonths(TestTimeStripperCase): """Test cases for TimeStripper methods.""" family = 'wikipedia' code = 'cs' - - cached = True - - def setUp(self): - """Setup a timestripper for the configured site.""" - super(TestTimeStripperWithDigitsAsMonths, self).setUp() - self.ts = TimeStripper(self.get_site()) def test_last_match_and_replace(self): """Test that pattern matches and removes items correctly.""" @@ -236,7 +246,7 @@ self.assertEqual(self.ts.timestripper(txtNoMatch), None) -class TestTimeStripperDoNotArchiveUntil(TestCase): +class TestTimeStripperDoNotArchiveUntil(TestTimeStripperCase): """Test cases for Do Not Archive Until templates. @@ -247,8 +257,6 @@ family = 'wikisource' code = 'en' - cached = True - username = '[[User:DoNotArchiveUntil]]' date = '06:57 06 June 2015 (UTC)' user_and_date = username + ' ' + date @@ -256,7 +264,7 @@ def test_timestripper_match(self): """Test that dates in comments are correctly recognised.""" - ts = TimeStripper(self.get_site()) + ts = self.ts txt_match = '<!-- [[User:Do___ArchiveUntil]] ' + self.date + ' -->' res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone) @@ -272,7 +280,7 @@ def test_timestripper_match_only(self): """Test that latest date is used instead of other dates.""" - ts = TimeStripper(self.get_site()) + ts = self.ts later_date = '10:57 06 June 2015 (UTC)' txt_match = '<!-- --> ' + self.user_and_date + ' <!-- -->' + later_date -- To view, visit https://gerrit.wikimedia.org/r/253965 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia349e78e68d94fc6c6ceab75d8b679bbee48b2b7 Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits