jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/270577 )
Change subject: [IMPR] Provide a private user script path to be used by pwb.py
......................................................................
[IMPR] Provide a private user script path to be used by pwb.py
- A privat script path must be located inside the framework folder.
The user_script_path will searched first.
- Print a UserWaring when user_script_path is not a list or not a tuple
- generate_user_files.py may copy this setting part to user-config
Change-Id: I3191a91b32c15cb69b77e3d0c9ccfd402cc3f948
---
M generate_user_files.py
M pwb.py
M pywikibot/config2.py
3 files changed, 28 insertions(+), 3 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index 8e59c8b..3343985 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Script to create user-config.py."""
#
-# (C) Pywikibot team, 2010-2015
+# (C) Pywikibot team, 2010-2016
#
# Distributed under the terms of the MIT license.
#
@@ -255,6 +255,7 @@
res = re.findall("^(# ############# (?:"
"LOGFILE|"
+ 'EXTERNAL SCRIPT PATH|'
"INTERWIKI|"
"SOLVE_DISAMBIGUATION|"
"IMAGE RELATED|"
diff --git a/pwb.py b/pwb.py
index 96de789..dc015b7 100755
--- a/pwb.py
+++ b/pwb.py
@@ -9,7 +9,7 @@
and it will use the package directory to store all user files, will fix up
search paths so the package does not need to be installed, etc.
"""
-# (C) Pywikibot team, 2015
+# (C) Pywikibot team, 2015-2016
#
# Distributed under the terms of the MIT license.
#
@@ -212,6 +212,14 @@
script_paths = ['scripts',
'scripts.maintenance',
'scripts.archive']
+ from pywikibot import config # flake8: disable=E402
+ if config.user_script_paths:
+ if isinstance(config.user_script_paths, (tuple, list)):
+ script_paths = config.user_script_paths + script_paths
+ else:
+ warn("'user_script_paths' must be a list or tuple,\n"
+ 'found: {0}. Ignoring this setting.'
+ ''.format(type(config.user_script_paths)))
for file_package in script_paths:
paths = file_package.split('.') + [filename]
testpath = os.path.join(_pwb_dir, *paths)
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index a1aa14f..9f4d72e 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -33,7 +33,7 @@
"""
#
# (C) Rob W.W. Hooft, 2003
-# (C) Pywikibot team, 2003-2015
+# (C) Pywikibot team, 2003-2016
#
# Distributed under the terms of the MIT license.
#
@@ -516,6 +516,22 @@
# (overrides log setting above)
debug_log = []
+# ############# EXTERNAL SCRIPT PATH SETTING ##############
+# set your own script path to lookup for your script files.
+# your private script path must be located inside the
+# framework folder, subfolders must be delimited by '.'.
+# every folder must contain an (empty) __init__.py file.
+#
+# The search order is
+# 1. user_script_paths in the given order
+# 2. scripts
+# 3. scripts/maintenance
+# 4. scripts/archive
+#
+# sample:
+# user_script_paths = ['scripts.myscripts']
+user_script_paths = []
+
# ############# INTERWIKI SETTINGS ##############
# Should interwiki.py report warnings for missing links between foreign
--
To view, visit https://gerrit.wikimedia.org/r/270577
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3191a91b32c15cb69b77e3d0c9ccfd402cc3f948
Gerrit-PatchSet: 6
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: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/326313 )
Change subject: site_detect.py: Raise ServerError on 500 response
......................................................................
site_detect.py: Raise ServerError on 500 response
A test for wikichristian.org is occasionally returning 500 error codes and
making travis builds fail.
Raising a ServerError here will make that test skip.
Bug: T151368
Change-Id: I9e0c5d64c28f8d4baf860541ad518c4ae861177d
---
M pywikibot/site_detect.py
1 file changed, 2 insertions(+), 0 deletions(-)
Approvals:
Magul: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py
index cc69e4b..4eb78d7 100644
--- a/pywikibot/site_detect.py
+++ b/pywikibot/site_detect.py
@@ -54,6 +54,8 @@
r = fetch(fromurl)
if r.status == 503:
raise ServerError('Service Unavailable')
+ elif r.status == 500:
+ raise ServerError('Internal Server Error')
if fromurl != r.data.url:
pywikibot.log('{0} redirected to {1}'.format(fromurl, r.data.url))
--
To view, visit https://gerrit.wikimedia.org/r/326313
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e0c5d64c28f8d4baf860541ad518c4ae861177d
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/324150 )
Change subject: Remove compat stuff "via API" from user messages
......................................................................
Remove compat stuff "via API" from user messages
- all pages are retrieved via API in core. It is not necessary to show that.
This was a relic from compat which had a screen scraping variant.
Change-Id: I63e236390ac83221fe6e1b61bcd67ab9bdb8caf1
---
M scripts/redirect.py
M scripts/watchlist.py
2 files changed, 4 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Sn1per: Looks good to me, approved
diff --git a/scripts/redirect.py b/scripts/redirect.py
index abe9b34..2c9fadb 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -342,9 +342,9 @@
datetime.timedelta(0, self.offset * 3600))
# self.offset hours ago
offset_time = start.strftime("%Y%m%d%H%M%S")
- pywikibot.output(u'Retrieving %s moved pages via API...'
- % (str(self.api_number)
- if self.api_number is not None else "all"))
+ pywikibot.output('Retrieving {0} moved pages...'
+ ''.format(str(self.api_number)
+ if self.api_number is not None else 'all'))
move_gen = self.site.logevents(logtype="move", start=offset_time)
if self.api_number:
move_gen.set_maximum_items(self.api_number)
diff --git a/scripts/watchlist.py b/scripts/watchlist.py
index 316ed70..931a6be 100755
--- a/scripts/watchlist.py
+++ b/scripts/watchlist.py
@@ -53,7 +53,7 @@
def refresh(site, sysop=False):
"""Fetch the watchlist."""
- pywikibot.output(u'Retrieving watchlist for %s via API.' % str(site))
+ pywikibot.output('Retrieving watchlist for {0}.'.format(str(site)))
return list(site.watched_pages(sysop=sysop, force=True))
--
To view, visit https://gerrit.wikimedia.org/r/324150
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I63e236390ac83221fe6e1b61bcd67ab9bdb8caf1
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Sn1per <geofbot(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/326245 )
Change subject: Document test decorators.
......................................................................
Document test decorators.
Documentation regarding mock.patch, tests.aspects.require_modules,
unittest.skipIf and unittest.skipUnless is added to the README file.
Bug: T152068
Change-Id: I335323a1704a9912dbc39bcec8042ae8ee706234
---
M tests/README.rst
1 file changed, 62 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/README.rst b/tests/README.rst
index fff848f..90f88db 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -226,6 +226,68 @@
Enabling only 'edit failure' tests or 'write' tests won't enable the other tests
automatically.
+Decorators
+=====================
+
+pywikibot's test suite, including Python's unittest module, provides decorators
+to modify the behaviour of the test cases.
+
+(a)unittest.skipIf
+-----------------
+Skip a test if the condition is true. Refer to unittest's documentation.
+
+::
+
+ import unittest
+ [......]
+ @unittest.skipIf(check_if_fatal(), 'Something is not okay.')
+ def test_skipIf(self):
+
+(a)unittest.skipUnless
+---------------------
+Skip a test unless the condition is true. Refer to unittest's documentation.
+
+::
+
+ import unittest
+ [......]
+ @unittest.skipUnless(check_if_true(), 'Something must happen.')
+ def test_skipUnless(self):
+
+(a)tests.aspects.require_modules
+-------------------------------
+Require that the given list of modules can be imported.
+
+::
+
+ from tests.aspects import require_modules
+ [......]
+ @require_modules(['important1', 'musthave2'])
+ def test_require_modules(self):
+
+(a)(unittest.)mock.patch
+-----------------------
+Replaces `target` with object specified in `new`. Refer to mock's documentation.
+This is especially useful in tests, where requests to third-parties should be
+avoided.
+
+In Python 3, this is part of the built-in unittest module.
+
+::
+
+ if sys.version_info[0] > 2:
+ from unittest.mock import patch
+ else:
+ from mock import patch
+
+
+ def fake_ping(url):
+ return 'pong'
+ [......]
+ @patch('http_ping', side_effect=fake_ping)
+ def test_patch(self):
+ self.assertEqual('pong', http_ping())
+
Contributing tests
==================
@@ -293,4 +355,3 @@
- ``user = True`` : test class needs to login to site
- ``sysop = True`` : test class needs to login to site as a sysop
- ``write = True`` : test class needs to write to a site
-
--
To view, visit https://gerrit.wikimedia.org/r/326245
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I335323a1704a9912dbc39bcec8042ae8ee706234
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dargasia <hxiao+scm(a)dargasea.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/323518 )
Change subject: login.py: Support specifying '*' for 'family' in user-config.py
......................................................................
login.py: Support specifying '*' for 'family' in user-config.py
- __init__.py:
- Check the username and sysopname of family '*' if none is found
in the specified family.
- login_tests.py:
- Use "import unittest.mock" instead of "import mock" when available.
(mock has been part of the standard library since python 3.3)
- FakeConfig.usernames should be a defaultdict.
- Add a test for the new funtionality of LoginManager.
Bug: T120334
Change-Id: I23749a4035c7d27186a92e67c6d6206e10326ff0
---
M pywikibot/__init__.py
M pywikibot/config2.py
M pywikibot/login.py
M tests/login_tests.py
4 files changed, 49 insertions(+), 17 deletions(-)
Approvals:
jenkins-bot: Verified
Sn1per: Looks good to me, approved
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 42b93ec..c68fcfe 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -825,13 +825,16 @@
interface = interface or fam.interface(code)
- # config.usernames is initialised with a dict for each family name
+ # config.usernames is initialised with a defaultdict for each family name
family_name = str(fam)
- if family_name in config.usernames:
- user = user or config.usernames[family_name].get(code) \
- or config.usernames[family_name].get('*')
- sysop = sysop or config.sysopnames[family_name].get(code) \
- or config.sysopnames[family_name].get('*')
+
+ code_to_user = config.usernames['*'].copy()
+ code_to_user.update(config.usernames[family_name])
+ user = user or code_to_user.get(code) or code_to_user.get('*')
+
+ code_to_sysop = config.sysopnames['*'].copy()
+ code_to_sysop.update(config.sysopnames[family_name])
+ sysop = sysop or code_to_sysop.get(code) or code_to_sysop.get('*')
if not isinstance(interface, type):
# If it isnt a class, assume it is a string
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 9451eb5..e1ab7dc 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -116,6 +116,7 @@
# If you have a unique username for all languages of a family,
# you can use '*'
# usernames['wikibooks']['*'] = 'mySingleUsername'
+# You may use '*' for family name in a similar manner.
#
# If you have a sysop account on some wikis, this will be used to delete pages
# or to edit locked pages if you add such lines to your
diff --git a/pywikibot/login.py b/pywikibot/login.py
index e110c47..01ebf6b 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -91,9 +91,12 @@
if user:
self.username = user
elif sysop:
+ config_names = config.sysopnames
+ family_sysopnames = (
+ config_names[self.site.family.name] or config_names['*']
+ )
+ self.username = family_sysopnames.get(self.site.code, None)
try:
- family_sysopnames = config.sysopnames[self.site.family.name]
- self.username = family_sysopnames.get(self.site.code, None)
self.username = self.username or family_sysopnames['*']
except KeyError:
raise NoUsername(u"""\
@@ -104,11 +107,14 @@
% {'fam_name': self.site.family.name,
'wiki_code': self.site.code})
else:
+ config_names = config.usernames
+ family_usernames = (
+ config_names[self.site.family.name] or config_names['*']
+ )
+ self.username = family_usernames.get(self.site.code, None)
try:
- family_usernames = config.usernames[self.site.family.name]
- self.username = family_usernames.get(self.site.code, None)
self.username = self.username or family_usernames['*']
- except:
+ except KeyError:
raise NoUsername(u"""\
ERROR: Username for %(fam_name)s:%(wiki_code)s is undefined.
If you have an account for that site, please add a line to user-config.py:
diff --git a/tests/login_tests.py b/tests/login_tests.py
index 9c63bc3..b40ea7c 100644
--- a/tests/login_tests.py
+++ b/tests/login_tests.py
@@ -13,8 +13,13 @@
__version__ = '$Id$'
#
-import mock
+from collections import defaultdict
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
+from pywikibot.exceptions import NoUsername
from pywikibot.login import LoginManager
from tests.aspects import (
@@ -35,17 +40,15 @@
code = "~FakeCode"
family = FakeFamily
+
FakeUsername = "~FakeUsername"
class FakeConfig(object):
"""Mock."""
- usernames = {
- FakeFamily.name: {
- FakeSite.code: FakeUsername
- }
- }
+ usernames = defaultdict(dict)
+ usernames[FakeFamily.name] = {FakeSite.code: FakeUsername}
@mock.patch("pywikibot.Site", FakeSite)
@@ -62,6 +65,24 @@
self.assertEqual(obj.username, FakeUsername)
self.assertEqual(obj.login_name, FakeUsername)
self.assertIsNone(obj.password)
+
+ @mock.patch.dict(
+ FakeConfig.usernames,
+ {'*': {'*': FakeUsername}},
+ clear=True
+ )
+ def test_star_family(self):
+ """Test LoginManager with '*' as family."""
+ lm = LoginManager()
+ self.assertEqual(lm.username, FakeUsername)
+
+ del FakeConfig.usernames['*']
+ FakeConfig.usernames['*']['en'] = FakeUsername
+ self.assertRaises(NoUsername, LoginManager)
+
+ FakeConfig.usernames['*']['*'] = FakeUsername
+ lm = LoginManager()
+ self.assertEqual(lm.username, FakeUsername)
@mock.patch("pywikibot.Site", FakeSite)
@@ -166,5 +187,6 @@
""", '~FakePassword')
self.assertEqual(obj.login_name, "~FakeUsername@~FakeSuffix")
+
if __name__ == '__main__': # pragma: no cover
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/323518
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I23749a4035c7d27186a92e67c6d6206e10326ff0
Gerrit-PatchSet: 15
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Sn1per <geofbot(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Fix format string
......................................................................
[bugfix] Fix format string
- match.groups() gives a tuple. Passing to a format string gives a
TypeError when the tuple contains more or less elements than 1.
- Use exception message directly and use str.format() method.
Bug: T152499
Change-Id: I3eef158317882f239ef3bc4bd499b31fd5bb25ce
---
M pywikibot/textlib.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
Dalba: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 48ca786..9f7782e 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -403,9 +403,9 @@
replacement += new[last:group_match.start()]
replacement += match.group(group_id) or ''
except IndexError:
- pywikibot.output('\nInvalid group reference: %s' % group_id)
- pywikibot.output('Groups found:\n%s' % match.groups())
- raise IndexError
+ raise IndexError(
+ 'Invalid group reference: {0}\nGroups found: {1}'
+ ''.format(group_id, match.groups()))
last = group_match.end()
replacement += new[last:]
--
To view, visit https://gerrit.wikimedia.org/r/325556
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3eef158317882f239ef3bc4bd499b31fd5bb25ce
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>