From a656fd764b0a608caaf198bfa9685a09a7eaca16 Mon Sep 17 00:00:00 2001 From: Vincent Danno Date: Wed, 26 May 2021 13:08:55 +0200 Subject: 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 Change-Id: I840211990b76f77a46e9e737fc4a4c857b57c0b2 --- xtesting/core/behaveframework.py | 8 +++----- xtesting/core/campaign.py | 10 +++++----- xtesting/core/feature.py | 4 +--- xtesting/core/mts.py | 20 ++++++++------------ xtesting/core/robotframework.py | 2 +- xtesting/core/testcase.py | 21 ++++++++------------- xtesting/core/unit.py | 5 ++--- 7 files changed, 28 insertions(+), 42 deletions(-) (limited to 'xtesting/core') 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 , " "Cedric Ollivier ") -@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 " -@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) -- cgit 1.2.3-korg