aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Danno <vincent.danno@orange.com>2021-05-26 13:08:55 +0200
committerVincent Danno <vincent.danno@orange.com>2021-06-01 20:40:32 +0200
commita656fd764b0a608caaf198bfa9685a09a7eaca16 (patch)
tree501fa47e06658b8a43e2ccca4837c530a49dfc72
parent6192b2cf9ffd46bdb8189ce3236cf4d9b722b69c (diff)
Drop six
python 2 was dropped [1] so we don't need six anymore [1]: https://gerrit.opnfv.org/gerrit/c/functest-xtesting/+/68262 Signed-off-by: Vincent Danno <vincent.danno@orange.com> Change-Id: I840211990b76f77a46e9e737fc4a4c857b57c0b2
-rw-r--r--requirements.txt1
-rw-r--r--xtesting/ci/run_tests.py3
-rw-r--r--xtesting/core/behaveframework.py8
-rw-r--r--xtesting/core/campaign.py10
-rw-r--r--xtesting/core/feature.py4
-rw-r--r--xtesting/core/mts.py20
-rw-r--r--xtesting/core/robotframework.py2
-rw-r--r--xtesting/core/testcase.py21
-rw-r--r--xtesting/core/unit.py5
-rw-r--r--xtesting/samples/first.py4
-rw-r--r--xtesting/samples/second.py4
-rw-r--r--xtesting/tests/unit/ci/test_run_tests.py4
-rw-r--r--xtesting/tests/unit/ci/test_tier_builder.py2
-rw-r--r--xtesting/tests/unit/core/test_behaveframework.py27
-rw-r--r--xtesting/tests/unit/core/test_feature.py28
-rw-r--r--xtesting/tests/unit/core/test_unit.py22
-rw-r--r--xtesting/tests/unit/utils/test_env.py5
-rw-r--r--xtesting/utils/decorators.py6
18 files changed, 75 insertions, 101 deletions
diff --git a/requirements.txt b/requirements.txt
index 7e4804d1..73948674 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -11,7 +11,6 @@ behave>=1.2.6
behave-html-formatter>=0.9.4;python_version>='3.6'
mock!=4.0.0,!=4.0.1 # BSD
PrettyTable<0.8 # BSD
-six # MIT
python-subunit # Apache-2.0/BSD
os-testr # Apache-2.0
junitxml
diff --git a/xtesting/ci/run_tests.py b/xtesting/ci/run_tests.py
index 989969bc..4477dedd 100644
--- a/xtesting/ci/run_tests.py
+++ b/xtesting/ci/run_tests.py
@@ -25,7 +25,6 @@ import textwrap
import enum
import pkg_resources
import prettytable
-import six
from stevedore import driver
import yaml
@@ -311,7 +310,7 @@ def main():
os.makedirs(constants.RESULTS_DIR)
except OSError as ex:
if ex.errno != errno.EEXIST:
- six.print_("{} {}".format("Cannot create", constants.RESULTS_DIR))
+ print("{} {}".format("Cannot create", constants.RESULTS_DIR))
return testcase.TestCase.EX_RUN_ERROR
if env.get('DEBUG').lower() == 'true':
logging.config.fileConfig(pkg_resources.resource_filename(
diff --git a/xtesting/core/behaveframework.py b/xtesting/core/behaveframework.py
index dba556f4..e288fff8 100644
--- a/xtesting/core/behaveframework.py
+++ b/xtesting/core/behaveframework.py
@@ -16,7 +16,6 @@ import os
import time
import json
-import six
from behave.__main__ import main as behave_main
@@ -92,10 +91,9 @@ class BehaveFramework(testcase.TestCase):
config = ['--tags='+','.join(tags),
'--junit', '--junit-directory={}'.format(self.res_dir),
'--format=json', '--outfile={}'.format(self.json_file)]
- if six.PY3:
- html_file = os.path.join(self.res_dir, 'output.html')
- config += ['--format=behave_html_formatter:HTMLFormatter',
- '--outfile={}'.format(html_file)]
+ html_file = os.path.join(self.res_dir, 'output.html')
+ config += ['--format=behave_html_formatter:HTMLFormatter',
+ '--outfile={}'.format(html_file)]
if kwargs.get("console", False):
config += ['--format=pretty', '--outfile=-']
for feature in suites:
diff --git a/xtesting/core/campaign.py b/xtesting/core/campaign.py
index 51a145c1..58747681 100644
--- a/xtesting/core/campaign.py
+++ b/xtesting/core/campaign.py
@@ -17,12 +17,12 @@ import os
import re
import zipfile
+from urllib.parse import urlparse
import boto3
from boto3.s3.transfer import TransferConfig
import botocore
import pkg_resources
import requests
-from six.moves import urllib
from xtesting.core import testcase
from xtesting.utils import env
@@ -120,9 +120,9 @@ class Campaign():
multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[
"S3_ENDPOINT_URL"] else 8 * 1024 * 1024
config = TransferConfig(multipart_threshold=multipart_threshold)
- bucket_name = urllib.parse.urlparse(dst_s3_url).netloc
+ bucket_name = urlparse(dst_s3_url).netloc
s3path = re.search(
- '^/*(.*)/*$', urllib.parse.urlparse(dst_s3_url).path).group(1)
+ '^/*(.*)/*$', urlparse(dst_s3_url).path).group(1)
prefix = os.path.join(s3path, build_tag)
# pylint: disable=no-member
for s3_object in b3resource.Bucket(bucket_name).objects.filter(
@@ -183,9 +183,9 @@ class Campaign():
multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[
"S3_ENDPOINT_URL"] else 8 * 1024 * 1024
config = TransferConfig(multipart_threshold=multipart_threshold)
- bucket_name = urllib.parse.urlparse(dst_s3_url).netloc
+ bucket_name = urlparse(dst_s3_url).netloc
mime_type = mimetypes.guess_type('{}.zip'.format(build_tag))
- path = urllib.parse.urlparse(dst_s3_url).path.strip("/")
+ path = urlparse(dst_s3_url).path.strip("/")
# pylint: disable=no-member
b3resource.Bucket(bucket_name).upload_file(
'{}.zip'.format(build_tag),
diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py
index 3b2a19f2..f92858bd 100644
--- a/xtesting/core/feature.py
+++ b/xtesting/core/feature.py
@@ -20,15 +20,13 @@ import subprocess
import sys
import time
-import six
from xtesting.core import testcase
__author__ = ("Serena Feng <feng.xiaowei@zte.com.cn>, "
"Cedric Ollivier <cedric.ollivier@orange.com>")
-@six.add_metaclass(abc.ABCMeta)
-class Feature(testcase.TestCase):
+class Feature(testcase.TestCase, metaclass=abc.ABCMeta):
"""Base model for single feature."""
__logger = logging.getLogger(__name__)
diff --git a/xtesting/core/mts.py b/xtesting/core/mts.py
index d6865a61..6ced2530 100644
--- a/xtesting/core/mts.py
+++ b/xtesting/core/mts.py
@@ -25,7 +25,6 @@ import time
from lxml import etree
import prettytable
-import six
from xtesting.core import testcase
@@ -245,17 +244,14 @@ class MTSLauncher(testcase.TestCase):
if console:
sys.stdout.write(line.decode("utf-8"))
f_stdout.write(line.decode("utf-8"))
- if six.PY3:
- try:
- process.wait(timeout=max_duration)
- except subprocess.TimeoutExpired:
- process.kill()
- self.__logger.info(
- "Killing MTS process after %d second(s).",
- max_duration)
- return 3
- else:
- process.wait()
+ try:
+ process.wait(timeout=max_duration)
+ except subprocess.TimeoutExpired:
+ process.kill()
+ self.__logger.info(
+ "Killing MTS process after %d second(s).",
+ max_duration)
+ return 3
with open(self.result_file, 'r') as f_stdin:
self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip())
return process.returncode
diff --git a/xtesting/core/robotframework.py b/xtesting/core/robotframework.py
index a973e9a2..64ee352c 100644
--- a/xtesting/core/robotframework.py
+++ b/xtesting/core/robotframework.py
@@ -14,12 +14,12 @@ from __future__ import division
import logging
import os
+from io import StringIO
import robot.api
from robot.errors import RobotError
from robot.reporting import resultwriter
import robot.run
from robot.utils.robottime import timestamp_to_secs
-from six import StringIO
from xtesting.core import testcase
diff --git a/xtesting/core/testcase.py b/xtesting/core/testcase.py
index 08ce426b..15936f1d 100644
--- a/xtesting/core/testcase.py
+++ b/xtesting/core/testcase.py
@@ -16,15 +16,13 @@ import logging
import mimetypes
import os
import re
-import sys
+from urllib.parse import urlparse
import boto3
from boto3.s3.transfer import TransferConfig
import botocore
import prettytable
import requests
-import six
-from six.moves import urllib
from xtesting.utils import decorators
from xtesting.utils import env
@@ -33,8 +31,7 @@ from xtesting.utils import constants
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
-@six.add_metaclass(abc.ABCMeta)
-class TestCase():
+class TestCase(metaclass=abc.ABCMeta):
# pylint: disable=too-many-instance-attributes
"""Base model for single test case."""
@@ -238,7 +235,7 @@ class TestCase():
url, data=json.dumps(data, sort_keys=True),
headers=self.headers)
req.raise_for_status()
- if urllib.parse.urlparse(url).scheme != "file":
+ if urlparse(url).scheme != "file":
# href must be postprocessed as OPNFV testapi is misconfigured
# (localhost is returned)
uid = re.sub(r'^.*/api/v1/results/*', '', req.json()["href"])
@@ -289,7 +286,7 @@ class TestCase():
multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[
"S3_ENDPOINT_URL"] else 8 * 1024 * 1024
config = TransferConfig(multipart_threshold=multipart_threshold)
- bucket_name = urllib.parse.urlparse(dst_s3_url).netloc
+ bucket_name = urlparse(dst_s3_url).netloc
try:
b3resource.meta.client.head_bucket(Bucket=bucket_name)
except botocore.exceptions.ClientError as exc:
@@ -298,12 +295,10 @@ class TestCase():
# pylint: disable=no-member
b3resource.create_bucket(Bucket=bucket_name)
else:
- typ, value, traceback = sys.exc_info()
- six.reraise(typ, value, traceback)
- except Exception: # pylint: disable=broad-except
- typ, value, traceback = sys.exc_info()
- six.reraise(typ, value, traceback)
- path = urllib.parse.urlparse(dst_s3_url).path.strip("/")
+ raise exc
+ except Exception as exc: # pylint: disable=broad-except
+ raise exc
+ path = urlparse(dst_s3_url).path.strip("/")
dst_http_url = os.environ["HTTP_DST_URL"]
output_str = "\n"
self.details["links"] = []
diff --git a/xtesting/core/unit.py b/xtesting/core/unit.py
index 877cd073..9d549a2d 100644
--- a/xtesting/core/unit.py
+++ b/xtesting/core/unit.py
@@ -10,7 +10,7 @@
"""Define the parent class to run unittest.TestSuite as TestCase."""
from __future__ import division
-
+from io import BytesIO
import logging
import os
import shutil
@@ -19,7 +19,6 @@ import time
import unittest
from subunit.run import SubunitTestRunner
-import six
from xtesting.core import testcase
@@ -112,7 +111,7 @@ class Suite(testcase.TestCase):
self.start_time = time.time()
if not os.path.isdir(self.res_dir):
os.makedirs(self.res_dir)
- stream = six.BytesIO()
+ stream = BytesIO()
result = SubunitTestRunner(
stream=stream, verbosity=2).run(self.suite).decorated
self.generate_stats(stream)
diff --git a/xtesting/samples/first.py b/xtesting/samples/first.py
index e8a17b23..5e240ed8 100644
--- a/xtesting/samples/first.py
+++ b/xtesting/samples/first.py
@@ -11,8 +11,6 @@
import time
-import six
-
from xtesting.core import testcase
@@ -20,6 +18,6 @@ class Test(testcase.TestCase):
def run(self, **kwargs):
self.start_time = time.time()
- six.print_("Hello World")
+ print("Hello World")
self.result = 100
self.stop_time = time.time()
diff --git a/xtesting/samples/second.py b/xtesting/samples/second.py
index 5e1b105b..af198e19 100644
--- a/xtesting/samples/second.py
+++ b/xtesting/samples/second.py
@@ -9,13 +9,11 @@
# pylint: disable=missing-docstring
-import six
-
from xtesting.core import feature
class Test(feature.Feature):
def execute(self, **kwargs):
- six.print_("Hello World")
+ print("Hello World")
return 0
diff --git a/xtesting/tests/unit/ci/test_run_tests.py b/xtesting/tests/unit/ci/test_run_tests.py
index 423bf486..b206a493 100644
--- a/xtesting/tests/unit/ci/test_run_tests.py
+++ b/xtesting/tests/unit/ci/test_run_tests.py
@@ -94,7 +94,7 @@ class RunTestsTesting(unittest.TestCase):
except Exception: # pylint: disable=broad-except
pass
envfile = 'rc_file'
- with mock.patch('six.moves.builtins.open',
+ with mock.patch('builtins.open',
mock.mock_open(read_data=msg)) as mock_method,\
mock.patch('os.path.isfile', return_value=True):
mock_method.return_value.__iter__ = lambda self: iter(
@@ -117,7 +117,7 @@ class RunTestsTesting(unittest.TestCase):
'export "\'OS_TENANT_NAME\'" = "\'admin\'"')
def test_get_dict_by_test(self):
- with mock.patch('six.moves.builtins.open', mock.mock_open()), \
+ with mock.patch('builtins.open', mock.mock_open()), \
mock.patch('yaml.safe_load') as mock_yaml:
mock_obj = mock.Mock()
testcase_dict = {'case_name': 'testname',
diff --git a/xtesting/tests/unit/ci/test_tier_builder.py b/xtesting/tests/unit/ci/test_tier_builder.py
index 70b5aeae..091142e2 100644
--- a/xtesting/tests/unit/ci/test_tier_builder.py
+++ b/xtesting/tests/unit/ci/test_tier_builder.py
@@ -38,7 +38,7 @@ class TierBuilderTesting(unittest.TestCase):
with mock.patch('xtesting.ci.tier_builder.yaml.safe_load',
return_value=self.mock_yaml), \
- mock.patch('six.moves.builtins.open', mock.mock_open()):
+ mock.patch('builtins.open', mock.mock_open()):
os.environ["INSTALLER_TYPE"] = 'test_installer'
os.environ["DEPLOY_SCENARIO"] = 'test_scenario'
self.tierbuilder = tier_builder.TierBuilder('testcases_file')
diff --git a/xtesting/tests/unit/core/test_behaveframework.py b/xtesting/tests/unit/core/test_behaveframework.py
index 754813ab..72fa6f29 100644
--- a/xtesting/tests/unit/core/test_behaveframework.py
+++ b/xtesting/tests/unit/core/test_behaveframework.py
@@ -14,7 +14,6 @@ import os
import unittest
import mock
-import six
from xtesting.core import behaveframework
@@ -32,26 +31,26 @@ class ParseResultTesting(unittest.TestCase):
self.test = behaveframework.BehaveFramework(
case_name='behave', project_name='xtesting')
- @mock.patch('six.moves.builtins.open', side_effect=OSError)
+ @mock.patch('builtins.open', side_effect=OSError)
def test_raises_exc_open(self, *args): # pylint: disable=unused-argument
with self.assertRaises(OSError):
self.test.parse_results()
@mock.patch('json.load', return_value=[{'foo': 'bar'}])
- @mock.patch('six.moves.builtins.open', mock.mock_open())
+ @mock.patch('builtins.open', mock.mock_open())
def test_raises_exc_key(self, *args): # pylint: disable=unused-argument
with self.assertRaises(KeyError):
self.test.parse_results()
@mock.patch('json.load', return_value=[])
- @mock.patch('six.moves.builtins.open', mock.mock_open())
+ @mock.patch('builtins.open', mock.mock_open())
def test_raises_exe_zerodivision(self, *args):
# pylint: disable=unused-argument
with self.assertRaises(ZeroDivisionError):
self.test.parse_results()
def _test_result(self, response, result):
- with mock.patch('six.moves.builtins.open', mock.mock_open()), \
+ with mock.patch('builtins.open', mock.mock_open()), \
mock.patch('json.load', return_value=response):
self.test.parse_results()
self.assertEqual(self.test.result, result)
@@ -68,7 +67,7 @@ class ParseResultTesting(unittest.TestCase):
data = [{'status': 'passed'}, {'status': 'passed'}]
self._test_result(data, 100)
- @mock.patch('six.moves.builtins.open', mock.mock_open())
+ @mock.patch('builtins.open', mock.mock_open())
def test_count(self, *args): # pylint: disable=unused-argument
self._response.extend([{'status': 'failed'}, {'status': 'skipped'}])
with mock.patch('json.load', mock.Mock(return_value=self._response)):
@@ -121,11 +120,9 @@ class RunTesting(unittest.TestCase):
args_list = [
'--tags=', '--junit',
'--junit-directory={}'.format(self.test.res_dir),
- '--format=json', '--outfile={}'.format(self.test.json_file)]
- if six.PY3:
- args_list += [
- '--format=behave_html_formatter:HTMLFormatter',
- '--outfile={}'.format(html_file)]
+ '--format=json', '--outfile={}'.format(self.test.json_file),
+ '--format=behave_html_formatter:HTMLFormatter',
+ '--outfile={}'.format(html_file)]
args_list.append('foo')
args[0].assert_called_once_with(args_list)
mock_method.assert_called_once_with()
@@ -155,11 +152,9 @@ class RunTesting(unittest.TestCase):
args_list = [
'--tags=', '--junit',
'--junit-directory={}'.format(self.test.res_dir),
- '--format=json', '--outfile={}'.format(self.test.json_file)]
- if six.PY3:
- args_list += [
- '--format=behave_html_formatter:HTMLFormatter',
- '--outfile={}'.format(html_file)]
+ '--format=json', '--outfile={}'.format(self.test.json_file),
+ '--format=behave_html_formatter:HTMLFormatter',
+ '--outfile={}'.format(html_file)]
if console:
args_list += ['--format=pretty', '--outfile=-']
args_list.append('foo')
diff --git a/xtesting/tests/unit/core/test_feature.py b/xtesting/tests/unit/core/test_feature.py
index ab483b27..b36fa367 100644
--- a/xtesting/tests/unit/core/test_feature.py
+++ b/xtesting/tests/unit/core/test_feature.py
@@ -11,12 +11,12 @@
import os
+from io import BytesIO
import logging
import subprocess
import unittest
import mock
-import six
from xtesting.core import feature
from xtesting.core import testcase
@@ -73,7 +73,7 @@ class FeatureTesting(FeatureTestingBase):
# logging must be disabled else it calls time.time()
# what will break these unit tests.
logging.disable(logging.CRITICAL)
- with mock.patch('six.moves.builtins.open'):
+ with mock.patch('builtins.open'):
self.feature = FakeTestCase(
project_name=self._project_name, case_name=self._case_name)
@@ -95,7 +95,7 @@ class BashFeatureTesting(FeatureTestingBase):
# logging must be disabled else it calls time.time()
# what will break these unit tests.
logging.disable(logging.CRITICAL)
- with mock.patch('six.moves.builtins.open'):
+ with mock.patch('builtins.open'):
self.feature = feature.BashFeature(
project_name=self._project_name, case_name=self._case_name)
@@ -109,7 +109,7 @@ class BashFeatureTesting(FeatureTestingBase):
@mock.patch('subprocess.Popen',
side_effect=subprocess.CalledProcessError(0, '', ''))
def test_run_ko1(self, *args):
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run(testcase.TestCase.EX_RUN_ERROR)
mopen.assert_called_once_with(self._output_file, "w")
args[0].assert_called_once_with(
@@ -119,12 +119,12 @@ class BashFeatureTesting(FeatureTestingBase):
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('subprocess.Popen')
def test_run_ko2(self, *args):
- stream = six.BytesIO()
+ stream = BytesIO()
stream.write(b"foo")
stream.seek(0)
attrs = {'return_value.stdout': stream, 'return_value.returncode': 1}
args[0].configure_mock(**attrs)
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run(testcase.TestCase.EX_RUN_ERROR)
self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
@@ -135,12 +135,12 @@ class BashFeatureTesting(FeatureTestingBase):
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('subprocess.Popen')
def test_run1(self, *args):
- stream = six.BytesIO()
+ stream = BytesIO()
stream.write(b"foo")
stream.seek(0)
attrs = {'return_value.stdout': stream, 'return_value.returncode': 0}
args[0].configure_mock(**attrs)
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run(testcase.TestCase.EX_OK)
self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
@@ -151,12 +151,12 @@ class BashFeatureTesting(FeatureTestingBase):
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('subprocess.Popen')
def test_run2(self, *args):
- stream = six.BytesIO()
+ stream = BytesIO()
stream.write(b"foo")
stream.seek(0)
attrs = {'return_value.stdout': stream, 'return_value.returncode': 0}
args[0].configure_mock(**attrs)
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_console(True, testcase.TestCase.EX_OK)
self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
@@ -167,12 +167,12 @@ class BashFeatureTesting(FeatureTestingBase):
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('subprocess.Popen')
def test_run3(self, *args):
- stream = six.BytesIO()
+ stream = BytesIO()
stream.write(b"foo")
stream.seek(0)
attrs = {'return_value.stdout': stream, 'return_value.returncode': 0}
args[0].configure_mock(**attrs)
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_console(False, testcase.TestCase.EX_OK)
self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
@@ -184,12 +184,12 @@ class BashFeatureTesting(FeatureTestingBase):
@mock.patch('os.path.isdir', return_value=False)
@mock.patch('subprocess.Popen')
def test_run4(self, *args):
- stream = six.BytesIO()
+ stream = BytesIO()
stream.write(b"foo")
stream.seek(0)
attrs = {'return_value.stdout': stream, 'return_value.returncode': 0}
args[0].configure_mock(**attrs)
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ with mock.patch('builtins.open', mock.mock_open()) as mopen:
self._test_run_console(False, testcase.TestCase.EX_OK)
self.assertIn(mock.call(self._output_file, 'w'), mopen.mock_calls)
self.assertIn(mock.call(self._output_file, 'r'), mopen.mock_calls)
diff --git a/xtesting/tests/unit/core/test_unit.py b/xtesting/tests/unit/core/test_unit.py
index 3be41442..86577713 100644
--- a/xtesting/tests/unit/core/test_unit.py
+++ b/xtesting/tests/unit/core/test_unit.py
@@ -7,12 +7,12 @@
# pylint: disable=missing-docstring
+import io
import logging
import subprocess
import unittest
import mock
-import six
from xtesting.core import unit
from xtesting.core import testcase
@@ -26,7 +26,7 @@ class SuiteTesting(unittest.TestCase):
@mock.patch('subprocess.Popen', side_effect=Exception)
def test_generate_stats_ko(self, *args):
- stream = six.StringIO()
+ stream = io.StringIO()
with self.assertRaises(Exception):
self.psrunner.generate_stats(stream)
args[0].assert_called_once_with(
@@ -36,17 +36,17 @@ class SuiteTesting(unittest.TestCase):
return_value=mock.Mock(
communicate=mock.Mock(return_value=(b"foo", b"bar"))))
def test_generate_stats_ok(self, *args):
- stream = six.StringIO()
+ stream = io.StringIO()
self.psrunner.generate_stats(stream)
args[0].assert_called_once_with(
['subunit-stats'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- @mock.patch('six.moves.builtins.open', mock.mock_open())
+ @mock.patch('builtins.open', mock.mock_open())
@mock.patch('subprocess.Popen', side_effect=Exception)
def test_generate_xunit_ko(self, *args):
- stream = six.StringIO()
+ stream = io.StringIO()
with self.assertRaises(Exception), \
- mock.patch('six.moves.builtins.open',
+ mock.patch('builtins.open',
mock.mock_open()) as mock_open:
self.psrunner.generate_xunit(stream)
args[0].assert_called_once_with(
@@ -59,8 +59,8 @@ class SuiteTesting(unittest.TestCase):
return_value=mock.Mock(
communicate=mock.Mock(return_value=(b"foo", b"bar"))))
def test_generate_xunit_ok(self, *args):
- stream = six.BytesIO()
- with mock.patch('six.moves.builtins.open',
+ stream = io.BytesIO()
+ with mock.patch('builtins.open',
mock.mock_open()) as mock_open:
self.psrunner.generate_xunit(stream)
args[0].assert_called_once_with(
@@ -93,7 +93,7 @@ class SuiteTesting(unittest.TestCase):
@mock.patch('subunit.run.SubunitTestRunner.run')
def _test_run(self, mock_result, status, result, *args):
args[0].return_value = mock_result
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as m_open:
+ with mock.patch('builtins.open', mock.mock_open()) as m_open:
self.assertEqual(self.psrunner.run(), status)
m_open.assert_called_once_with(
'{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
@@ -112,7 +112,7 @@ class SuiteTesting(unittest.TestCase):
@mock.patch('subunit.run.SubunitTestRunner.run')
def _test_run_name(self, name, mock_result, status, result, *args):
args[0].return_value = mock_result
- with mock.patch('six.moves.builtins.open', mock.mock_open()) as m_open:
+ with mock.patch('builtins.open', mock.mock_open()) as m_open:
self.assertEqual(self.psrunner.run(name=name), status)
m_open.assert_called_once_with(
'{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
@@ -135,7 +135,7 @@ class SuiteTesting(unittest.TestCase):
decorated=mock.Mock(
testsRun=50, errors=[], failures=[]))
args[3].side_effect = exc
- with mock.patch('six.moves.builtins.open',
+ with mock.patch('builtins.open',
mock.mock_open()) as m_open:
self.assertEqual(
self.psrunner.run(), testcase.TestCase.EX_RUN_ERROR)
diff --git a/xtesting/tests/unit/utils/test_env.py b/xtesting/tests/unit/utils/test_env.py
index 08601fa5..83b1a19d 100644
--- a/xtesting/tests/unit/utils/test_env.py
+++ b/xtesting/tests/unit/utils/test_env.py
@@ -12,8 +12,7 @@
import logging
import os
import unittest
-
-from six.moves import reload_module
+import importlib
from xtesting.utils import env
@@ -32,7 +31,7 @@ class EnvTesting(unittest.TestCase):
def test_get_unknown_env(self):
self.assertEqual(env.get('FOO'), 'foo')
- reload_module(env)
+ importlib.reload(env)
def test_get_unset_env(self):
del os.environ['CI_LOOP']
diff --git a/xtesting/utils/decorators.py b/xtesting/utils/decorators.py
index 230a99e7..2ce12fa7 100644
--- a/xtesting/utils/decorators.py
+++ b/xtesting/utils/decorators.py
@@ -12,17 +12,17 @@
import errno
import functools
import os
+from urllib.parse import urlparse
import mock
import requests.sessions
-from six.moves import urllib
def can_dump_request_to_file(method):
def dump_preparedrequest(request, **kwargs):
# pylint: disable=unused-argument
- parseresult = urllib.parse.urlparse(request.url)
+ parseresult = urlparse(request.url)
if parseresult.scheme == "file":
try:
dirname = os.path.dirname(parseresult.path)
@@ -41,7 +41,7 @@ def can_dump_request_to_file(method):
def patch_request(method, url, **kwargs):
with requests.sessions.Session() as session:
- parseresult = urllib.parse.urlparse(url)
+ parseresult = urlparse(url)
if parseresult.scheme == "file":
with mock.patch.object(session, 'send',
side_effect=dump_preparedrequest):