jenkins-bot has submitted this change and it was merged.
Change subject: tests: replace sys with tools
......................................................................
tests: replace sys with tools
Use existing tools PY2 and PYTHON_VERSION.
While performance is not a consideration, these variables are
shorter and more descriptive.
Use new tools StringTypes and UnicodeType, are equivalent to the
types.StringTypes and types.UnicodeType that were dropped in Python 3.
These reduce the need for importing sys and doing version specific
logic at the beginning of each module.
Change-Id: Ie72f8df1dabe988d62bbc6337512df6b5daf47b7
---
M pywikibot/tools/__init__.py
M tests/__init__.py
M tests/api_tests.py
M tests/archivebot_tests.py
M tests/aspects.py
M tests/bot_tests.py
M tests/family_tests.py
M tests/file_tests.py
M tests/flow_edit_tests.py
M tests/flow_tests.py
M tests/http_tests.py
M tests/i18n_tests.py
M tests/logentry_tests.py
M tests/namespace_tests.py
M tests/page_tests.py
M tests/script_tests.py
M tests/site_detect_tests.py
M tests/site_tests.py
M tests/tk_tests.py
M tests/tools_tests.py
M tests/ui_tests.py
M tests/utils.py
M tests/weblib_tests.py
23 files changed, 124 insertions(+), 124 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 8f2c918..f0b7084 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -27,11 +27,15 @@
if not PY2:
import queue as Queue
- basestring = (str,)
- unicode = str
+
+ StringTypes = basestring = (str,)
+ UnicodeType = unicode = str
else:
import Queue
+ StringTypes = types.StringTypes
+ UnicodeType = types.UnicodeType
+
from pywikibot.logging import debug
_logger = 'tools'
diff --git a/tests/__init__.py b/tests/__init__.py
index 5fa1e4b..290914d 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -10,7 +10,6 @@
__version__ = '$Id$'
import os
-import sys
import warnings
__all__ = ('requests', '_cache_dir', 'TestRequest',
@@ -20,23 +19,23 @@
# - requests is mandatory
# - future is needed as a fallback for python 2.6,
# however if unavailable this will fail on use; see pywikibot/tools.py
+# - unittest2; see below
# - mwparserfromhell is optional, so is only imported in textlib_tests
-try:
- import requests # noqa
-except ImportError as e:
- print("ImportError: %s" % e)
- sys.exit(1)
+import requests # noqa
-if sys.version_info < (2, 7, 3):
- # Unittest2 is a backport of python 2.7s unittest module to python 2.6
+from pywikibot.tools import PYTHON_VERSION
+
+if PYTHON_VERSION < (2, 7, 3):
+ # unittest2 is a backport of python 2.7s unittest module to python 2.6
# Also use unittest2 for python 2.7.2 (T106512)
import unittest2 as unittest
else:
import unittest
+import pywikibot.data.api
+
from pywikibot import config
from pywikibot import i18n
-import pywikibot.data.api
from pywikibot.data.api import Request as _original_Request
from pywikibot.data.api import CachedRequest
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 21f526b..c707617 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -15,10 +15,14 @@
import pywikibot.data.api as api
import pywikibot.family
import pywikibot.login
-import pywikibot.site
import pywikibot.page
+import pywikibot.site
-from pywikibot.tools import MediaWikiVersion, PY2
+from pywikibot.tools import (
+ MediaWikiVersion,
+ PY2,
+ UnicodeType,
+)
from tests.aspects import (
unittest,
@@ -30,7 +34,6 @@
if not PY2:
from urllib.parse import unquote_to_bytes
- unicode = str
else:
from urllib import unquote_plus as unquote_to_bytes
@@ -73,7 +76,7 @@
for param, value in self.assert_parameters.items():
self.assertIn(param, parameters)
if value is not None:
- if isinstance(value, unicode):
+ if isinstance(value, UnicodeType):
value = value.split('|')
self.assertLessEqual(set(value), parameters[param])
return self.data
diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py
index c77c07c..910cf9f 100644
--- a/tests/archivebot_tests.py
+++ b/tests/archivebot_tests.py
@@ -10,15 +10,16 @@
__version__ = '$Id$'
from datetime import datetime
-import sys
+
import pywikibot
import pywikibot.page
-from pywikibot.textlib import TimeStripper
-from scripts import archivebot
-from tests.aspects import unittest, TestCase
-if sys.version_info[0] > 2:
- basestring = (str,)
+from pywikibot.textlib import TimeStripper
+from pywikibot.tools import StringTypes as basestring
+
+from scripts import archivebot
+
+from tests.aspects import unittest, TestCase
THREADS = {
'als': 4, 'ar': 1, 'bar': 0, 'bg': 0, 'bjn':
1, 'bs': 0, 'ca': 5, 'ckb': 2,
diff --git a/tests/aspects.py b/tests/aspects.py
index e2b65a7..fa0e486 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -44,11 +44,12 @@
import pywikibot.config2 as config
from pywikibot import Site
-from pywikibot.exceptions import ServerError, NoUsername
-from pywikibot.site import BaseSite
-from pywikibot.family import WikimediaFamily
from pywikibot.comms import http
from pywikibot.data.api import Request as _original_Request
+from pywikibot.exceptions import ServerError, NoUsername
+from pywikibot.family import WikimediaFamily
+from pywikibot.site import BaseSite
+from pywikibot.tools import PY2
import tests
@@ -57,6 +58,8 @@
add_metaclass, execute_pwb, DrySite, DryRequest,
WarningSourceSkipContextManager,
)
+
+OSWIN32 = (sys.platform == 'win32')
class TestCaseBase(unittest.TestCase):
@@ -1309,7 +1312,7 @@
if 'PYWIKIBOT2_DIR' in os.environ:
self.orig_pywikibot_dir = os.environ['PYWIKIBOT2_DIR']
base_dir = pywikibot.config.base_dir
- if sys.platform == 'win32' and sys.version_info[0] < 3:
+ if OSWIN32 and PY2:
base_dir = str(base_dir)
os.environ[str('PYWIKIBOT2_DIR')] = base_dir
diff --git a/tests/bot_tests.py b/tests/bot_tests.py
index 4577029..c95b9d5 100644
--- a/tests/bot_tests.py
+++ b/tests/bot_tests.py
@@ -15,6 +15,7 @@
import pywikibot.bot
from pywikibot import i18n
+from pywikibot.tools import PY2
from tests.aspects import (
unittest, DefaultSiteTestCase, SiteAttributeTestCase, TestCase,
@@ -229,7 +230,7 @@
self.bot.site = self.de
with self.assertRaises(ValueError):
self.bot.site
- if sys.version_info[0] == 2:
+ if PY2:
# The exc_info still contains the AttributeError :/
sys.exc_clear()
self.bot.treat = self._treat(self._generator())
@@ -237,7 +238,7 @@
self.bot.run()
with self.assertRaises(ValueError):
self.bot.site
- if sys.version_info[0] == 2:
+ if PY2:
# The exc_info still contains the AttributeError :/
sys.exc_clear()
@@ -290,7 +291,7 @@
post_treat)
# TODO: sys.exc_info is empty in Python 3
- if sys.version_info[0] > 2:
+ if not PY2:
exc = None
else:
exc = KeyboardInterrupt
diff --git a/tests/family_tests.py b/tests/family_tests.py
index a676af9..d98570d 100644
--- a/tests/family_tests.py
+++ b/tests/family_tests.py
@@ -9,11 +9,11 @@
__version__ = '$Id$'
-from pywikibot.family import Family, SingleSiteFamily
-from pywikibot.exceptions import UnknownFamily
-from pywikibot.tools import PY2
-
import pywikibot.site
+
+from pywikibot.exceptions import UnknownFamily
+from pywikibot.family import Family, SingleSiteFamily
+from pywikibot.tools import StringTypes as basestring
from tests.aspects import (
unittest,
@@ -22,9 +22,6 @@
PatchingTestCase,
)
from tests.utils import DrySite
-
-if not PY2:
- basestring = (str, )
class TestFamily(TestCase):
diff --git a/tests/file_tests.py b/tests/file_tests.py
index 6dae36c..de459bc 100644
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -11,12 +11,9 @@
import pywikibot
-from pywikibot.tools import PY2
+from pywikibot.tools import UnicodeType as unicode
from tests.aspects import unittest, TestCase, DeprecationTestCase
-
-if not PY2:
- unicode = str
class TestShareFiles(TestCase):
diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index e8d2b33..899274c 100644
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -11,12 +11,9 @@
from pywikibot.exceptions import LockedPage
from pywikibot.flow import Board, Topic, Post
-from pywikibot.tools import PY2
+from pywikibot.tools import UnicodeType as unicode
from tests.aspects import TestCase
-
-if not PY2:
- unicode = str
class TestFlowCreateTopic(TestCase):
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
index ddb04c1..cf76536 100644
--- a/tests/flow_tests.py
+++ b/tests/flow_tests.py
@@ -11,19 +11,15 @@
from pywikibot.exceptions import NoPage
from pywikibot.flow import Board, Topic, Post
-from pywikibot.tools import PY2
+from pywikibot.tools import UnicodeType as unicode
from tests.aspects import (
TestCase,
)
-
from tests.basepage_tests import (
BasePageMethodsTestBase,
BasePageLoadRevisionsCachingTestBase,
)
-
-if not PY2:
- unicode = str
class TestBoardBasePageMethods(BasePageMethodsTestBase):
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 8fcbe9b..41c3c29 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -11,7 +11,6 @@
import os
import re
-import sys
import warnings
import requests
@@ -20,12 +19,13 @@
from pywikibot import config2 as config
from pywikibot.comms import http, threadedhttp
+from pywikibot.tools import (
+ PYTHON_VERSION,
+ UnicodeType as unicode,
+)
from tests import _images_dir
from tests.aspects import unittest, TestCase, DeprecationTestCase
-
-if sys.version_info[0] > 2:
- unicode = str
class HttpTestCase(TestCase):
@@ -281,7 +281,7 @@
self.assertNotIn('(;', http.user_agent())
self.assertNotIn(';)', http.user_agent())
self.assertIn('requests/', http.user_agent())
- self.assertIn('Python/' + str(sys.version_info[0]), http.user_agent())
+ self.assertIn('Python/' + str(PYTHON_VERSION[0]), http.user_agent())
class CharsetTestCase(TestCase):
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 9ff5913..3b5340d 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -9,16 +9,12 @@
__version__ = '$Id$'
-import sys
-
import pywikibot
from pywikibot import i18n, bot, plural
+from pywikibot.tools import StringTypes
from tests.aspects import unittest, TestCase, DefaultSiteTestCase, PwbTestCase
-
-if sys.version_info[0] == 3:
- basestring = (str, )
class TestTranslate(TestCase):
@@ -130,7 +126,7 @@
@classmethod
def setUpClass(cls):
"""Verify that the test translations are not
empty."""
- if not isinstance(cls.message_package, basestring):
+ if not isinstance(cls.message_package, StringTypes):
raise TypeError('%s.message_package must be a package name'
% cls.__name__)
# The call to set_messages_package below exists only to confirm
diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py
index 7bd126e..b43c770 100644
--- a/tests/logentry_tests.py
+++ b/tests/logentry_tests.py
@@ -10,19 +10,19 @@
__version__ = '$Id$'
import datetime
-import sys
import pywikibot
+
from pywikibot.logentries import LogEntryFactory
-from pywikibot.tools import MediaWikiVersion
+from pywikibot.tools import (
+ MediaWikiVersion,
+ UnicodeType as unicode,
+)
from tests.aspects import (
unittest, MetaTestCaseClass, TestCase, DeprecationTestCase
)
from tests.utils import add_metaclass
-
-if sys.version_info[0] > 2:
- unicode = str
class TestLogentriesBase(TestCase):
diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py
index 7cce7c5..2ed8bf9 100644
--- a/tests/namespace_tests.py
+++ b/tests/namespace_tests.py
@@ -10,13 +10,15 @@
__version__ = '$Id$'
from collections import Iterable
-from pywikibot.site import Namespace, NamespacesDict
-from tests.aspects import unittest, TestCase, AutoDeprecationTestCase
-import sys
-if sys.version_info[0] > 2:
- basestring = (str, )
- unicode = str
+from pywikibot.site import Namespace, NamespacesDict
+from pywikibot.tools import (
+ PY2,
+ StringTypes as basestring,
+ UnicodeType as unicode,
+)
+
+from tests.aspects import unittest, TestCase, AutoDeprecationTestCase
# Default namespaces which should work in any MW wiki
_base_builtin_ns = {
@@ -126,7 +128,7 @@
aliases=[u'Image', u'Immagine'], **kwargs)
self.assertEqual(str(y), ':File:')
- if sys.version_info[0] <= 2:
+ if PY2:
self.assertEqual(unicode(y), u':ملف:')
self.assertEqual(y.canonical_prefix(), ':File:')
self.assertEqual(y.custom_prefix(), u':ملف:')
diff --git a/tests/page_tests.py b/tests/page_tests.py
index a8359a8..079fb3e 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -9,22 +9,22 @@
__version__ = '$Id$'
-import sys
import pywikibot
-from pywikibot import config
-from pywikibot import InvalidTitle
import pywikibot.page
-from pywikibot.tools import PY2
+from pywikibot import config
+from pywikibot import InvalidTitle
+
+from pywikibot.tools import (
+ PY2,
+ StringTypes as basestring,
+ UnicodeType as unicode,
+)
from tests.aspects import (
unittest, TestCase, DefaultSiteTestCase, SiteAttributeTestCase,
DefaultDrySiteTestCase, DeprecationTestCase,
)
-
-if sys.version_info[0] > 2:
- basestring = (str, )
- unicode = str
class TestLinkObject(SiteAttributeTestCase):
@@ -568,14 +568,14 @@
page = pywikibot.Page(self.get_site(), u'Ō')
self.assertEqual(repr(page), b'Page(\xc5\x8c)')
- @unittest.skipIf(sys.version_info[0] > 2, 'Python 2 specific test')
+ @unittest.skipIf(not PY2, 'Python 2 specific test')
def test_unicode_percent_r_failure(self):
"""Test
u'{x!r}'.format(Page(u'<non-ascii>')) raises exception on Python
2."""
# This raises an exception on Python 2, but passes on Python 3
page = pywikibot.Page(self.get_site(), u'Ō')
self.assertRaisesRegex(UnicodeDecodeError, '', unicode.format,
u'{0!r}', page)
- @unittest.skipIf(sys.version_info[0] < 3, 'Python 3+ specific test')
+ @unittest.skipIf(PY2, 'Python 3+ specific test')
def test_unicode_value_py3(self):
"""Test to capture actual Python 3 result pre
unicode_literals."""
self.assertEqual(repr(self.page), "Page('Ō')")
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 8bbe085..fa07b17 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -11,12 +11,15 @@
import os
import sys
+from pywikibot.tools import (
+ PY2,
+ PYTHON_VERSION,
+ StringTypes,
+)
+
from tests import _root_dir
from tests.aspects import unittest, DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase
from tests.utils import allowed_failure, execute_pwb, add_metaclass
-
-if sys.version_info[0] > 2:
- basestring = (str, )
scripts_path = os.path.join(_root_dir, 'scripts')
@@ -36,11 +39,11 @@
'weblinkchecker.py': ['memento_client'],
}
-if sys.version_info < (2, 7):
+if PYTHON_VERSION < (2, 7):
script_deps['replicate_wiki'] = ['argparse']
script_deps['editarticle'] = ['argparse']
-if sys.version_info < (3, 0):
+if PY2:
script_deps['data_ingestion'] = ['unicodecsv']
@@ -150,7 +153,7 @@
'upload': 'ERROR: Upload error',
}
-if sys.version_info[0] > 2:
+if not PY2:
no_args_expected_results['replicate_wiki'] = (
'error: the following arguments are required: destination')
else:
@@ -238,7 +241,7 @@
if self._results and script_name in self._results:
error = self._results[script_name]
- if isinstance(error, basestring):
+ if isinstance(error, StringTypes):
stdout = None
else:
stdout, error = error
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index cfde088..2da5730 100644
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -13,12 +13,9 @@
from pywikibot.exceptions import ServerError
from pywikibot.site_detect import MWSite
-from pywikibot.tools import MediaWikiVersion, PY2
+from pywikibot.tools import MediaWikiVersion
from tests.aspects import unittest, TestCase
-
-if not PY2:
- basestring = (str,)
class TestWikiSiteDetection(TestCase):
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 26227d0..85bdefd 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -9,23 +9,26 @@
__version__ = '$Id$'
-
import json
-import sys
import os
+import re
+import sys
+
from collections import Iterable, Mapping
from datetime import datetime, timedelta
-import re
import pywikibot
from pywikibot import config
-from pywikibot import async_request, page_put_queue
from pywikibot.comms import http
from pywikibot.data import api
+
+from pywikibot import async_request, page_put_queue
from pywikibot.tools import (
MediaWikiVersion,
PY2,
+ StringTypes as basestring,
+ UnicodeType as unicode,
)
from tests.aspects import (
@@ -38,12 +41,8 @@
DefaultWikidataClientTestCase,
AlteredDefaultSiteTestCase,
)
-from tests.utils import allowed_failure, allowed_failure_if, entered_loop
from tests.basepage_tests import BasePageLoadRevisionsCachingTestBase
-
-if sys.version_info[0] > 2:
- basestring = (str, )
- unicode = str
+from tests.utils import allowed_failure, allowed_failure_if, entered_loop
class TokenTestBase(TestCaseBase):
@@ -2015,7 +2014,7 @@
self.assertNotIn(not_exists, mysite.siteinfo)
self.assertEqual(len(mysite.siteinfo.get(not_exists)), 0)
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists)))
- if sys.version_info[0] == 2:
+ if PY2:
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).iteritems()))
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).itervalues()))
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).iterkeys()))
diff --git a/tests/tk_tests.py b/tests/tk_tests.py
index cc430fa..42fb2c4 100644
--- a/tests/tk_tests.py
+++ b/tests/tk_tests.py
@@ -9,12 +9,12 @@
__version__ = '$Id$'
-
import os
-import sys
+
+from pywikibot.tools import PY2
if os.environ.get('PYWIKIBOT2_TEST_GUI', '0') == '1':
- if sys.version_info[0] > 2:
+ if not PY2:
import tkinter as Tkinter
else:
import Tkinter
diff --git a/tests/tools_tests.py b/tests/tools_tests.py
index 2c63736..acbb7ac 100644
--- a/tests/tools_tests.py
+++ b/tests/tools_tests.py
@@ -13,7 +13,6 @@
import decimal
import os.path
import subprocess
-import sys
import tempfile
from pywikibot import tools
@@ -430,7 +429,7 @@
deduper = tools.filter_unique(self.strs, container=deduped, key=hash)
self._test_dedup_str(deduped, deduper, hash)
- @expected_failure_if(sys.version_info[0] >= 3)
+ @expected_failure_if(not tools.PY2)
def test_str_id(self):
"""Test str using id as key fails on Python 3."""
# str in Python 3 behave like objects.
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index fb8ef3c..e47fdbe 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -60,16 +60,16 @@
from pywikibot.bot import (
ui, DEBUG, VERBOSE, INFO, STDOUT, INPUT, WARNING, ERROR, CRITICAL
)
-from pywikibot.tools import PY2
+from pywikibot.tools import (
+ PY2,
+ UnicodeType as unicode,
+)
from pywikibot.userinterfaces import (
terminal_interface_win32, terminal_interface_base, terminal_interface_unix,
)
from tests.aspects import TestCase
from tests.utils import unittest, FakeModule
-
-if sys.version_info[0] > 2:
- unicode = str
class Stream(object):
@@ -86,7 +86,7 @@
the patched stream.
@type patched_streams: dict
"""
- self._stream = io.StringIO() if sys.version_info[0] > 2 else io.BytesIO()
+ self._stream = io.StringIO() if not PY2 else io.BytesIO()
self._name = 'std{0}'.format(name)
self._original = getattr(sys, self._name)
patched_streams[self._original] = self._stream
@@ -172,7 +172,7 @@
newstderr = strerr._stream
newstdin = strin._stream
-if sys.version_info[0] == 2:
+if PY2:
# In Python 2 the sys.std* streams use bytes instead of unicode
# But this module is using unicode_literals so '…' will generate unicode
# So it'll convert those back into bytes
@@ -229,7 +229,7 @@
unpatch()
def _encode(self, string, encoding='utf-8'):
- if sys.version_info[0] > 2:
+ if not PY2:
return string
else:
return string.encode(encoding)
diff --git a/tests/utils.py b/tests/utils.py
index 6d29604..e5ba6be 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -22,10 +22,10 @@
from types import ModuleType
from warnings import warn
-if sys.version_info[0] > 2:
- import six
+from pywikibot.tools import PY2
- unicode = str
+if not PY2:
+ import six
import pywikibot
@@ -34,10 +34,15 @@
from pywikibot.site import Namespace
from pywikibot.data.api import CachedRequest
from pywikibot.data.api import Request as _original_Request
-from pywikibot.tools import PYTHON_VERSION
+from pywikibot.tools import (
+ PYTHON_VERSION,
+ UnicodeType as unicode,
+)
from tests import _pwb_py
from tests import unittest # noqa
+
+OSWIN32 = (sys.platform == 'win32')
class DrySiteNote(RuntimeWarning):
@@ -104,7 +109,7 @@
def add_metaclass(cls):
"""Call six's add_metaclass with the site's __metaclass__ in
Python 3."""
- if sys.version_info[0] > 2:
+ if not PY2:
return six.add_metaclass(cls.__metaclass__)(cls)
else:
assert cls.__metaclass__
@@ -564,7 +569,7 @@
# sys.path may have been modified by the test runner to load dependencies.
pythonpath = os.pathsep.join(sys.path)
- if sys.platform == 'win32' and sys.version_info[0] < 3:
+ if OSWIN32 and PY2:
pythonpath = str(pythonpath)
env[str('PYTHONPATH')] = pythonpath
env[str('PYTHONIOENCODING')] = str(config.console_encoding)
@@ -574,7 +579,7 @@
env[str('LC_ALL')] = str(pywikibot.config.userinterface_lang)
# Set EDITOR to an executable that ignores all arguments and does nothing.
- env[str('EDITOR')] = str('call' if sys.platform == 'win32'
else 'true')
+ env[str('EDITOR')] = str('call' if OSWIN32 else 'true')
options = {
'stdout': subprocess.PIPE,
@@ -587,7 +592,7 @@
p = subprocess.Popen(command, env=env, **options)
except TypeError as e:
# Generate a more informative error
- if sys.platform == 'win32' and sys.version_info[0] < 3:
+ if OSWIN32 and PY2:
unicode_env = [(k, v) for k, v in os.environ.items()
if not isinstance(k, str) or
not isinstance(v, str)]
diff --git a/tests/weblib_tests.py b/tests/weblib_tests.py
index d1e93aa..769080c 100644
--- a/tests/weblib_tests.py
+++ b/tests/weblib_tests.py
@@ -9,8 +9,9 @@
__version__ = '$Id$'
-import sys
-if sys.version_info[0] > 2:
+from pywikibot.tools import PY2
+
+if not PY2:
from urllib.parse import urlparse
else:
from urlparse import urlparse
--
To view, visit
https://gerrit.wikimedia.org/r/239559
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie72f8df1dabe988d62bbc6337512df6b5daf47b7
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Mattflaschen <mflaschen(a)wikimedia.org>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>