Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3597
Status: Errored
Duration: 33 minutes and 47 seconds
Commit: 76279dd (master)
Author: xqt
Message: [bugfix] Add test for lagpattern
- When the regex acts as expected site.throttle.lag is called.
The DummyThrottle saves the lag value and raises an exception
to escape from the while loop inside api.Request.submit().
Do some minor tests with that value.
Otherwise when regex cannot extract the value api raises an
APIError in his normal way. Print an additional warning that
the lagpattern fails in that case.
Bug: T144023
Change-Id: I96adc5b5d8bbf65a7c99d380a0f1df6108a5dcfd
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/eeab621ce115...76279dd6…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/155725181
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Add test for lagpattern
......................................................................
[bugfix] Add test for lagpattern
- When the regex acts as expected site.throttle.lag is called.
The DummyThrottle saves the lag value and raises an exception
to escape from the while loop inside api.Request.submit().
Do some minor tests with that value.
Otherwise when regex cannot extract the value api raises an
APIError in his normal way. Print an additional warning that
the lagpattern fails in that case.
Bug: T144023
Change-Id: I96adc5b5d8bbf65a7c99d380a0f1df6108a5dcfd
---
M tests/api_tests.py
1 file changed, 41 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index c236f68..5507956 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""API test module."""
#
-# (C) Pywikibot team, 2007-2015
+# (C) Pywikibot team, 2007-2016
#
# Distributed under the terms of the MIT license.
#
@@ -18,6 +18,7 @@
import pywikibot.page
import pywikibot.site
+from pywikibot.throttle import Throttle
from pywikibot.tools import (
MediaWikiVersion,
PY2,
@@ -1026,6 +1027,45 @@
self.assertEqual(result, expect)
self.assertIsInstance(result, str)
+
+class DummyThrottle(Throttle):
+
+ """Dummy Throttle class."""
+
+ def lag(self, lag):
+ """Override lag method, save the lag value and exit the api loop."""
+ self._lagvalue = lag # save the lag value
+ raise SystemExit # exit the api loop
+
+
+class TestLagpattern(DefaultSiteTestCase):
+
+ """Test the lag pattern."""
+
+ cached = False
+
+ def test_valid_lagpattern(self):
+ """Test whether api.lagpattern is valid."""
+ mysite = self.get_site()
+ mythrottle = DummyThrottle(mysite)
+ mysite._throttle = mythrottle
+ params = {'action': 'query',
+ 'titles': self.get_mainpage().title(),
+ 'maxlag': -1}
+ req = api.Request(site=mysite, parameters=params)
+ try:
+ req.submit()
+ except SystemExit:
+ pass # expected exception from DummyThrottle instance
+ except api.APIError as e:
+ pywikibot.warning(
+ 'Wrong api.lagpattern regex, cannot retrieve lag value')
+ raise e
+ value = mysite.throttle._lagvalue
+ self.assertIsInstance(value, int)
+ self.assertGreaterEqual(value, 0)
+
+
if __name__ == '__main__': # pragma: no cover
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/307121
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I96adc5b5d8bbf65a7c99d380a0f1df6108a5dcfd
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Update lagpattern
......................................................................
[bugfix] Update lagpattern
Backport I081fe872c437177 from core
Bug: T144023
Change-Id: I1586b01fda359e427f8368004af001290a39d8ba
---
M wikipedia.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia.py b/wikipedia.py
index a330824..39ad3bb 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -2417,7 +2417,7 @@
if errorCode == 'maxlag' or response.code == 503:
# server lag; wait for the lag time and retry
lagpattern = re.compile(
- r"Waiting for [\d.]+: (?P<lag>\d+) seconds? lagged")
+ r'Waiting for [\w. ]+: (?P<lag>\d+)(?:\.\d+)? seconds? lagged')
lag = lagpattern.search(data['error']['info'])
timelag = int(lag.group("lag"))
output(u"Pausing %d seconds due to database server lag."
--
To view, visit https://gerrit.wikimedia.org/r/307118
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1586b01fda359e427f8368004af001290a39d8ba
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>