jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/511463 )
Change subject: [TEST] fix test_create_short_link
......................................................................
[TEST] fix test_create_short_link
Bug: T223865
Change-Id: Ib980e88bf0dec0ce16ecc7ce42a5110a508bc3aa
---
M pywikibot/page.py
M tests/page_tests.py
2 files changed, 13 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 062ec9d..7cc9f3f 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -66,6 +66,8 @@
from urllib import quote as quote_from_bytes, unquote as unquote_to_bytes
+PROTOCOL_REGEX = r'\Ahttps?://'
+
__all__ = (
'BasePage',
'Page',
@@ -2218,7 +2220,7 @@
"""
return self.content_model == 'flow-board'
- def create_short_link(self, permalink=False, with_protocol=False):
+ def create_short_link(self, permalink=False, with_protocol=True):
"""
Return a shortened link that points to that page.
@@ -2228,8 +2230,9 @@
@param permalink: If true, the link will point to the actual revision
of the page.
@type permalink: bool
- @param with_protocol: If true, the link will have https propotol
- prepend.
+ @param with_protocol: If true, and if it's not already included,
+ the link will have http(s) protocol prepended. On Wikimedia wikis
+ the protocol is already present.
@type with_protocol: bool
@return: The reduced link.
@rtype: str
@@ -2241,7 +2244,10 @@
url = self.permalink() if permalink else self.full_url()
link = wiki.create_short_link(url)
- if with_protocol:
+ if re.match(PROTOCOL_REGEX, link):
+ if not with_protocol:
+ return re.sub(PROTOCOL_REGEX, '', link)
+ elif with_protocol:
return '{}://{}'.format(wiki.protocol(), link)
return link
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 55ce2fe..7aa8008 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1186,12 +1186,13 @@
site = self.get_site()
p1 = pywikibot.Page(site, 'User:Framawiki/pwb_tests/shortlink')
with self.subTest(parameters='defaulted'):
- self.assertEqual(p1.create_short_link(), 'w.wiki/3Cy')
+ self.assertEqual(p1.create_short_link(), 'https://w.wiki/3Cy')
with self.subTest(with_protocol=True):
self.assertEqual(p1.create_short_link(with_protocol=True),
'https://w.wiki/3Cy')
with self.subTest(permalink=True):
- self.assertEqual(p1.create_short_link(permalink=True),
+ self.assertEqual(p1.create_short_link(permalink=True,
+ with_protocol=False),
'w.wiki/3Cz')
--
To view, visit https://gerrit.wikimedia.org/r/511463
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib980e88bf0dec0ce16ecc7ce42a5110a508bc3aa
Gerrit-Change-Number: 511463
Gerrit-PatchSet: 5
Gerrit-Owner: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Lokal Profil <andre.costa(a)wikimedia.se>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/512116 )
Change subject: [cleanup] use "any" function instead of sequence of "or" statements
......................................................................
[cleanup] use "any" function instead of sequence of "or" statements
Reduce code complexity from E32 to D26 in getCombinedGenerator
(reported from codeclimate.com)
Change-Id: I386e9ab3c2126d80d457053247368cf5226b6b23
---
M pywikibot/pagegenerators.py
1 file changed, 15 insertions(+), 16 deletions(-)
Approvals:
Lokal Profil: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index ea2ae8e..2cd467c 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -526,17 +526,18 @@
self.gens[i].set_maximum_items(self.limit)
except AttributeError:
self.gens[i] = itertools.islice(self.gens[i], self.limit)
- if len(self.gens) == 0:
- if (self.titlefilter_list
- or self.titlenotfilter_list
- or self.articlefilter_list
- or self.claimfilter_list
- or self.catfilter_list
- or self.subpage_max_depth is not None
- or self.qualityfilter_list):
- pywikibot.warning(
- 'filter(s) specified but no generators.')
+
+ if not self.gens:
+ if any((self.titlefilter_list,
+ self.titlenotfilter_list,
+ self.articlefilter_list,
+ self.claimfilter_list,
+ self.catfilter_list,
+ self.qualityfilter_list,
+ self.subpage_max_depth is not None)):
+ pywikibot.warning('filter(s) specified but no generators.')
return None
+
elif len(self.gens) == 1:
dupfiltergen = self.gens[0]
if hasattr(self, '_single_gen_filter_unique'):
@@ -544,13 +545,11 @@
if self.intersect:
pywikibot.warning(
'"-intersect" ignored as only one generator is specified.')
+ elif self.intersect:
+ # By definition no duplicates are possible.
+ dupfiltergen = intersect_generators(self.gens)
else:
- if self.intersect:
- # By definition no duplicates are possible.
- dupfiltergen = intersect_generators(self.gens)
- else:
- dupfiltergen = _filter_unique_pages(itertools.chain(
- *self.gens))
+ dupfiltergen = _filter_unique_pages(itertools.chain(*self.gens))
# Add on subpage filter generator
if self.subpage_max_depth is not None:
--
To view, visit https://gerrit.wikimedia.org/r/512116
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I386e9ab3c2126d80d457053247368cf5226b6b23
Gerrit-Change-Number: 512116
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/512134 )
Change subject: [tests] use subTest with l10n_tests.TestSites
......................................................................
[tests] use subTest with l10n_tests.TestSites
Change-Id: If8565af684434d0a48f9aa1187739491f0d1e80a
---
M tests/l10n_tests.py
1 file changed, 4 insertions(+), 3 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py
index 2b86318..f461ee3 100644
--- a/tests/l10n_tests.py
+++ b/tests/l10n_tests.py
@@ -107,9 +107,10 @@
for package in PACKAGES:
keys = i18n.twget_keys(package)
for key in keys:
- self.assertIn(key, languages,
- "'{}' - json key '{}' is not a site language"
- .format(package, key))
+ with self.subTest(package=package, key=key):
+ self.assertIn(key, languages,
+ "'{}' - json key '{}' is not a site language"
+ .format(package, key))
def setUpModule(): # noqa: N802
--
To view, visit https://gerrit.wikimedia.org/r/512134
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: If8565af684434d0a48f9aa1187739491f0d1e80a
Gerrit-Change-Number: 512134
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/512110 )
Change subject: [cleanup] remove # TODO because it was done already
......................................................................
[cleanup] remove # TODO because it was done already
logtype is checked in _handle_logevents() already
Change-Id: I40e9416e094c1f1c31d2ef6f84633360ef498e88
---
M pywikibot/pagegenerators.py
1 file changed, 1 insertion(+), 4 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index ea2ae8e..53110f9 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -670,11 +670,8 @@
@return: The generator or None if invalid 'total' value.
@rtype: LogeventsPageGenerator
"""
- # TODO: Check if logtype is one of the allowed log types
-
- # 'start or None', because start might be an empty string
total = None
- start = start or None
+ start = start or None # because start might be an empty string
if isinstance(start, UnicodeType) and len(start) == 8:
start = pywikibot.Timestamp.strptime(start, '%Y%m%d')
elif start is not None:
--
To view, visit https://gerrit.wikimedia.org/r/512110
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I40e9416e094c1f1c31d2ef6f84633360ef498e88
Gerrit-Change-Number: 512110
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/512107 )
Change subject: [cleanup] Simplify range checking in proofreadpage.py
......................................................................
[cleanup] Simplify range checking in proofreadpage.py
Change-Id: I3cc966b44222aa2b48475b0980d6b35ceda2a2fc
---
M pywikibot/proofreadpage.py
1 file changed, 1 insertion(+), 3 deletions(-)
Approvals:
Lokal Profil: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index d05f932..4a72548 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -953,9 +953,7 @@
if end is None:
end = self.num_pages
- if not ((1 <= start <= self.num_pages)
- and (1 <= end <= self.num_pages)
- and (start <= end)):
+ if not (1 <= start <= end <= self.num_pages):
raise ValueError('start=%s, end=%s are not in valid range (%s, %s)'
% (start, end, 1, self.num_pages))
--
To view, visit https://gerrit.wikimedia.org/r/512107
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3cc966b44222aa2b48475b0980d6b35ceda2a2fc
Gerrit-Change-Number: 512107
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: jenkins-bot (75)