jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/459777 )
Change subject: tests/pwb: Put the main body of the scripts in a `if __name__ == '__main__':`
......................................................................
tests/pwb: Put the main body of the scripts in a `if __name__ == '__main__':`
Bug: T204042
Change-Id: Ic4f5bd1d2be4a60598f8ea72b46e183d61491c36
---
M tests/pwb/print_env.py
M tests/pwb/print_locals.py
M tests/pwb/print_unicode.py
3 files changed, 43 insertions(+), 34 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pwb/print_env.py b/tests/pwb/print_env.py
index 72ffd90..1377c14 100644
--- a/tests/pwb/print_env.py
+++ b/tests/pwb/print_env.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Script that forms part of pwb_tests."""
#
-# (C) Pywikibot team, 2015
+# (C) Pywikibot team, 2015-2018
#
# Distributed under the terms of the MIT license.
#
@@ -13,26 +13,33 @@
from pywikibot.tools import first_upper
-_pwb_dir = os.path.abspath(os.path.join(
- os.path.split(__file__)[0], '..', '..'))
-_pwb_dir = first_upper(_pwb_dir)
-print('os.environ:')
-for k, v in sorted(os.environ.items()):
- # Don't leak the password into logs
- if k == 'USER_PASSWORD':
- continue
- # This only appears in subprocesses
- if k == 'PYWIKIBOT_DIR_PWB':
- continue
- print("%r: %r" % (k, v))
+def main():
+ """Print environment variables."""
+ _pwb_dir = os.path.abspath(os.path.join(
+ os.path.split(__file__)[0], '..', '..'))
+ _pwb_dir = first_upper(_pwb_dir)
-print('sys.path:')
-for path in sys.path:
- if path == '' or path.startswith('.'):
- continue
- # Normalise DOS drive letter
- path = first_upper(path)
- if path.startswith(_pwb_dir):
- continue
- print(path)
+ print('os.environ:')
+ for k, v in sorted(os.environ.items()):
+ # Don't leak the password into logs
+ if k == 'USER_PASSWORD':
+ continue
+ # This only appears in subprocesses
+ if k == 'PYWIKIBOT_DIR_PWB':
+ continue
+ print('{}: {}'.format(k, v))
+
+ print('sys.path:')
+ for path in sys.path:
+ if path == '' or path.startswith('.'):
+ continue
+ # Normalise DOS drive letter
+ path = first_upper(path)
+ if path.startswith(_pwb_dir):
+ continue
+ print(path)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/pwb/print_locals.py b/tests/pwb/print_locals.py
index 57951f8..e9d08d4 100644
--- a/tests/pwb/print_locals.py
+++ b/tests/pwb/print_locals.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Script that forms part of pwb_tests."""
#
-# (C) Pywikibot team, 2013-2017
+# (C) Pywikibot team, 2013-2018
#
# Distributed under the terms of the MIT license.
#
@@ -10,11 +10,12 @@
import os.path
-for k, v in sorted(locals().copy().items()):
- # Skip a few items that Python 3 adds and are not emulated in pwb.
- if k in ['__cached__', '__loader__', '__spec__', '__annotations__']:
- continue
- if k == '__file__':
- print("__file__: %r" % os.path.join('.', os.path.relpath(__file__)))
- else:
- print("%r: %r" % (k, v))
+if __name__ == '__main__':
+ for k, v in sorted(locals().copy().items()):
+ # Skip a few items that Python 3 adds and are not emulated in pwb.
+ if k in ['__cached__', '__loader__', '__spec__', '__annotations__']:
+ continue
+ if k == '__file__':
+ print('__file__: ' + os.path.join('.', os.path.relpath(__file__)))
+ else:
+ print('{}: {}'.format(k, v))
diff --git a/tests/pwb/print_unicode.py b/tests/pwb/print_unicode.py
index b8505cd..c02f028 100644
--- a/tests/pwb/print_unicode.py
+++ b/tests/pwb/print_unicode.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Script that forms part of pwb_tests."""
#
-# (C) Pywikibot team, 2015
+# (C) Pywikibot team, 2018
#
# Distributed under the terms of the MIT license.
#
@@ -10,5 +10,6 @@
import pywikibot
-pywikibot.output('Häuser')
-print('Häuser')
+if __name__ == '__main__':
+ pywikibot.output('Häuser')
+ print('Häuser')
--
To view, visit https://gerrit.wikimedia.org/r/459777
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: Ic4f5bd1d2be4a60598f8ea72b46e183d61491c36
Gerrit-Change-Number: 459777
Gerrit-PatchSet: 5
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
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 (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/459772 )
Change subject: page.py: Fix param info in FileInfo.__init__ and get_file_url docstrings
......................................................................
page.py: Fix param info in FileInfo.__init__ and get_file_url docstrings
Fix the param names in get_file_url.
FileInfo did not have any param named `page`.
Change-Id: I8b6a8da4f58a008c2b87af07270da7ae8737967e
---
M pywikibot/page.py
1 file changed, 4 insertions(+), 11 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 126fb95..dd4f49a 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2500,13 +2500,11 @@
Parameters validation and error handling left to the API call.
- @param width: see iiurlwidth in [1]
- @param height: see iiurlheigth in [1]
- @param param: see iiurlparam in [1]
-
+ @param url_width: see iiurlwidth in [1]
+ @param url_height: see iiurlheigth in [1]
+ @param url_param: see iiurlparam in [1]
@return: latest file url or thumburl
@rtype: unicode
-
"""
# Plain url is requested.
if url_width is None and url_height is None and url_param is None:
@@ -5413,12 +5411,7 @@
"""
def __init__(self, file_revision):
- """
- Create class with the dictionary returned by site.loadimageinfo().
-
- @param page: FilePage containing the image.
- @type page: FilePage object
- """
+ """Initiate the class using the dict from L{APISite.loadimageinfo}."""
self.__dict__.update(file_revision)
self.timestamp = pywikibot.Timestamp.fromISOformat(self.timestamp)
--
To view, visit https://gerrit.wikimedia.org/r/459772
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: I8b6a8da4f58a008c2b87af07270da7ae8737967e
Gerrit-Change-Number: 459772
Gerrit-PatchSet: 1
Gerrit-Owner: 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 (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/459400 )
Change subject: [cleanup] notes cleanup
......................................................................
[cleanup] notes cleanup
- move development notes in front of its function in pwb.py
- remove outdatet note in bot.py and move loging mode to _logger string
- remove TODO note in aspects which is T203921 now
Change-Id: I09866ec00a264e9650e0bc43f42b9907923d05e2
---
M pwb.py
M pywikibot/bot.py
M tests/aspects.py
3 files changed, 11 insertions(+), 23 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 371b9e0..b71a78d 100755
--- a/pwb.py
+++ b/pwb.py
@@ -15,13 +15,6 @@
#
from __future__ import absolute_import, print_function, unicode_literals
-# The following snippet was developed by Ned Batchelder (and others)
-# for coverage [1], with python 3 support [2] added later,
-# and is available under the BSD license (see [3])
-# [1] https://bitbucket.org/ned/coveragepy/src/b5abcee50dbe/coverage/execfile.py
-# [2] https://bitbucket.org/ned/coveragepy/src/fd5363090034/coverage/execfile.py
-# [3] https://bitbucket.org/ned/coveragepy/src/2c5fb3a8b81c/setup.py?at=default#c…
-
import os
import sys
import types
@@ -76,6 +69,16 @@
pwb = pywikibot
+# The following snippet was developed by Ned Batchelder (and others)
+# for coverage [1], with python 3 support [2] added later,
+# and is available under the BSD license (see [3])
+# [1]
+# https://bitbucket.org/ned/coveragepy/src/b5abcee50dbe/coverage/execfile.py
+# [2]
+# https://bitbucket.org/ned/coveragepy/src/fd5363090034/coverage/execfile.py
+# [3]
+# https://bitbucket.org/ned/coveragepy/src/2c5fb3a8b81c/setup.py?at=default#c…
+
def run_python_file(filename, argv, argvu, package=None):
"""Run a python file as if it were the main program on the command line.
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index faaad1c..ddeeeb8 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -54,10 +54,6 @@
#
from __future__ import absolute_import, unicode_literals
-# Note: the intention is to develop this module (at some point) into a Bot
-# class definition that can be subclassed to create new, functional bot
-# scripts, instead of writing each one from scratch.
-
__all__ = (
'CRITICAL', 'ERROR', 'INFO', 'WARNING', 'DEBUG', 'INPUT', 'STDOUT',
'VERBOSE', 'critical', 'debug', 'error', 'exception', 'log', 'warning',
@@ -81,7 +77,6 @@
'WikidataBot',
)
-# Note: all output goes thru python std library "logging" module
import codecs
import datetime
@@ -126,6 +121,7 @@
from pywikibot.tools.formatter import color_format
+# Note: all output goes thru python std library "logging" module
_logger = 'bot'
if not PY2:
diff --git a/tests/aspects.py b/tests/aspects.py
index 1d7c9ee..331d633 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -12,17 +12,6 @@
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, print_function, unicode_literals
-# TODO:
-# skip if the user is blocked.
-# sysop flag, implement in site & page, and
-# possibly some of the script tests.
-# slow flag
-# weblib - also slow
-# (this class, and a FastTest, could error/pass based
-# it consumed more than a specified amount of time allowed.)
-# net flag should disable network libraries
-# UITestCase:
-# Not integrated; direct subclass of unittest.TestCase.
import inspect
import itertools
import os
--
To view, visit https://gerrit.wikimedia.org/r/459400
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: I09866ec00a264e9650e0bc43f42b9907923d05e2
Gerrit-Change-Number: 459400
Gerrit-PatchSet: 3
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: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/459370 )
Change subject: SearchTestCase.test_search_where_title: Don't look for the searched word
......................................................................
SearchTestCase.test_search_where_title: Don't look for the searched word
Don't look for the searched word in the results. Matches do not always
contain the exact searched term. See T203886#4569832.
Just test that params are correct and that the results are page objects
from the requested namespace.
pywikibot.site.APISite.search:
Checking for the family is not the best way to learn about the
search engine params. Change the
`isinstance(self.family, WikimediaFamily)` condition to
`self.has_extension('CirrusSearch')` which hopefully is more accurate.
Bug: T203886
Change-Id: I3438eecad5197b1d7a2707fbf1ee10894fd6ead8
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 19 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 8a15511..304dcdc 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -67,7 +67,6 @@
UnknownSite,
UserBlocked,
)
-from pywikibot.family import WikimediaFamily
from pywikibot.throttle import Throttle
from pywikibot.tools import (
compute_file_hash,
@@ -4802,7 +4801,7 @@
if where not in where_types:
raise Error("search: unrecognized 'where' value: %s" % where)
if where in ('title', 'titles'):
- if isinstance(self.family, WikimediaFamily):
+ if self.has_extension('CirrusSearch'):
# 'title' search was disabled, use intitle instead
searchstring = 'intitle:' + searchstring
issue_deprecation_warning(
diff --git a/tests/site_tests.py b/tests/site_tests.py
index ee7b90e..d676b11 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1585,17 +1585,27 @@
@suppress_warnings("where='title' is deprecated", DeprecationWarning)
def test_search_where_title(self):
"""Test site.search() method with 'where' parameter set to title."""
+ search_gen = self.site.search(
+ 'wiki', namespaces=0, total=10, get_redirects=True, where='title')
+ expected_params = {
+ 'prop': ['info', 'imageinfo', 'categoryinfo'],
+ 'inprop': ['protection'],
+ 'iiprop': [
+ 'timestamp', 'user', 'comment', 'url', 'size', 'sha1',
+ 'metadata'],
+ 'iilimit': ['max'], 'generator': ['search'], 'action': ['query'],
+ 'indexpageids': [True], 'continue': [True], 'gsrnamespace': [0]}
+ if self.site.has_extension('CirrusSearch'):
+ expected_params.update({
+ 'gsrsearch': ['intitle:wiki'], 'gsrwhat': [None]})
+ else:
+ expected_params.update({
+ 'gsrsearch': ['wiki'], 'gsrwhat': ['title']})
+ self.assertEqual(search_gen.request._params, expected_params)
try:
- for hit in self.site.search('wiki', namespaces=0, total=10,
- get_redirects=True, where='title'):
+ for hit in search_gen:
self.assertIsInstance(hit, pywikibot.Page)
self.assertEqual(hit.namespace(), 0)
- if 'wiki' not in hit.title().lower():
- self.assertTrue(
- any('wiki' in r.title().lower()
- for r in hit.getReferences(filter_redirects=True)),
- "'wiki' neither found in '{0}'.lower() "
- 'nor in its redirects'.format(hit.title()))
except pywikibot.data.api.APIError as e:
if e.code in ('search-title-disabled', 'gsrsearch-title-disabled'):
raise unittest.SkipTest(
--
To view, visit https://gerrit.wikimedia.org/r/459370
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: I3438eecad5197b1d7a2707fbf1ee10894fd6ead8
Gerrit-Change-Number: 459370
Gerrit-PatchSet: 3
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
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 (75)