jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/540853 )
Change subject: [IMPR] Improvements for askForHints (2)
......................................................................
[IMPR] Improvements for askForHints (2)
- decrease nested code
Change-Id: I0380a8c3342e9672da86e372c9ab985b886fc84d
---
M scripts/interwiki.py
1 file changed, 28 insertions(+), 28 deletions(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 35da344..36bcc7f 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1178,35 +1178,35 @@
and not self.originPage.isCategoryRedirect()):
self.hintsAsked = True
- if self.conf.untranslated:
- t = self.conf.showtextlink
- if t:
- pywikibot.output(self.originPage.get()[:t])
+ if not self.conf.untranslated:
+ return
- while True:
- newhint = pywikibot.input(
- 'Give a hint (? to see pagetext):')
- if not newhint:
- break
- if newhint == '?':
- t += self.conf.showtextlinkadd
- pywikibot.output(self.originPage.get()[:t])
- elif ':' not in newhint:
- pywikibot.output(fill(
- 'Please enter a hint in the format '
- 'language:pagename or type nothing if you do not '
- 'have a hint.'))
- else:
- links = titletranslate.translate(
- self.originPage,
- hints=[newhint],
- auto=self.conf.auto,
- removebrackets=self.conf.hintnobracket)
- for link in links:
- page = pywikibot.Page(link)
- self.addIfNew(page, counter, None)
- if self.conf.hintsareright:
- self.hintedsites.add(page.site)
+ t = self.conf.showtextlink
+ if t:
+ pywikibot.output(self.originPage.get()[:t])
+
+ while True:
+ newhint = pywikibot.input('Give a hint (? to see pagetext):')
+ if not newhint:
+ break
+ if newhint == '?':
+ t += self.conf.showtextlinkadd
+ pywikibot.output(self.originPage.get()[:t])
+ elif ':' not in newhint:
+ pywikibot.output(fill(
+ 'Please enter a hint in the format language:pagename '
+ 'or type nothing if you do not have a hint.'))
+ else:
+ links = titletranslate.translate(
+ self.originPage,
+ hints=[newhint],
+ auto=self.conf.auto,
+ removebrackets=self.conf.hintnobracket)
+ for link in links:
+ page = pywikibot.Page(link)
+ self.addIfNew(page, counter, None)
+ if self.conf.hintsareright:
+ self.hintedsites.add(page.site)
def batchLoaded(self, counter):
"""
--
To view, visit https://gerrit.wikimedia.org/r/540853
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: I0380a8c3342e9672da86e372c9ab985b886fc84d
Gerrit-Change-Number: 540853
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/539068 )
Change subject: [tests] Use assert_valid_iter_params for Site.blocks()
......................................................................
[tests] Use assert_valid_iter_params for Site.blocks()
- assert_valid_iter_params is able to compare Timestamps as well as strings
Use this as default validation for start/end parameters
- Use subTest for all tests inside test_blocks
- use variables for some often reused values
- reorder some tests
Bug: T233779
Change-Id: I9428ee2dc3e944bace3696674db890becdf50731
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 69 insertions(+), 76 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index d1b6518..26c53fb 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -4562,16 +4562,8 @@
@type total: int
"""
if starttime and endtime:
- if reverse:
- if starttime > endtime:
- raise Error(
- 'blocks: '
- 'starttime must be before endtime with reverse=True')
- else:
- if endtime > starttime:
- raise Error(
- 'blocks: '
- 'endtime must be before starttime with reverse=False')
+ self.assert_valid_iter_params('blocks', starttime, endtime,
+ reverse)
bkgen = self._generator(api.ListGenerator, type_arg='blocks',
total=total)
bkgen.request['bkprop'] = ['id', 'user', 'by', 'timestamp', 'expiry',
diff --git a/tests/site_tests.py b/tests/site_tests.py
index c55d232..306ea27 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -888,76 +888,77 @@
"""Test the site.blocks() method."""
mysite = self.get_site()
props = ('id', 'by', 'timestamp', 'expiry', 'reason')
- bl = list(mysite.blocks(total=10))
- self.assertLessEqual(len(bl), 10)
- for block in bl:
- self.assertIsInstance(block, dict)
- for prop in props:
- self.assertIn(prop, block)
- # timestamps should be in descending order
- timestamps = [block['timestamp'] for block in bl]
- for t in range(1, len(timestamps)):
- self.assertLessEqual(timestamps[t], timestamps[t - 1])
- b2 = list(mysite.blocks(total=10, reverse=True))
- self.assertLessEqual(len(b2), 10)
- for block in b2:
- self.assertIsInstance(block, dict)
- for prop in props:
- self.assertIn(prop, block)
- # timestamps should be in ascending order
- timestamps = [block['timestamp'] for block in b2]
- for t in range(1, len(timestamps)):
- self.assertGreaterEqual(timestamps[t], timestamps[t - 1])
+ with self.subTest(total=10, reverse=False):
+ bl = list(mysite.blocks(total=10))
+ self.assertLessEqual(len(bl), 10)
+ for block in bl:
+ self.assertIsInstance(block, dict)
+ for prop in props:
+ self.assertIn(prop, block)
- for block in mysite.blocks(
- starttime=pywikibot.Timestamp.fromISOformat(
- '2008-07-01T00:00:01Z'),
- total=5):
- self.assertIsInstance(block, dict)
- for prop in props:
- self.assertIn(prop, block)
- for block in mysite.blocks(
- endtime=pywikibot.Timestamp.fromISOformat(
- '2008-07-31T23:59:59Z'),
- total=5):
- self.assertIsInstance(block, dict)
- for prop in props:
- self.assertIn(prop, block)
- for block in mysite.blocks(
- starttime=pywikibot.Timestamp.fromISOformat(
- '2008-08-02T00:00:01Z'),
- endtime=pywikibot.Timestamp.fromISOformat(
- '2008-08-02T23:59:59Z'),
- reverse=True, total=5):
- self.assertIsInstance(block, dict)
- for prop in props:
- self.assertIn(prop, block)
- for block in mysite.blocks(
- starttime=pywikibot.Timestamp.fromISOformat(
- '2008-08-03T23:59:59Z'),
- endtime=pywikibot.Timestamp.fromISOformat(
- '2008-08-03T00:00:01Z'),
- total=5):
- self.assertIsInstance(block, dict)
- for prop in props:
- self.assertIn(prop, block)
+ # timestamps should be in descending order
+ timestamps = [block['timestamp'] for block in bl]
+ for t in range(1, len(timestamps)):
+ self.assertLessEqual(timestamps[t], timestamps[t - 1])
+
+ with self.subTest(total=10, reverse=True):
+ b2 = list(mysite.blocks(total=10, reverse=True))
+ self.assertLessEqual(len(b2), 10)
+
+ for block in b2:
+ self.assertIsInstance(block, dict)
+ for prop in props:
+ self.assertIn(prop, block)
+
+ # timestamps should be in ascending order
+ timestamps = [block['timestamp'] for block in b2]
+ for t in range(1, len(timestamps)):
+ self.assertGreaterEqual(timestamps[t], timestamps[t - 1])
+
+ ip = '80.100.22.71'
+ with self.subTest(users=ip):
+ for block in mysite.blocks(users=ip, total=5):
+ self.assertIsInstance(block, dict)
+ self.assertEqual(block['user'], ip)
+
+ low = pywikibot.Timestamp.fromISOformat('2008-08-03T00:00:01Z')
+ high = pywikibot.Timestamp.fromISOformat('2008-08-03T23:59:59Z')
+
+ with self.subTest(starttime=low):
+ for block in mysite.blocks(starttime=low, total=5):
+ self.assertIsInstance(block, dict)
+ for prop in props:
+ self.assertIn(prop, block)
+
+ with self.subTest(endtime=high):
+ for block in mysite.blocks(endtime=high, total=5):
+ self.assertIsInstance(block, dict)
+ for prop in props:
+ self.assertIn(prop, block)
+
+ with self.subTest(starttime=high, endtime=low, reverse=False):
+ for block in mysite.blocks(starttime=high, endtime=low, total=5):
+ self.assertIsInstance(block, dict)
+ for prop in props:
+ self.assertIn(prop, block)
+
+ with self.subTest(starttime=low, endtime=high, reverse=True):
+ for block in mysite.blocks(starttime=low, endtime=high,
+ reverse=True, total=5):
+ self.assertIsInstance(block, dict)
+ for prop in props:
+ self.assertIn(prop, block)
+
# starttime earlier than endtime
- self.assertRaises(AssertionError, mysite.blocks, total=5,
- starttime=pywikibot.Timestamp.fromISOformat(
- '2008-08-03T00:00:01Z'),
- endtime=pywikibot.Timestamp.fromISOformat(
- '2008-08-03T23:59:59Z'))
+ with self.subTest(starttime=low, endtime=high, reverse=False):
+ self.assertRaises(AssertionError, mysite.blocks, total=5,
+ starttime=low, endtime=high)
+
# reverse: endtime earlier than starttime
- self.assertRaises(AssertionError, mysite.blocks,
- starttime=pywikibot.Timestamp.fromISOformat(
- '2008-08-03T23:59:59Z'),
- endtime=pywikibot.Timestamp.fromISOformat(
- '2008-08-03T00:00:01Z'),
- reverse=True, total=5)
- for block in mysite.blocks(users='80.100.22.71', total=5):
- self.assertIsInstance(block, dict)
- self.assertEqual(block['user'], '80.100.22.71')
+ with self.subTest(starttime=high, endtime=low, reverse=True):
+ self.assertRaises(AssertionError, mysite.blocks, total=5,
+ starttime=high, endtime=low, reverse=True)
def test_exturl_usage(self):
"""Test the site.exturlusage() method."""
--
To view, visit https://gerrit.wikimedia.org/r/539068
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: I9428ee2dc3e944bace3696674db890becdf50731
Gerrit-Change-Number: 539068
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
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/540845 )
Change subject: [bugfix] combine two dictionaries
......................................................................
[bugfix] combine two dictionaries
Use itertools.chain to combine mapLat and mapLcl dicts.
First combine these dicts to ignore duplicates in mapLcl.
Note: itertools.chain is necessary for Python 2 compatibility.
Bug: T234146
Change-Id: I2e3ac75d036e2c86a3472f21b50a5db1e14e28d3
---
M scripts/casechecker.py
1 file changed, 3 insertions(+), 4 deletions(-)
Approvals:
D3r1ck01: Looks good to me, but someone else must approve
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/casechecker.py b/scripts/casechecker.py
index 3ee06ff..c666f10 100755
--- a/scripts/casechecker.py
+++ b/scripts/casechecker.py
@@ -9,7 +9,7 @@
from __future__ import absolute_import, division, unicode_literals
import codecs
-import itertools
+from itertools import chain, combinations
import os
import re
from string import ascii_letters
@@ -547,7 +547,7 @@
else:
# Replace all unambiguous bad words
- for k, v in mapLat.items() + mapLcl.items():
+ for k, v in dict(chain(mapLat.items(), mapLcl.items())).items():
if k not in ambigBadWords:
title = title.replace(k, v)
if len(ambigBadWords) == 0:
@@ -561,8 +561,7 @@
# latin character.
for itemCntToPick in range(len(ambigBadWords) + 1):
title2 = title
- for uc in itertools.combinations(list(ambigBadWords),
- itemCntToPick):
+ for uc in combinations(list(ambigBadWords), itemCntToPick):
wordsToLat = ambigBadWords.copy()
for bw in uc:
title2 = title2.replace(bw, mapLcl[bw])
--
To view, visit https://gerrit.wikimedia.org/r/540845
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: I2e3ac75d036e2c86a3472f21b50a5db1e14e28d3
Gerrit-Change-Number: 540845
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/540852 )
Change subject: [IMPR] Improvements for askForHints (1)
......................................................................
[IMPR] Improvements for askForHints (1)
- separate checkings each in one line
- reorder checks in while statement
- use fill for long message to prevent ugly line break
Change-Id: I08e5fa8bad281050bc53c73131d83a10c77fe928
---
M scripts/interwiki.py
1 file changed, 16 insertions(+), 13 deletions(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index c3ac569..35da344 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -355,6 +355,7 @@
import shelve
import socket
import sys
+from textwrap import fill
import pywikibot
@@ -1166,33 +1167,35 @@
def askForHints(self, counter):
"""Ask for hints to other sites."""
- if not self.workonme:
- # Do not ask hints for pages that we don't work on anyway
+ if not self.workonme: # we don't work on it anyway
return
- if (self.untranslated or self.conf.askhints) and not self.hintsAsked \
- and self.originPage and self.originPage.exists() \
- and not self.originPage.isRedirectPage() and \
- not self.originPage.isCategoryRedirect():
- # Only once!
+
+ if ((self.untranslated or self.conf.askhints)
+ and not self.hintsAsked
+ and self.originPage
+ and self.originPage.exists()
+ and not self.originPage.isRedirectPage()
+ and not self.originPage.isCategoryRedirect()):
+
self.hintsAsked = True
if self.conf.untranslated:
t = self.conf.showtextlink
if t:
pywikibot.output(self.originPage.get()[:t])
- # loop
+
while True:
newhint = pywikibot.input(
'Give a hint (? to see pagetext):')
+ if not newhint:
+ break
if newhint == '?':
t += self.conf.showtextlinkadd
pywikibot.output(self.originPage.get()[:t])
- elif newhint and ':' not in newhint:
- pywikibot.output(
+ elif ':' not in newhint:
+ pywikibot.output(fill(
'Please enter a hint in the format '
'language:pagename or type nothing if you do not '
- 'have a hint.')
- elif not newhint:
- break
+ 'have a hint.'))
else:
links = titletranslate.translate(
self.originPage,
--
To view, visit https://gerrit.wikimedia.org/r/540852
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: I08e5fa8bad281050bc53c73131d83a10c77fe928
Gerrit-Change-Number: 540852
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: jenkins-bot (75)