jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768310 )
Change subject: [tests] remove unused CapturingTestCase and AutoDeprecationTestCase
......................................................................
[tests] remove unused CapturingTestCase and AutoDeprecationTestCase
Change-Id: I195ac0f044bd3039ad6788f82472c49ee7e1373d
---
M tests/aspects.py
1 file changed, 10 insertions(+), 105 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py
index 0cc5949..c93da45 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -24,7 +24,7 @@
import pywikibot
from pywikibot import Site, config
-from pywikibot.backports import removeprefix
+from pywikibot.backports import removeprefix, removesuffix
from pywikibot.comms import http
from pywikibot.data.api import Request as _original_Request
from pywikibot.exceptions import (
@@ -677,10 +677,7 @@
# sitedata['family'] may be an AutoFamily. Use str() for its name
sitename = str(sitedata['family']) + ':' + sitedata['code']
if func.__doc__:
- if func.__doc__.endswith('.'):
- wrapped_method.__doc__ = func.__doc__[:-1]
- else:
- wrapped_method.__doc__ = func.__doc__
+ wrapped_method.__doc__ = removesuffix(func.__doc__, '.')
wrapped_method.__doc__ += ' on ' + sitename
else:
wrapped_method.__doc__ = 'Test ' + sitename
@@ -815,16 +812,13 @@
for test in tests:
test_func = dct[test]
- # method decorated with unittest.expectedFailure has no arguments
+ # Method decorated with unittest.expectedFailure has no arguments
# so it is assumed to not be a multi-site test method.
- if test_func.__code__.co_argcount == 0:
+ # A normal test method only accepts 'self'
+ if test_func.__code__.co_argcount in (0, 1):
continue
- # a normal test method only accepts 'self'
- if test_func.__code__.co_argcount == 1:
- continue
-
- # a multi-site test method only accepts 'self' and the site-key
+ # A multi-site test method only accepts 'self' and the site-key
if test_func.__code__.co_argcount != 2:
raise Exception(
'{}: Test method {} must accept either 1 or 2 arguments; '
@@ -833,8 +827,8 @@
# create test methods processed by unittest
for (key, sitedata) in dct['sites'].items():
- test_name = (test + '_'
- + key.replace('-', '_').replace(':', '_'))
+ table = str.maketrans('-:', '__')
+ test_name = (test + '_' + key.translate(table))
cls.add_method(dct, test_name,
wrap_method(key, sitedata, dct[test]))
@@ -961,8 +955,7 @@
if not family:
raise Exception('no family defined for {}'.format(cls.__name__))
if not code:
- raise Exception('no site code defined for {}'
- .format(cls.__name__))
+ raise Exception('no site code defined for {}'.format(cls.__name__))
usernames = config.usernames
@@ -1018,80 +1011,13 @@
"""
if not site:
site = self.get_site()
- page = pywikibot.Page(pywikibot.page.Link(
- 'There is no page with this title', site))
+ page = pywikibot.Page(site, 'There is no page with this title')
if page.exists():
raise unittest.SkipTest('Did not find a page that does not exist.')
return page
-class CapturingTestCase(TestCase):
-
- """
- Capture assertion calls to do additional calls around them.
-
- All assertions done which start with "assert" are patched in such a way
- that after the assertion it calls ``process_assertion`` with the assertion
- and the arguments.
-
- To avoid that it patches the assertion it's possible to put the call in an
- ``disable_assert_capture`` with-statement.
-
- """
-
- # Is True while an assertion is running, so that assertions won't be
- # patched when they are executed while an assertion is running and only
- # the outer most assertion gets actually patched.
- _patched = False
-
- @contextmanager
- def disable_assert_capture(self):
- """A context manager preventing that assertions are patched."""
- nested = self._patched # Don't reset if it was set before
- self._patched = True
- yield
- if not nested:
- self._patched = False
-
- @contextmanager
- def _delay_assertion(self, context, assertion, args, kwargs):
- with self.disable_assert_capture():
- with context as ctx:
- yield ctx
- self.after_assert(assertion, *args, **kwargs)
-
- def process_assert(self, assertion, *args, **kwargs):
- """Handle the assertion call."""
- return assertion(*args, **kwargs)
-
- def after_assert(self, assertion, *args, **kwargs):
- """Handle after the assertion."""
-
- def patch_assert(self, assertion):
- """Execute process_assert when the assertion is called."""
- def inner_assert(*args, **kwargs):
- assert self._patched is False
- self._patched = True
- try:
- context = self.process_assert(assertion, *args, **kwargs)
- if hasattr(context, '__enter__'):
- return self._delay_assertion(context, assertion, args,
- kwargs)
- self.after_assert(assertion, *args, **kwargs)
- return context
- finally:
- self._patched = False
- return inner_assert
-
- def __getattribute__(self, attr):
- """Patch assertions if enabled."""
- result = super().__getattribute__(attr)
- if attr.startswith('assert') and not self._patched:
- return self.patch_assert(result)
- return result
-
-
class PatchingTestCase(TestCase):
"""Easily patch and unpatch instances."""
@@ -1602,27 +1528,6 @@
super().tearDown()
-class AutoDeprecationTestCase(CapturingTestCase, DeprecationTestCase):
-
- """
- A test case capturing asserts and asserting a deprecation afterwards.
-
- For example ``assertEqual`` will do first ``assertEqual`` and then
- ``assertOneDeprecation``.
- """
-
- def after_assert(self, assertion, *args, **kwargs):
- """Handle assertion and call ``assertOneDeprecation`` after it."""
- super().after_assert(
- assertion, *args, **kwargs)
- self.assertOneDeprecation()
-
- source_adjustment_skips = DeprecationTestCase.source_adjustment_skips + [
- CapturingTestCase.process_assert,
- CapturingTestCase.patch_assert,
- ]
-
-
@optional_pytest_httpbin_cls_decorator
class HttpbinTestCase(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768310
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: I195ac0f044bd3039ad6788f82472c49ee7e1373d
Gerrit-Change-Number: 768310
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/+/768283 )
Change subject: [doc] Update ROADMAP.rst and CHANGELOG.md
......................................................................
[doc] Update ROADMAP.rst and CHANGELOG.md
Change-Id: I53b80d36e8fefe8ae0da7dbf7a31d08588885b1d
---
M ROADMAP.rst
M scripts/CHANGELOG.md
2 files changed, 13 insertions(+), 2 deletions(-)
Approvals:
Meno25: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index d62de5d..fd9c4a5 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,7 +1,10 @@
Current release changes
^^^^^^^^^^^^^^^^^^^^^^^
-* (no changes yet)
+* -cosmetic_changes (-cc) option allows to assign the value directly instead of toggle it
+* distutils.util.strtobool() was implemented as tools.strtobool() due to :pep:`632`
+* The "in" operator always return whether the siteinfo contains the key even it is not cached (T302859)
+* Siteinfo.clear() and Siteinfo.is_cached() methods were added
Deprecations
^^^^^^^^^^^^
diff --git a/scripts/CHANGELOG.md b/scripts/CHANGELOG.md
index 876d578..7f9266e 100644
--- a/scripts/CHANGELOG.md
+++ b/scripts/CHANGELOG.md
@@ -1,8 +1,16 @@
# Scripts Changelog
-## 7.0.0
+
+## 7.1.0
*In development*
+### fixing_redirects
+* -always option was enabled
+
+
+## 7.0.0
+*26 February 2022*
+
### general
* L10N updates
* Provide ConfigParserBot for several scripts (T223778)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768283
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: I53b80d36e8fefe8ae0da7dbf7a31d08588885b1d
Gerrit-Change-Number: 768283
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768233 )
Change subject: [tests] skip SiteRandomTestCase for beta sites
......................................................................
[tests] skip SiteRandomTestCase for beta sites
Bug: T282602
Change-Id: Ic6f715b5beb5a3f951624425f10ef4e69fa34a83
---
M tests/site_tests.py
1 file changed, 8 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 3b126fa..da62cf2 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -2353,6 +2353,14 @@
"""Test random methods of a site."""
+ @classmethod
+ def setUpClass(cls):
+ """Skip test on beta due to T282602."""
+ super().setUpClass()
+ site = cls.get_site()
+ if site.family.name in ('wpbeta', 'wsbeta'):
+ cls.skipTest('Skipping test on {} due to T282602'.format(site))
+
def test_unlimited_small_step(self):
"""Test site.randompages() continuation.
@@ -2360,8 +2368,6 @@
performed, so we also don't test this here.
"""
mysite = self.get_site()
- if mysite.family.name in ('wpbeta', 'wsbeta'):
- self.skipTest('Skipping test on {} due to T282602'.format(mysite))
pages = []
rngen = mysite.randompages(total=None)
rngen.set_query_increment = 5
@@ -2375,8 +2381,6 @@
def test_limit_10(self):
"""Test site.randompages() with limit."""
mysite = self.get_site()
- if mysite.family.name in ('wpbeta', 'wsbeta'):
- self.skipTest('Skipping test on {} due to T282602'.format(mysite))
rn = list(mysite.randompages(total=10))
self.assertLessEqual(len(rn), 10)
for a_page in rn:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768233
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: Ic6f715b5beb5a3f951624425f10ef4e69fa34a83
Gerrit-Change-Number: 768233
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/+/767200 )
Change subject: [IMPR] allow True/False/1/0 as -cosmeticchanges -cc value
......................................................................
[IMPR] allow True/False/1/0 as -cosmeticchanges -cc value
Currently -cc can be only switched but the current setting is deeply
hidden in (user-)config.py. Enable direct setting like -cc:True or
-cc:False respectivly -cc:1 or -cc:0 and some other variants.
- add a reimplementation fo distutils.util.strtobool due to PEP 632
- use strtobool to determine the -cc setting
- add tests for tools string functions
Change-Id: I106e38becfdfe881c93e96e8535d931a20288331
---
M pywikibot/bot.py
M pywikibot/tools/__init__.py
M tests/tools_tests.py
3 files changed, 62 insertions(+), 5 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 16a02bf..1bd974d 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -85,7 +85,6 @@
'WikidataBot',
)
-
import atexit
import codecs
import configparser
@@ -177,6 +176,7 @@
PYTHON_VERSION,
deprecated,
issue_deprecation_warning,
+ strtobool,
)
from pywikibot.tools._logging import LoggingFormatter
from pywikibot.tools.formatter import color_format
@@ -248,9 +248,13 @@
-verbose Have the bot provide additional console output that may be
-v useful in debugging.
--cosmeticchanges Toggles the cosmetic_changes setting made in config.py or
--cc user-config.py to its inverse and overrules it. All other
- settings and restrictions are untouched.
+-cosmeticchanges Toggles the cosmetic_changes setting made in config.py
+-cc or user-config.py to its inverse and overrules it. All
+ other settings and restrictions are untouched. The
+ setting may also be given directly like `-cc:True`;
+ accepted values for the option are `1`, `yes`, `true`,
+ `on`, `y`, `t` for True and `0`, `no`, `false`, `off`,
+ `n`, `f` for False. Values are case-insensitive.
-simulate Disables writing to the server. Useful for testing and
debugging of new code (if given, doesn't do any real
@@ -899,7 +903,8 @@
elif option == '-nolog':
config.log = []
elif option in ('-cosmeticchanges', '-cc'):
- config.cosmetic_changes = not config.cosmetic_changes
+ config.cosmetic_changes = (strtobool(value) if value
+ else not config.cosmetic_changes)
output('NOTE: option cosmetic_changes is {}\n'
.format(config.cosmetic_changes))
elif option == '-simulate':
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 9e19104..323ddf5 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -369,6 +369,26 @@
return (_first_upper_exception(first) or first.upper()) + string[1:]
+def strtobool(val: str) -> bool:
+ """Convert a string representation of truth to True or False.
+
+ This is a reimplementation of distutils.util.strtobool due to
+ :pep:`632#Migration Advice`
+
+ .. versionadded:: 7.1
+
+ :param val: True values are 'y', 'yes', 't', 'true', 'on', and '1';
+ false values are 'n', 'no', 'f', 'false', 'off', and '0'.
+ :raises ValueError: `val` is not a valid truth value
+ """
+ val = val.lower()
+ if val in ('y', 'yes', 't', 'true', 'on', '1'):
+ return True
+ if val in ('n', 'no', 'f', 'false', 'off', '0'):
+ return False
+ raise ValueError('invalid truth value {!r}'.format(val))
+
+
def normalize_username(username) -> Optional[str]:
"""Normalize the username.
diff --git a/tests/tools_tests.py b/tests/tools_tests.py
index 30ec3b7..bc7751b 100644
--- a/tests/tools_tests.py
+++ b/tests/tools_tests.py
@@ -892,6 +892,38 @@
self.assertFalse(has_module('setuptools', '99999'))
+class TestStringFunctions(TestCase):
+
+ """Unit test class for string functions."""
+
+ net = False
+
+ def test_first_lower(self):
+ """Test first_lower function."""
+ self.assertEqual(tools.first_lower('Foo Bar'), 'foo Bar')
+ self.assertEqual(tools.first_lower('FOO BAR'), 'fOO BAR')
+ self.assertEqual(tools.first_lower(''), '')
+
+ def test_first_upper(self):
+ """Test first_upper function."""
+ self.assertEqual(tools.first_upper('foo bar'), 'Foo bar')
+ self.assertEqual(tools.first_upper('foo BAR'), 'Foo BAR')
+ self.assertEqual(tools.first_upper(''), '')
+ self.assertEqual(tools.first_upper('ß'), 'ß')
+ self.assertNotEqual(tools.first_upper('ß'), str.upper('ß'))
+
+ def test_strtobool(self):
+ """Test strtobool function."""
+ for string in ('True', 'TRUE', 'true', 'T', 'Yes', 'y', 'on', '1'):
+ with self.subTest(truth=string):
+ self.assertTrue(tools.strtobool(string))
+ for string in ('False', 'F', 'No', 'n', 'oFF', '0'):
+ with self.subTest(falsity=string):
+ self.assertFalse(tools.strtobool(string))
+ with self.assertRaises(ValueError):
+ tools.strtobool('okay')
+
+
if __name__ == '__main__': # pragma: no cover
with suppress(SystemExit):
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/767200
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: I106e38becfdfe881c93e96e8535d931a20288331
Gerrit-Change-Number: 767200
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768216 )
Change subject: [tests] Skip SiteRandomTestCase on beta cluster
......................................................................
[tests] Skip SiteRandomTestCase on beta cluster
Also fix mythrottle._lagvalue check in TestLagpattern
which may be an int (at beta)
Bug: T282602
Change-Id: I59e41e1e4a6f8a1d86dcd482de9b674ebe9981a6
---
M tests/api_tests.py
M tests/site_tests.py
2 files changed, 6 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index ae6b813..af3b672 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -988,8 +988,8 @@
pywikibot.warning(
'Wrong api.lagpattern regex, cannot retrieve lag value')
raise e
- self.assertIsInstance(mythrottle._lagvalue, float)
- self.assertGreaterEqual(mythrottle._lagvalue, 0.0)
+ self.assertIsInstance(mythrottle._lagvalue, (int, float))
+ self.assertGreaterEqual(mythrottle._lagvalue, 0)
self.assertIsInstance(mythrottle.retry_after, int)
self.assertGreaterEqual(mythrottle.retry_after, 0)
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 9813d81..3b126fa 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -2360,6 +2360,8 @@
performed, so we also don't test this here.
"""
mysite = self.get_site()
+ if mysite.family.name in ('wpbeta', 'wsbeta'):
+ self.skipTest('Skipping test on {} due to T282602'.format(mysite))
pages = []
rngen = mysite.randompages(total=None)
rngen.set_query_increment = 5
@@ -2373,6 +2375,8 @@
def test_limit_10(self):
"""Test site.randompages() with limit."""
mysite = self.get_site()
+ if mysite.family.name in ('wpbeta', 'wsbeta'):
+ self.skipTest('Skipping test on {} due to T282602'.format(mysite))
rn = list(mysite.randompages(total=10))
self.assertLessEqual(len(rn), 10)
for a_page in rn:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768216
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: I59e41e1e4a6f8a1d86dcd482de9b674ebe9981a6
Gerrit-Change-Number: 768216
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged