jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/602298 )
Change subject: [bugfix] Use the scripts args executing a script with pwb.py
......................................................................
[bugfix] Use the scripts args executing a script with pwb.py
- pwb.py is able to handle global args. These must not be passed to the
script as arguments. Therefore use the result of handle_args function
instead of argvu list to be passed to run_python_file
- call run_python_file with only 3 parameters:
filename, script_args and file_package
- combine these 3 parameters to fill sys.argv and pwb.argvu inside
run_python_file function
- update generate_user_files call
- tests were added already. Check also the argv content.
Bug: T254435
Change-Id: Ic201599583d6527047050846c12a898f0d2f0b2c
---
M pwb.py
M tests/pwb_tests.py
2 files changed, 20 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 8c5da9f..1f6741d 100755
--- a/pwb.py
+++ b/pwb.py
@@ -102,12 +102,16 @@
# https://bitbucket.org/ned/coveragepy/src/2c5fb3a8b81c/setup.py?at=default#c…
-def run_python_file(filename, argv, argvu, package=None):
+def run_python_file(filename, args, package=None):
"""Run a python file as if it were the main program on the command line.
- `filename` is the path to the file to execute, it need not be a .py file.
- `args` is the argument array to present as sys.argv, as unicode strings.
-
+ :param filename: The path to the file to execute, it need not be a
+ .py file.
+ :type filename: str
+ :param args: is the argument list to present as sys.argv, as strings.
+ :type args: List[str]
+ :param package: The package of the script. Used for checks.
+ :type package: Optional[module]
"""
# Create a module to serve as __main__
old_main_mod = sys.modules['__main__']
@@ -123,8 +127,8 @@
old_argv = sys.argv
old_argvu = pwb.argvu
- sys.argv = argv
- pwb.argvu = argvu
+ sys.argv = [filename] + args
+ pwb.argvu = [Path(filename).stem] + args
sys.path.insert(0, os.path.dirname(filename))
try:
@@ -281,9 +285,7 @@
or filename == 'version.py'):
print("NOTE: 'user-config.py' was not found!")
print('Please follow the prompts to create it:')
- run_python_file(os.path.join(_pwb_dir, 'generate_user_files.py'),
- ['generate_user_files.py'],
- ['generate_user_files.py'])
+ run_python_file(os.path.join(_pwb_dir, 'generate_user_files.py'), [])
# because we have loaded pywikibot without user-config.py loaded,
# we need to re-start the entire process. Ask the user to do so.
print('Now, you have to re-execute the command to start your script.')
@@ -403,7 +405,6 @@
return False
file_package = None
- argvu = pwb.argvu[1:]
if not os.path.exists(filename):
filename = find_filename(filename)
@@ -440,10 +441,7 @@
help_option = any(arg.startswith('-help:') or arg == '-help'
for arg in script_args)
if site_package or check_modules(filename) or help_option:
- run_python_file(filename,
- [filename] + script_args,
- [Path(filename).stem] + argvu[1:],
- module)
+ run_python_file(filename, script_args, module)
return True
diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py
index 66d4298..2d59c6b 100644
--- a/tests/pwb_tests.py
+++ b/tests/pwb_tests.py
@@ -75,18 +75,22 @@
self.assertEqual('Häuser', vpwb['stdout'].strip())
self.assertEqual('Häuser', vpwb['stderr'].strip())
- @unittest.expectedFailure # T254435
def test_argv(self):
"""Test argv of pywikibot.
Make sure that argv passed to the script is not contaminated by
global options given to pwb.py wrapper.
"""
- script_path = join_pwb_tests_path('print_argv.py')
- without_global_args = execute_pwb([script_path, '-help'])
- with_no_global_args = execute_pwb(['-maxlag:5', script_path, '-help'])
+ script_name = 'print_argv'
+ script_path = join_pwb_tests_path(script_name + '.py')
+ script_opts = ['-help']
+ command = [script_path] + script_opts
+ without_global_args = execute_pwb(command)
+ with_no_global_args = execute_pwb(['-maxlag:5'] + command)
self.assertEqual(without_global_args['stdout'],
with_no_global_args['stdout'])
+ self.assertEqual(without_global_args['stdout'].rstrip(),
+ str([script_name] + script_opts))
def test_script_found(self):
"""Test pwb.py script call which is found."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/602298
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic201599583d6527047050846c12a898f0d2f0b2c
Gerrit-Change-Number: 602298
Gerrit-PatchSet: 9
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Bugreporter <bugreporter1(a)sina.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/742216 )
Change subject: [tests] Test whether pywikibot.argvu is not contaminated by global args
......................................................................
[tests] Test whether pywikibot.argvu is not contaminated by global args
running pwb -global_arg script -script_arg should be give the
same argvu vector like running pwb -global_arg script -script_arg.
Currently it fails due to T254435.
Bug: T254435
Change-Id: I1e8f0001d62a00f718bfd4f6fe4f86c4387869e8
---
A tests/pwb/print_argv.py
M tests/pwb_tests.py
2 files changed, 33 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pwb/print_argv.py b/tests/pwb/print_argv.py
new file mode 100644
index 0000000..76d1adb
--- /dev/null
+++ b/tests/pwb/print_argv.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+"""Script that forms part of pwb_tests.
+
+.. versionadded:: 7.0
+"""
+#
+# (C) Pywikibot team, 2021
+#
+# Distributed under the terms of the MIT license.
+#
+import pywikibot
+
+
+def main() -> None:
+ """Print pywikibot.argvu."""
+ print(pywikibot.argvu)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py
index e86be66..66d4298 100644
--- a/tests/pwb_tests.py
+++ b/tests/pwb_tests.py
@@ -75,6 +75,19 @@
self.assertEqual('Häuser', vpwb['stdout'].strip())
self.assertEqual('Häuser', vpwb['stderr'].strip())
+ @unittest.expectedFailure # T254435
+ def test_argv(self):
+ """Test argv of pywikibot.
+
+ Make sure that argv passed to the script is not contaminated by
+ global options given to pwb.py wrapper.
+ """
+ script_path = join_pwb_tests_path('print_argv.py')
+ without_global_args = execute_pwb([script_path, '-help'])
+ with_no_global_args = execute_pwb(['-maxlag:5', script_path, '-help'])
+ self.assertEqual(without_global_args['stdout'],
+ with_no_global_args['stdout'])
+
def test_script_found(self):
"""Test pwb.py script call which is found."""
stdout = io.StringIO(execute_pwb(['pwb'])['stdout'])
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/742216
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1e8f0001d62a00f718bfd4f6fe4f86c4387869e8
Gerrit-Change-Number: 742216
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/738509 )
Change subject: [IMPR] Provide is_locked method
......................................................................
[IMPR] Provide is_locked method
- add APISite.get_globaluserinfo() method to retrieve global user
info for a given user or user ID. This enables to get global info like
global groups for any user.
- add globaluserinfo deleter to force reloading
- add APISite.is_locked() method
- rename User.isBlocked() to User.is_blocked() and deprecate the old
variant to be unified wit APISite.is_blocked()
- add force parameter to APISite.is_blocked like we have in User method
- add User.is_locked() method
- add is_locked to user_tests
- use renamed is_blocked in welcome.py script and also check for
global lock
Bug: T163629
Bug: T249392
Change-Id: I735b3b46fea82354f9beddbdfe7df0ee9670eba9
---
M pywikibot/page/__init__.py
M pywikibot/site/_apisite.py
M scripts/welcome.py
M tests/user_tests.py
4 files changed, 124 insertions(+), 30 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 4b78130..0552e50 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -2871,14 +2871,36 @@
"""
return self.getprops(force).get('editcount', 0)
- def isBlocked(self, force: bool = False) -> bool:
- """
- Determine whether the user is currently blocked.
+ def is_blocked(self, force: bool = False) -> bool:
+ """Determine whether the user is currently blocked.
+
+ .. versionchanged:: 7.0
+ renamed from :meth:`isBlocked` method
:param force: if True, forces reloading the data from API
"""
return 'blockedby' in self.getprops(force)
+ @deprecated('is_blocked', since='7.0.0')
+ def isBlocked(self, force: bool = False) -> bool:
+ """Determine whether the user is currently blocked.
+
+ .. deprecated:: 7.0
+ use :meth:`is_blocked` instead
+
+ :param force: if True, forces reloading the data from API
+ """
+ return self.is_blocked(force)
+
+ def is_locked(self, force: bool = False) -> bool:
+ """Determine whether the user is currently locked globally.
+
+ .. versionadded:: 7.0
+
+ :param force: if True, forces reloading the data from API
+ """
+ return self.site.is_locked(self.username, force)
+
def isEmailable(self, force: bool = False) -> bool:
"""
Determine whether emails may be send to this user through MediaWiki.
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 77658bc..74b45cd 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -14,12 +14,12 @@
from collections.abc import Iterable
from contextlib import suppress
from textwrap import fill
-from typing import Optional, Union
+from typing import Any, Optional, Union
from warnings import warn
import pywikibot
import pywikibot.family
-from pywikibot.backports import List
+from pywikibot.backports import Dict, List
from pywikibot.comms.http import get_authentication
from pywikibot.data import api
from pywikibot.exceptions import (
@@ -109,11 +109,12 @@
def __init__(self, code, fam=None, user=None):
"""Initializer."""
super().__init__(code, fam, user)
- self._msgcache = {}
- self._loginstatus = _LoginStatus.NOT_ATTEMPTED
- self._siteinfo = Siteinfo(self)
- self._paraminfo = api.ParamInfo(self)
+ self._globaluserinfo = {}
self._interwikimap = _InterwikiMap(self)
+ self._loginstatus = _LoginStatus.NOT_ATTEMPTED
+ self._msgcache = {}
+ self._paraminfo = api.ParamInfo(self)
+ self._siteinfo = Siteinfo(self)
self.tokens = TokenWallet(self)
def __getstate__(self):
@@ -450,7 +451,9 @@
To force retrieving userinfo ignoring cache, just delete this
property.
- self._userinfo will be a dict with the following keys and values:
+ .. seealso:: https://www.mediawiki.org/wiki/API:Userinfo
+
+ :return: A dict with the following keys and values:
- id: user id (numeric str)
- name: username (if user is logged in)
@@ -460,7 +463,6 @@
- message: present if user has a new message on talk page
- blockinfo: present if user is blocked (dict)
- https://www.mediawiki.org/wiki/API:Userinfo
"""
if not hasattr(self, '_userinfo'):
uirequest = self._simple_request(
@@ -481,15 +483,24 @@
@userinfo.deleter
def userinfo(self):
- """Delete cached userinfo."""
+ """Delete cached userinfo.
+
+ ..versionadded:: 5.5
+ """
if hasattr(self, '_userinfo'):
del self._userinfo
- @property
- def globaluserinfo(self):
+ def get_globaluserinfo(self,
+ user: Union[str, int, None] = None,
+ force: bool = False) -> Dict[str, Any]:
"""Retrieve globaluserinfo from site and cache it.
- self._globaluserinfo will be a dict with the following keys and values:
+ .. versionadded:: 7.0
+
+ :param user: The user name or user ID whose global info is
+ retrieved. Defaults to the current user.
+ :param force: Whether the cache should be discarded.
+ :return: A dict with the following keys and values:
- id: user id (numeric str)
- home: dbname of home wiki
@@ -497,36 +508,87 @@
- groups: list of groups (could be empty)
- rights: list of rights (could be empty)
- editcount: global editcount
+
+ :raises TypeError: Inappropriate argument type of 'user'
"""
- if not hasattr(self, '_globaluserinfo'):
- uirequest = self._simple_request(
+ if user is None:
+ user = self.username
+ param = {}
+ elif isinstance(user, str):
+ param = {'guiuser': user}
+ elif isinstance(user, int):
+ param = {'guiid': user}
+ else:
+ raise TypeError("Inappropriate argument type of 'user' ({})"
+ .format(type(user).__name__))
+
+ if force or user not in self._globaluserinfo:
+ param.update(
action='query',
meta='globaluserinfo',
- guiprop='groups|rights|editcount'
+ guiprop='groups|rights|editcount',
)
+ uirequest = self._simple_request(**param)
uidata = uirequest.submit()
assert 'query' in uidata, \
"API userinfo response lacks 'query' key"
assert 'globaluserinfo' in uidata['query'], \
- "API userinfo response lacks 'userinfo' key"
- self._globaluserinfo = uidata['query']['globaluserinfo']
- ts = self._globaluserinfo['registration']
- iso_ts = pywikibot.Timestamp.fromISOformat(ts)
- self._globaluserinfo['registration'] = iso_ts
- return self._globaluserinfo
+ "API userinfo response lacks 'globaluserinfo' key"
+ data = uidata['query']['globaluserinfo']
+ ts = data['registration']
+ data['registration'] = pywikibot.Timestamp.fromISOformat(ts)
+ self._globaluserinfo[user] = data
+ return self._globaluserinfo[user]
- def is_blocked(self):
+ @property
+ def globaluserinfo(self) -> Dict[str, Any]:
+ """Retrieve globaluserinfo of the current user from site.
+
+ To get globaluserinfo for a given user or user ID use
+ :meth:`get_globaluserinfo` method instead
+
+ .. versionadded:: 3.0
"""
- Return True when logged in user is blocked.
+ return self.get_globaluserinfo()
+
+ @globaluserinfo.deleter
+ def globaluserinfo(self):
+ """Delete cached globaluserinfo of current user.
+
+ ..versionadded:: 7.0
+ """
+ with suppress(KeyError):
+ del self._globaluserinfo[self.username]
+
+ def is_blocked(self, force: bool = False) -> bool:
+ """Return True when logged in user is blocked.
To check whether a user can perform an action,
the method has_right should be used.
https://www.mediawiki.org/wiki/API:Userinfo
- :rtype: bool
+ .. versionadded:: 7.0
+ The *force* parameter
+
+ :param force: Whether the cache should be discarded.
"""
+ if force:
+ del self.userinfo
return 'blockinfo' in self.userinfo
+ def is_locked(self,
+ user: Union[str, int, None] = None,
+ force: bool = False) -> bool:
+ """Return True when given user is locked globally.
+
+ .. versionadded:: 7.0
+
+ :param user: The user name or user ID. Defaults to the current
+ user.
+ :param force: Whether the cache should be discarded.
+ """
+ return 'locked' in self.get_globaluserinfo(user, force)
+
def get_searched_namespaces(self, force=False):
"""
Retrieve the default searched namespaces for the user.
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 6009db2..518cd19 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -768,8 +768,12 @@
return self._randomSignature
def skip_page(self, user) -> bool:
- """Check whether the user is to be skipped."""
- if user.isBlocked():
+ """Check whether the user is to be skipped.
+
+ .. versionchanged:: 7.0
+ also skip if user is locked globally
+ """
+ if user.is_blocked() or user.is_locked():
self.show_status(Msg.SKIP)
pywikibot.output('{} has been blocked!'.format(user.username))
diff --git a/tests/user_tests.py b/tests/user_tests.py
index a8368d1..7485349 100644
--- a/tests/user_tests.py
+++ b/tests/user_tests.py
@@ -56,7 +56,7 @@
self.assertFalse(user.isAnonymous())
self.assertIsInstance(user.registration(), pywikibot.Timestamp)
self.assertGreater(user.editCount(), 0)
- self.assertFalse(user.isBlocked())
+ self.assertFalse(user.is_blocked())
# self.assertTrue(user.isEmailable())
self.assertEqual(user.gender(), 'unknown')
self.assertIn('userid', user.getprops())
@@ -81,6 +81,7 @@
for contrib in contribs))
self.assertIn('user', user.groups())
self.assertIn('edit', user.rights())
+ self.assertFalse(user.is_locked())
def test_registered_user_without_timestamp(self):
"""Test registered user when registration timestamp is None."""
@@ -155,6 +156,11 @@
'This is an autoblock ID'):
user.getUserTalkPage()
+ def test_locked_user(self):
+ """Test global lock."""
+ user = User(self.site, 'TonjaHeritage2')
+ self.assertTrue(user.is_locked())
+
class TestUserMethods(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/738509
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I735b3b46fea82354f9beddbdfe7df0ee9670eba9
Gerrit-Change-Number: 738509
Gerrit-PatchSet: 8
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Revi <wiki(a)revi.dev>
Gerrit-Reviewer: TheSandDoctor <majorjohn1(a)mail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/736530 )
Change subject: [IMPR] Allow family files in base_dir by default
......................................................................
[IMPR] Allow family files in base_dir by default
private family files can be registered via register_families_folder()
function already. Register 'families' folder in basedir by default
within config.py.
Change-Id: Ic84fbc6b95910b9b144faa8309c54f3ed3714a11
---
M pywikibot/config.py
1 file changed, 17 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py
index d573ada..13c79c1 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -395,14 +395,27 @@
family_files[family_name] = file_path
-def register_families_folder(folder_path: str) -> None:
+def register_families_folder(folder_path: str,
+ not_exists_ok: bool = False) -> None:
"""Register all family class files contained in a directory.
+ .. versionadded:: 7.0
+ The *not_exists_ok* parameter
+
:param folder_path: The path of a folder containing family files.
The families may also be inside a zip archive structure.
+ :param not_exists_ok: When true, ignore FileNotFoundError
+ :raises FileNotFoundError: Family folder does not exist
:raises NotADirectoryError: folder_path is not a directory
"""
suffix = '_family.py'
+
+ if not os.path.exists(folder_path):
+ if not_exists_ok:
+ return
+ raise FileNotFoundError('Family folder {!r} does not exist'
+ .format(folder_path))
+
if os.path.isdir(folder_path):
for file_name in os.listdir(folder_path):
if file_name.endswith(suffix):
@@ -435,6 +448,9 @@
# Get the names of all known families, and initialize with empty dictionaries.
# ‘families/’ is a subdirectory of the directory in which config.py is found.
register_families_folder(os.path.join(os.path.dirname(__file__), 'families'))
+# ‘families/’ can also be stored in the base directory
+register_families_folder(os.path.join(base_dir, 'families'),
+ not_exists_ok=True)
# ############# USER INTERFACE SETTINGS ##############
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/736530
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic84fbc6b95910b9b144faa8309c54f3ed3714a11
Gerrit-Change-Number: 736530
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/742169 )
Change subject: [tests] Only find one alternative script with script_tests.py
......................................................................
[tests] Only find one alternative script with script_tests.py
utils.execute_pwb imports pwb and pywikibot and config variable cannot
be set directly for that environment and will be ignored. To set the
pwb_close_matches variable use the global argument handling.
This partly reverts change-ID I90d9243
Bug: T296204
Change-Id: If737765748115bc93770945832ab76999bd5e92b
---
M tests/script_tests.py
1 file changed, 8 insertions(+), 19 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index cb88909..6f9b47f 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -10,14 +10,12 @@
from contextlib import suppress
from pywikibot.tools import has_module
-from pywikibot import config
from tests import join_root_path, unittest_print
from tests.aspects import DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase
from tests.utils import execute_pwb
-saved_pwb_close_matches = config.pwb_close_matches
scripts_path = join_root_path('scripts')
# These dependencies are not always the package name which is in setup.py.
@@ -45,7 +43,7 @@
if not check_script_deps(name)}
# scripts which cannot be tested
-unrunnable_script_set = {'commonscat'}
+unrunnable_script_set = set()
def list_scripts(path, exclude=None):
@@ -57,8 +55,7 @@
return scripts
-script_list = (['login']
- + list_scripts(scripts_path, 'login.py'))
+script_list = ['login'] + list_scripts(scripts_path, exclude='login.py')
script_input = {
'interwiki': 'Test page that should not exist\n',
@@ -196,9 +193,11 @@
.format(script_name))
def test_script(self):
- global_args = 'For global options use -help:global or run pwb'
+ global_args_msg = \
+ 'For global options use -help:global or run pwb'
+ global_args = ['-pwb_close_matches:1']
- cmd = [script_name] + args
+ cmd = global_args + [script_name] + args
data_in = script_input.get(script_name)
timeout = 5 if is_autorun else None
@@ -238,7 +237,7 @@
elif not is_autorun:
if not stderr_other:
- self.assertIn(global_args, out_result)
+ self.assertIn(global_args_msg, out_result)
else:
self.assertIn('Use -help for further information.',
stderr_other)
@@ -267,7 +266,7 @@
self.assertNotIn('deprecated', err_result.lower())
# If stdout doesn't include global help..
- if global_args not in out_result:
+ if global_args_msg not in out_result:
# Specifically look for deprecated
self.assertNotIn('deprecated', out_result.lower())
# But also complain if there is any stdout
@@ -368,16 +367,6 @@
_results = no_args_expected_results
-def setUpModule(): # noqa: N802
- """Only find one alternative script (T296204)."""
- config.pwb_close_matches = 1
-
-
-def tearDownModule(): # noqa: N802
- """Restore pwb_close_matches setting."""
- config.pwb_close_matches = saved_pwb_close_matches
-
-
if __name__ == '__main__': # pragma: no cover
with suppress(SystemExit):
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/742169
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If737765748115bc93770945832ab76999bd5e92b
Gerrit-Change-Number: 742169
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/740297 )
Change subject: [bugfix] Only ignore FileExistsError when creating the api cache
......................................................................
[bugfix] Only ignore FileExistsError when creating the api cache
Bug: T295924
Change-Id: Ib2e83060857e748ddf56a019d9fd615c6ed9a229
---
M pywikibot/data/api.py
1 file changed, 6 insertions(+), 5 deletions(-)
Approvals:
Chico Venancio: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 2cf5144..acde07e 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -12,8 +12,8 @@
import pprint
import re
import traceback
+
from collections.abc import Container, MutableMapping, Sized
-from contextlib import suppress
from email.generator import BytesGenerator
from email.mime.multipart import MIMEMultipart as MIMEMultipartOrig
from email.mime.nonmultipart import MIMENonMultipart
@@ -1933,13 +1933,14 @@
def _make_dir(dir_name: str) -> str:
"""Create directory if it does not exist already.
- The directory name (dir_name) is returned unmodified.
+ .. versionchanged:: 7.0
+ Only `FileExistsError` is ignored but other OS exceptions can
+ be still raised
:param dir_name: directory path
- :return: directory name
+ :return: unmodified directory name for test purpose
"""
- with suppress(OSError): # directory already exists
- os.makedirs(dir_name)
+ os.makedirs(dir_name, exist_ok=True)
return dir_name
def _uniquedescriptionstr(self) -> str:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/740297
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib2e83060857e748ddf56a019d9fd615c6ed9a229
Gerrit-Change-Number: 740297
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Chico Venancio <chicocvenancio(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged