jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] Support assertAPIError
......................................................................
[FEAT] Support assertAPIError
To assert a specific APIError the base class supports `assertAPIError` which
wraps around `assertRaises` and additionally checks if the error is of a
specific code and optionally a specific info. Like `assertRaises` it can be
used as a context manager when additional checks should be done afterwards.
Change-Id: Ib211974ec3acd17fb45c2280e084723257a88650
---
M tests/aspects.py
M tests/upload_tests.py
M tests/utils.py
3 files changed, 72 insertions(+), 6 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py
index 0503077..2dfcc09 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -56,7 +56,7 @@
from tests import unittest, patch_request, unpatch_request
from tests.utils import (
add_metaclass, execute_pwb, DrySite, DryRequest,
- WarningSourceSkipContextManager,
+ WarningSourceSkipContextManager, AssertAPIErrorContextManager,
)
OSWIN32 = (sys.platform == 'win32')
@@ -263,6 +263,33 @@
assertPagelistTitles = assertPageTitlesEqual
+ def assertAPIError(self, code, info=None, callable_obj=None, *args,
+ **kwargs):
+ """
+ Assert that a specific APIError wrapped around L{assertRaises}.
+
+ If no callable object is defined and it returns a context manager, that
+ context manager will return the underlying context manager used by
+ L{assertRaises}. So it's possible to access the APIError by using it's
+ C{exception} attribute.
+
+ @param code: The code of the error which must have happened.
+ @type code: str
+ @param info: The info string of the error or None if no it shouldn't be
+ checked.
+ @type info: str or None
+ @param callable_obj: The object that will be tested. If None it returns
+ a context manager like L{assertRaises}.
+ @type callable_obj: callable
+ @param args: The positional arguments forwarded to the callable object.
+ @param kwargs: The keyword arguments forwared to the callable object.
+ @return: The context manager if callable_obj is None and None otherwise.
+ @rtype: None or context manager
+ """
+ msg = kwargs.pop('msg', None)
+ return AssertAPIErrorContextManager(
+ code, info, msg, self).handle(callable_obj, args, kwargs)
+
class TestTimerMixin(TestCaseBase):
diff --git a/tests/upload_tests.py b/tests/upload_tests.py
index a7987d8..7968f01 100644
--- a/tests/upload_tests.py
+++ b/tests/upload_tests.py
@@ -15,8 +15,6 @@
import pywikibot
-from pywikibot.data.api import APIError
-
from tests import join_images_path
from tests.aspects import unittest, TestCase
@@ -103,9 +101,8 @@
self._finish_upload(chunk_size, self.sounds_png)
# Check if it's still cached
- with self.assertRaises(APIError) as cm:
+ with self.assertAPIError('siiinvalidsessiondata') as cm:
self.site.stash_info(self._file_key)
- self.assertEqual(cm.exception.code, 'siiinvalidsessiondata')
self.assertTrue(cm.exception.info.startswith('File not found'),
'info ({0}) did not start with '
'"File not found"'.format(cm.exception.info))
diff --git a/tests/utils.py b/tests/utils.py
index 7cb96d6..6884cb1 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -32,7 +32,7 @@
from pywikibot import config
from pywikibot.comms import threadedhttp
from pywikibot.site import Namespace
-from pywikibot.data.api import CachedRequest
+from pywikibot.data.api import CachedRequest, APIError
from pywikibot.data.api import Request as _original_Request
from pywikibot.tools import (
PYTHON_VERSION,
@@ -244,6 +244,48 @@
return log
+class AssertAPIErrorContextManager(object):
+
+ """
+ Context manager to assert certain APIError exceptions.
+
+ This is build similar to the L{unittest.TestCase.assertError} implementation
+ which creates an context manager. It then calls L{handle} which either
+ returns this manager if no executing object given or calls the callable
+ object.
+ """
+
+ def __init__(self, code, info, msg, test_case):
+ """Create instance expecting the code and info."""
+ self.code = code
+ self.info = info
+ self.msg = msg
+ self.test_case = test_case
+
+ def __enter__(self):
+ """Enter this context manager and the unittest's context manager."""
+ self.cm = self.test_case.assertRaises(APIError, msg=self.msg)
+ self.cm.__enter__()
+ return self.cm
+
+ def __exit__(self, exc_type, exc_value, tb):
+ """Exit the context manager and assert code and optionally info."""
+ result = self.cm.__exit__(exc_type, exc_value, tb)
+ assert result is isinstance(exc_value, APIError)
+ if result:
+ self.test_case.assertEqual(exc_value.code, self.code)
+ if self.info:
+ self.test_case.assertEqual(exc_value.info, self.info)
+ return result
+
+ def handle(self, callable_obj, args, kwargs):
+ """Handle the callable object by returning itself or using itself."""
+ if callable_obj is None:
+ return self
+ with self:
+ callable_obj(*args, **kwargs)
+
+
class DryParamInfo(dict):
"""Dummy class to use instead of L{pywikibot.data.api.ParamInfo}."""
--
To view, visit https://gerrit.wikimedia.org/r/239683
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib211974ec3acd17fb45c2280e084723257a88650
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [i18n] use twn translations
......................................................................
[i18n] use twn translations
self.comment is used without fallback because it contains L10N parts.
Fallback may be enabled when a -summary option is provided or settings
could be retrieved from a local wiki page.
Change-Id: Ic1c69d6531f810560ba930af52db73bfe8c4acaa
---
M scripts/checkimages.py
1 file changed, 5 insertions(+), 38 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 4ab4405..e7c5cbc 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -155,25 +155,6 @@
'zh': [u'{{no source', u'{{unknown', u'{{No license'],
}
-# Summary for when the will add the no source
-msg_comm = {
- 'ar': u'بوت: التعليم على ملف مرفوع حديثا غير موسوم',
- 'commons': u'Bot: Marking newly uploaded untagged file',
- 'de': u'Bot: Markiere mit {{[[Wikipedia:Dateiüberprüfung/Anleitung|DÜP]]}},'
- u' da keine Lizenzvorlage gefunden — bitte nicht entfernen,'
- u' Informationen bald auf der Benutzerdiskussion des Uploaders.',
- 'en': u'Bot: Marking newly uploaded untagged file',
- 'fa': u'ربات: حق تکثیر تصویر تازه بارگذاری شده نامعلوم است.',
- 'ga': u'Róbó: Ag márcáil comhad nua-uaslódáilte gan ceadúnas',
- 'hu': u'Robot: Frissen feltöltött licencsablon nélküli fájl megjelölése',
- 'it': u"Bot: Aggiungo unverified",
- 'ja': u'ロボットによる:著作権情報なしの画像をタグ',
- 'ko': u'로봇:라이선스 없음',
- 'ta': u'தானியங்கி:காப்புரிமை வழங்கப்படா படிமத்தை சுட்டுதல்',
- 'ur': u'روبالہ:نشان زدگی جدید زبراثقال شدہ املاف',
- 'zh': u'機器人:標示新上傳且未包含必要資訊的檔案',
-}
-
# When the Bot find that the usertalk is empty is not pretty to put only the
# no source without the welcome, isn't it?
empty = {
@@ -192,23 +173,6 @@
'ta': u'{{welcome}}\n~~~~\n',
'ur': u'{{خوش آمدید}}\n~~~~\n',
'zh': u'{{subst:welcome|sign=~~~~}}',
-}
-
-# Summary that the bot use when it notify the problem with the image's license
-msg_comm2 = {
- 'ar': u'بوت: طلب معلومات المصدر.',
- 'commons': u'Bot: Requesting source information.',
- 'de': u'Bot: Benachrichtigung über Lizenzprobleme',
- 'en': u'Robot: Requesting source information.',
- 'fa': u'ربات: درخواست منبع تصویر',
- 'ga': u'Róbó: Ag iarraidh eolais foinse.',
- 'it': u"Bot: Notifico l'unverified",
- 'hu': u'Robot: Forrásinformáció kérése',
- 'ja': u'ロボットによる:著作権情報明記のお願い',
- 'ko': u'로봇:라이선스 정보 요청',
- 'ta': u'தானியங்கி:மூலம் வழங்கப்படா படிமத்தை சுட்டுதல்',
- 'ur': u'روبالہ:درخواست ماخذ تصویر',
- 'zh': u'機器人:告知用戶',
}
# if the file has an unknown extension it will be tagged with this template.
@@ -618,7 +582,9 @@
for tmp in hiddentemplatesRaw])
self.pageHidden = i18n.translate(self.site, PageWithHiddenTemplates)
self.pageAllowed = i18n.translate(self.site, PageWithAllowedTemplates)
- self.comment = i18n.translate(self.site, msg_comm, fallback=True)
+ self.comment = i18n.twtranslate(self.site,
+ 'checkimages-source-tag-comment',
+ fallback=False)
# Adding the bot's nickname at the notification text if needed.
self.bots = i18n.translate(self.site, bot_list)
if self.bots:
@@ -774,7 +740,8 @@
def put_mex_in_talk(self):
"""Function to put the warning in talk page of the uploader."""
- commento2 = i18n.translate(self.site, msg_comm2, fallback=True)
+ commento2 = i18n.twtranslate(self.site,
+ 'checkimages-source-notice-comment')
emailPageName = i18n.translate(self.site, emailPageWithText)
emailSubj = i18n.translate(self.site, emailSubject)
if self.notification2:
--
To view, visit https://gerrit.wikimedia.org/r/239664
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic1c69d6531f810560ba930af52db73bfe8c4acaa
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Optimize/remove unneeded calls to Page.isEmpty()
......................................................................
[IMPROV] Optimize/remove unneeded calls to Page.isEmpty()
A check for Page.isEmpty() is unnecessary as it will never be checked when it
would yield True.
A sequence of conditions was also optimized (quicker condition check first)
when replacing links.
Change-Id: Ib68446a77f52f59440d9f50fef416b9bfdb39827
---
M scripts/interwiki.py
1 file changed, 1 insertion(+), 9 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 9854bc6..f1b314a 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1446,14 +1446,6 @@
pywikibot.output(u'File autonomous_problems.dat open or corrupted! Try again with -restore.')
sys.exit()
iw = ()
- elif not page.isCategory() and page.isEmpty():
- globalvar.remove.append(unicode(page))
- if not globalvar.quiet:
- pywikibot.output(u"NOTE: %s is empty; ignoring it and its interwiki links"
- % page)
- # Ignore the interwiki links
- self.done.remove(page)
- iw = ()
for link in iw:
linkedPage = pywikibot.Page(link)
@@ -1834,7 +1826,7 @@
except pywikibot.NoPage:
pywikibot.output(u"Not editing %s: page does not exist" % page)
raise SaveError(u'Page doesn\'t exist')
- if page.isEmpty() and not page.isCategory():
+ if not page.isCategory() and page.isEmpty():
pywikibot.output(u"Not editing %s: page is empty" % page)
raise SaveError(u'Page is empty.')
--
To view, visit https://gerrit.wikimedia.org/r/243506
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib68446a77f52f59440d9f50fef416b9bfdb39827
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Malafaya <malafaya(a)clix.pt>
Gerrit-Reviewer: jenkins-bot <>