jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/609507 )
Change subject: [tests] Remove six dependency ......................................................................
[tests] Remove six dependency
Change-Id: I49baea1d2f494b87139bfded001eab91eccf56dd --- M dev-requirements.txt M scripts/followlive.py M setup.py M tests/aspects.py M tests/date_tests.py M tests/l10n_tests.py M tests/logentries_tests.py M tests/plural_tests.py M tests/script_tests.py M tests/tools_tests.py M tests/utils.py M tox.ini 12 files changed, 43 insertions(+), 102 deletions(-)
Approvals: Zhuyifei1999: Looks good to me, approved jenkins-bot: Verified
diff --git a/dev-requirements.txt b/dev-requirements.txt index c08d091..8c45d76 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -11,8 +11,6 @@ werkzeug>=0.15.5 pytest-httpbin
-six - nose git+https://github.com/jayvdb/nosetrim@py3
diff --git a/scripts/followlive.py b/scripts/followlive.py index 3c1ecad..27d4e99 100644 --- a/scripts/followlive.py +++ b/scripts/followlive.py @@ -28,8 +28,6 @@ from pywikibot import i18n, pagegenerators, editor from pywikibot.bot import SingleSiteBot, CurrentPageBot, QuitKeyboardInterrupt
-__metaclass__ = type - # This is required for the text that is shown when you run this script # with the parameter -help. docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816 @@ -465,8 +463,8 @@ pywikibot.output('Page correct! Proceeding with next pages.') return # Check user input: - if answer[0] == '': - # Answer entered as an utf8 string + if answer[0] == 'u': + # Answer entered as string answer = answer[1:] try: choices = answer.split(',') diff --git a/setup.py b/setup.py index 7c50871..242ff93 100644 --- a/setup.py +++ b/setup.py @@ -139,7 +139,6 @@
# These extra dependencies are needed other unittest fails to load tests. test_deps += extra_deps['eventstreams'] -test_deps += ['six']
class _DottedDict(dict): diff --git a/tests/aspects.py b/tests/aspects.py index e6ab7f2..5c368a4 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -39,7 +39,7 @@ from tests import ( safe_repr, unittest, patch_request, unpatch_request, unittest_print) from tests.utils import ( - add_metaclass, execute_pwb, DrySite, DryRequest, + execute_pwb, DrySite, DryRequest, WarningSourceSkipContextManager, AssertAPIErrorContextManager, )
@@ -886,13 +886,10 @@ dct[test_name].__doc__ = doc
-@add_metaclass -class TestCase(TestTimerMixin, TestCaseBase): +class TestCase(TestTimerMixin, TestCaseBase, metaclass=MetaTestCaseClass):
"""Run tests on pre-defined sites."""
- __metaclass__ = MetaTestCaseClass - @classmethod def setUpClass(cls): """ diff --git a/tests/date_tests.py b/tests/date_tests.py index 5308049..0272e2f 100644 --- a/tests/date_tests.py +++ b/tests/date_tests.py @@ -1,18 +1,16 @@ # -*- coding: utf-8 -*- """Tests for the date module.""" # -# (C) Pywikibot team, 2012-2018 +# (C) Pywikibot team, 2012-2020 # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - +from contextlib import suppress from datetime import datetime
from pywikibot import date
from tests.aspects import unittest, MetaTestCaseClass, TestCase -from tests.utils import add_metaclass
class TestDateMeta(MetaTestCaseClass): @@ -55,13 +53,10 @@ return super(TestDateMeta, cls).__new__(cls, name, bases, dct)
-@add_metaclass -class TestDate(TestCase): +class TestDate(TestCase, metaclass=TestDateMeta):
"""Test cases for date library processed by unittest."""
- __metaclass__ = TestDateMeta - net = False
@@ -108,7 +103,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py index d54cee9..341f61e 100644 --- a/tests/l10n_tests.py +++ b/tests/l10n_tests.py @@ -1,20 +1,19 @@ # -*- coding: utf-8 -*- """Test valid templates.""" # -# (C) Pywikibot team, 2015-2019 +# (C) Pywikibot team, 2015-2020 # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import os
+from contextlib import suppress + import pywikibot from pywikibot import i18n from pywikibot.textlib import extract_templates_and_params_regex_simple
from tests.aspects import unittest, MetaTestCaseClass, TestCase -from tests.utils import add_metaclass
PACKAGES = ( 'redirect-broken-redirect-template', # speedy deletion template @@ -85,13 +84,10 @@ return super(TestValidTemplateMeta, cls).__new__(cls, name, bases, dct)
-@add_metaclass -class TestValidTemplate(TestCase): +class TestValidTemplate(TestCase, metaclass=TestValidTemplateMeta):
"""Test cases L10N message templates processed by unittest."""
- __metaclass__ = TestValidTemplateMeta - family = 'wikipedia' code = 'en'
@@ -133,7 +129,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/logentries_tests.py b/tests/logentries_tests.py index 6d8ce78..81fc48a 100644 --- a/tests/logentries_tests.py +++ b/tests/logentries_tests.py @@ -7,6 +7,8 @@ # import datetime
+from contextlib import suppress + import pywikibot
from pywikibot.exceptions import HiddenKeyError @@ -149,6 +151,8 @@
"""Test general LogEntry properties."""
+ pass +
class TestSimpleLogentries(TestLogentriesBase):
@@ -335,7 +339,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/plural_tests.py b/tests/plural_tests.py index f89ca8c..57893d9 100644 --- a/tests/plural_tests.py +++ b/tests/plural_tests.py @@ -1,18 +1,15 @@ # -*- coding: utf-8 -*- """Test plural module.""" # -# (C) Pywikibot team, 2015-2018 +# (C) Pywikibot team, 2015-2020 # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals +from contextlib import suppress
from pywikibot import plural
-from tests.aspects import ( - unittest, TestCase, MetaTestCaseClass, -) -from tests.utils import add_metaclass +from tests.aspects import unittest, TestCase, MetaTestCaseClass
class MetaPluralRulesTest(MetaTestCaseClass): @@ -55,13 +52,10 @@ return super(MetaPluralRulesTest, cls).__new__(cls, name, bases, dct)
-@add_metaclass -class TestPluralRules(TestCase): +class TestPluralRules(TestCase, metaclass=MetaPluralRulesTest):
"""Test the consistency of the plural rules."""
- __metaclass__ = MetaPluralRulesTest - net = False # for callable plural rules it'll test up until this number, this number # must cause to create all plurals in all dynamic languages @@ -69,7 +63,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/script_tests.py b/tests/script_tests.py index 033991e..8e64326 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -5,17 +5,17 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import os import sys
-from pywikibot.tools import has_module, PY2 +from contextlib import suppress + +from pywikibot.tools import has_module
from tests import join_root_path, unittest_print from tests.aspects import (unittest, DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase) -from tests.utils import execute_pwb, add_metaclass +from tests.utils import execute_pwb
scripts_path = join_root_path('scripts')
@@ -31,9 +31,6 @@ 'weblinkchecker': ['memento_client'], }
-if PY2: - script_deps['data_ingestion'] = ['unicodecsv'] -
def check_script_deps(script_name): """Detect whether all dependencies are installed.""" @@ -132,6 +129,8 @@ 'login': 'Logged in on ', 'pagefromfile': 'Please enter the file name', 'replace': 'Press Enter to use this automatic message', + 'replicate_wiki': + 'error: the following arguments are required: destination', 'shell': ('>>> ', 'Welcome to the'), 'transferbot': 'Target site not different from source site', 'unusedfiles': ('Working on', None), @@ -144,12 +143,6 @@ 'upload': 'ERROR: Upload error', }
-if not PY2: - no_args_expected_results['replicate_wiki'] = ( - 'error: the following arguments are required: destination') -else: - no_args_expected_results['replicate_wiki'] = 'error: too few arguments' -
enable_autorun_tests = ( os.environ.get('PYWIKIBOT_TEST_AUTORUN', '0') == '1') @@ -345,16 +338,13 @@ return super(TestScriptMeta, cls).__new__(cls, name, bases, dct)
-@add_metaclass -class TestScriptHelp(PwbTestCase): +class TestScriptHelp(PwbTestCase, metaclass=TestScriptMeta):
"""Test cases for running scripts with -help.
All scripts should not create a Site for -help, so net = False. """
- __metaclass__ = TestScriptMeta - net = False
# Here come scripts requiring and missing dependencies, that haven't been @@ -366,8 +356,8 @@ _results = None
-@add_metaclass -class TestScriptSimulate(DefaultSiteTestCase, PwbTestCase): +class TestScriptSimulate(DefaultSiteTestCase, PwbTestCase, + metaclass=TestScriptMeta):
"""Test cases for scripts.
@@ -377,8 +367,6 @@ run in pwb can automatically login using the saved cookies. """
- __metaclass__ = TestScriptMeta - user = True
_expected_failures = { @@ -397,7 +385,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/tools_tests.py b/tests/tools_tests.py index 1cb70d9..1b5b39d 100644 --- a/tests/tools_tests.py +++ b/tests/tools_tests.py @@ -2,24 +2,21 @@ # -*- coding: utf-8 -*- """Test tools package alone which don't fit into other tests.""" # -# (C) Pywikibot team, 2015-2019 +# (C) Pywikibot team, 2015-2020 # # Distributed under the terms of the MIT license. -from __future__ import absolute_import, division, unicode_literals - -try: - from collections.abc import Mapping -except ImportError: # Python 2.7 - from collections import Mapping -from collections import OrderedDict import decimal -from importlib import import_module import inspect import os.path import subprocess import tempfile import warnings
+from collections.abc import Mapping +from collections import OrderedDict +from contextlib import suppress +from importlib import import_module + from pywikibot import tools from pywikibot.tools import classproperty, suppress_warnings
@@ -27,7 +24,6 @@ from tests.aspects import ( unittest, require_modules, DeprecationTestCase, TestCase, MetaTestCaseClass ) -from tests.utils import add_metaclass
class ContextManagerWrapperTestCase(TestCase): @@ -715,13 +711,10 @@ return super(MetaTestArgSpec, cls).__new__(cls, name, bases, dct)
-@add_metaclass -class TestArgSpec(DeprecationTestCase): +class TestArgSpec(DeprecationTestCase, metaclass=MetaTestArgSpec):
"""Test getargspec and ArgSpec from tools."""
- __metaclass__ = MetaTestArgSpec - expected_class = tools.ArgSpec
def _method_test_args(self, param): @@ -913,7 +906,5 @@
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass diff --git a/tests/utils.py b/tests/utils.py index 65c440a..e1fd429 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -16,8 +16,6 @@ from subprocess import PIPE, Popen, TimeoutExpired from types import ModuleType
-import six - try: from cryptography import __version__ as cryptography_version cryptography_version = list(map(int, cryptography_version.split('.'))) @@ -57,11 +55,6 @@ return lambda orig: orig
-def add_metaclass(cls): - """Call six's add_metaclass with the site's __metaclass__ in Python 3.""" - return six.add_metaclass(cls.__metaclass__)(cls) - - def fixed_generator(iterable): """Return a dummy generator ignoring all parameters.""" def gen(*args, **kwargs): diff --git a/tox.ini b/tox.ini index 0ea567e..ed3d8f6 100644 --- a/tox.ini +++ b/tox.ini @@ -45,7 +45,6 @@ fasttest-py35: mwparserfromhell fasttest-py35: beautifulsoup4 fasttest-py35: nose-detecthttp>=0.1.3 - fasttest-py35: six
[testenv:commit-message] basepython = python3 @@ -62,7 +61,6 @@ py35: python3.5 deps = nose - six
[testenv:venv] commands = {posargs} @@ -85,7 +83,7 @@ # FI1: __future__ import "x" missing # FI5: __future__ import "x" present # H101: TODO format -# H236: Mandatory use of six for Python 2 & 3 metaclass support +# H238: Old style class # H301: Do not import more than one module per line; Pywikibot uses H306 (Alphabetically order your imports by the full module path) # H404: docstring multiline start # H405: docstring summary line @@ -100,7 +98,7 @@ # D412: No blank lines allowed between a section header and its content # D413: Missing blank line after last section
-ignore = D105,D211,D401,D413,D412,FI1,FI5,H101,H236,H301,H404,H405,H903,P101,P102,P103,W503 +ignore = D105,D211,D401,D413,D412,FI1,FI5,H101,H238,H301,H404,H405,H903,P101,P102,P103,W503 enable-extensions = H203,H204,H205 exclude = .tox,.git,./*.egg,build,scripts/archive/*,./scripts/i18n/* min-version = 2.7
pywikibot-commits@lists.wikimedia.org