jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/609497 )

Change subject: [4.0] Remove Python 3 backports from TestCaseBase
......................................................................

[4.0] Remove Python 3 backports from TestCaseBase

Bug: T213287
Change-Id: I321e3a09e31ab4ff1cbd68bb0ec770bc544095f7
---
M tests/aspects.py
1 file changed, 10 insertions(+), 67 deletions(-)

Approvals:
  Zhuyifei1999: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/aspects.py b/tests/aspects.py
index d8a34a1..e6ab7f2 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -11,8 +11,6 @@
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import (absolute_import, division,
-                        print_function, unicode_literals)
 import inspect
 import itertools
 import os
@@ -21,11 +19,8 @@
 import time
 import warnings

-from contextlib import contextmanager
-try:
-    from collections.abc import Sized
-except ImportError:  # Python 2.7
-    from collections import Sized
+from contextlib import contextmanager, suppress
+from collections.abc import Sized

 import pywikibot

@@ -38,7 +33,6 @@
 from pywikibot.exceptions import ServerError, NoUsername
 from pywikibot.family import WikimediaFamily
 from pywikibot.site import BaseSite
-from pywikibot.tools import PY2, StringTypes

 import tests

@@ -67,49 +61,6 @@

     """Base class for all tests."""

-    if not hasattr(unittest.TestCase, 'subTest'):
-        @contextmanager
-        def subTest(self, *args, **kwargs):
-            """Dummy subTest context manager for Python 2 that does nothing."""
-            yield
-
-    if not hasattr(unittest.TestCase, 'assertRaisesRegex'):
-        def assertRaisesRegex(self, *args, **kwargs):
-            """
-            Wrapper of unittest.assertRaisesRegexp for Python 2 unittest.
-
-            assertRaisesRegexp is deprecated in Python 3.
-            """
-            return self.assertRaisesRegexp(*args, **kwargs)
-
-    if not hasattr(unittest.TestCase, 'assertRegex'):
-        def assertRegex(self, *args, **kwargs):
-            """
-            Wrapper of unittest.assertRegexpMatches for Python 2 unittest.
-
-            assertRegexpMatches is deprecated in Python 3.
-            """
-            return self.assertRegexpMatches(*args, **kwargs)
-
-    if not hasattr(unittest.TestCase, 'assertNotRegex'):
-        def assertNotRegex(self, *args, **kwargs):
-            """
-            Wrapper of unittest.assertNotRegexpMatches for Python 2 unittest.
-
-            assertNotRegexpMatches is deprecated in Python 3.
-            """
-            return self.assertNotRegexpMatches(*args, **kwargs)
-
-    if not hasattr(unittest.TestCase, 'assertCountEqual'):
-
-        def assertCountEqual(self, *args, **kwargs):
-            """
-            Wrapper of unittest.assertItemsEqual for Python 2 unittest.
-
-            assertItemsEqual is removed in Python 3.
-            """
-            return self.assertItemsEqual(*args, **kwargs)
-
     def assertIsEmpty(self, seq, msg=None):
         """Check that the sequence is empty."""
         self.assertIsInstance(
@@ -154,7 +105,7 @@
         All args must be already converted to a string.
         """
         for arg in args:
-            self.assertIsInstance(arg, StringTypes)
+            self.assertIsInstance(arg, str)
         self.assertMethod(method, *args)

     def assertPageInNamespaces(self, page, namespaces):
@@ -193,14 +144,12 @@

         gen_pages = list(gen)

-        try:
+        with suppress(StopIteration):
             gen_pages.append(next(original_iter))
             next(original_iter)
             if not site:
                 site = gen_pages[0].site
             gen_pages.append(pywikibot.Page(site, '...'))
-        except StopIteration:
-            pass

         for page in gen_pages:
             self.assertIsInstance(page, pywikibot.Page)
@@ -671,10 +620,8 @@
                     'Site {} has readonly state: {}'.format(
                         site, site.siteinfo.get('readonlyreason', '')))

-            try:
+            with suppress(NoUsername):
                 site.login()
-            except NoUsername:
-                pass

             if not site.user():
                 raise unittest.SkipTest(
@@ -983,13 +930,11 @@
                 data['site'] = Site(data['code'], data['family'],
                                     interface=interface)
             if 'hostname' not in data and 'site' in data:
-                try:
+                # Ignore if the family has defined this as
+                # obsolete without a mapping to a hostname.
+                with suppress(KeyError):
                     data['hostname'] = (
                         data['site'].base_url(data['site'].path()))
-                except KeyError:
-                    # The family has defined this as obsolete
-                    # without a mapping to a hostname.
-                    pass

         cm.__exit__(None, None, None)

@@ -1461,16 +1406,14 @@
         if 'PYWIKIBOT_DIR' in os.environ:
             self.orig_pywikibot_dir = os.environ['PYWIKIBOT_DIR']
         base_dir = pywikibot.config.base_dir
-        if OSWIN32 and PY2:
-            base_dir = str(base_dir)
-        os.environ[str('PYWIKIBOT_DIR')] = base_dir
+        os.environ['PYWIKIBOT_DIR'] = base_dir

     def tearDown(self):
         """Restore the environment after running the pwb.py script."""
         super(PwbTestCase, self).tearDown()
         del os.environ['PYWIKIBOT_DIR']
         if self.orig_pywikibot_dir:
-            os.environ[str('PYWIKIBOT_DIR')] = self.orig_pywikibot_dir
+            os.environ['PYWIKIBOT_DIR'] = self.orig_pywikibot_dir

     def _execute(self, args, data_in=None, timeout=None, error=None):
         site = self.get_site()

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/609497
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: I321e3a09e31ab4ff1cbd68bb0ec770bc544095f7
Gerrit-Change-Number: 609497
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to