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/tests/unit/ci/test_run_tests.py | 4 ++-- xtesting/tests/unit/ci/test_tier_builder.py | 2 +- xtesting/tests/unit/core/test_behaveframework.py | 27 ++++++++++------------- xtesting/tests/unit/core/test_feature.py | 28 ++++++++++++------------ xtesting/tests/unit/core/test_unit.py | 22 +++++++++---------- xtesting/tests/unit/utils/test_env.py | 5 ++--- 6 files changed, 41 insertions(+), 47 deletions(-) (limited to 'xtesting/tests/unit') 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'] -- cgit 1.2.3-korg