From dfb6f5779bdfe59d5a4958f910d009b74d14b87f Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Tue, 19 Mar 2019 15:34:54 -0400 Subject: [PATCH] Python 2 leftovers: drop conditions and keep Python 3 only There's no need to keep the special conditions for Python 2, now that it's not supported anymore. Signed-off-by: Cleber Rosa --- avocado/utils/astring.py | 8 +------- avocado/utils/process.py | 11 ++--------- selftests/functional/test_basic.py | 18 +++++------------- selftests/functional/test_standalone.py | 10 ++-------- selftests/unit/test_astring.py | 6 +----- selftests/unit/test_utils_disk.py | 12 +++--------- 6 files changed, 14 insertions(+), 51 deletions(-) diff --git a/avocado/utils/astring.py b/avocado/utils/astring.py index 8e7b9176..5b989eb3 100644 --- a/avocado/utils/astring.py +++ b/avocado/utils/astring.py @@ -28,7 +28,6 @@ And not notice until their code starts failing. import itertools import locale import re -import sys import string from six import string_types, PY3 @@ -315,8 +314,6 @@ def is_text(data): That is, if it can hold text that requires more than one byte for each character. """ - if sys.version_info[0] < 3: - return isinstance(data, unicode) # pylint: disable=E0602 return isinstance(data, str) @@ -341,8 +338,5 @@ def to_text(data, encoding=ENCODING, errors='strict'): encoding = ENCODING return data.decode(encoding, errors=errors) elif not isinstance(data, string_types): - if sys.version_info[0] < 3: - return unicode(data) # pylint: disable=E0602 - else: - return str(data) + return str(data) return data diff --git a/avocado/utils/process.py b/avocado/utils/process.py index 20d54f41..c98f8391 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -28,7 +28,6 @@ import shutil import signal import stat import subprocess -import sys import threading import time @@ -312,14 +311,8 @@ def cmd_split(cmd): :param cmd: text (a multi byte string) encoded as 'utf-8' """ - if sys.version_info[0] < 3: - data = cmd.encode('utf-8') - result = shlex.split(data) - result = [i.decode('utf-8') for i in result] - else: - data = astring.to_text(cmd, 'utf-8') - result = shlex.split(data) - return result + data = astring.to_text(cmd, 'utf-8') + return shlex.split(data) class CmdResult(object): diff --git a/selftests/functional/test_basic.py b/selftests/functional/test_basic.py index 1f026504..97a0faa7 100644 --- a/selftests/functional/test_basic.py +++ b/selftests/functional/test_basic.py @@ -156,13 +156,9 @@ class RunnerOperationTest(unittest.TestCase): def test_show_version(self): result = process.run('%s -v' % AVOCADO, ignore_status=True) self.assertEqual(result.exit_status, 0) - if sys.version_info[0] == 3: - content = result.stdout_text - else: - content = result.stderr_text - self.assertTrue(re.match(r"^Avocado \d+\.\d+$", content), + self.assertTrue(re.match(r"^Avocado \d+\.\d+$", result.stdout_text), "Version string does not match 'Avocado \\d\\.\\d:'\n" - "%r" % (content)) + "%r" % (result.stdout_text)) def test_alternate_config_datadir(self): """ @@ -438,11 +434,8 @@ class RunnerOperationTest(unittest.TestCase): cmd_line = AVOCADO result = process.run(cmd_line, ignore_status=True) self.assertEqual(result.exit_status, exit_codes.AVOCADO_FAIL) - if sys.version_info[0] == 3: - exp = b'avocado: error: the following arguments are required' - else: - exp = b'error: too few arguments' - self.assertIn(exp, result.stderr) + self.assertIn(b'avocado: error: the following arguments are required', + result.stderr) def test_empty_test_list(self): cmd_line = '%s run --sysinfo=off --job-results-dir %s' % (AVOCADO, @@ -1120,8 +1113,7 @@ class PluginsTest(AbsPluginsTest, unittest.TestCase): self.assertEqual(result.exit_status, expected_rc, "Avocado did not return rc %d:\n%s" % (expected_rc, result)) - if sys.version_info[:2] >= (2, 7, 0): - self.assertNotIn(b'Disabled', result.stdout) + self.assertNotIn(b'Disabled', result.stdout) def test_config_plugin(self): cmd_line = '%s config --paginator off' % AVOCADO diff --git a/selftests/functional/test_standalone.py b/selftests/functional/test_standalone.py index 15d06bf3..f0bb6a33 100644 --- a/selftests/functional/test_standalone.py +++ b/selftests/functional/test_standalone.py @@ -48,10 +48,7 @@ class StandaloneTests(unittest.TestCase): cmd_line = '%s ./examples/tests/errortest_nasty.py -r' % PY_CMD expected_rc = exit_codes.AVOCADO_TESTS_FAIL result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty') - if sys.version_info[0] == 3: - exc = u"errortest_nasty.NastyException: Nasty-string-like-exception\u017e" - else: - exc = u"NastyException: Nasty-string-like-exception\\u017e" + exc = u"errortest_nasty.NastyException: Nasty-string-like-exception\u017e" count = result.stdout_text.count(u"\n%s" % exc) self.assertEqual(count, 2, "Exception \\n%s should be present twice in" "the log (once from the log, second time when parsing" @@ -68,10 +65,7 @@ class StandaloneTests(unittest.TestCase): cmd_line = '%s ./examples/tests/errortest_nasty3.py -r' % PY_CMD expected_rc = exit_codes.AVOCADO_TESTS_FAIL result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty3') - if sys.version_info[0] == 3: - exc = b"TypeError: exceptions must derive from BaseException" - else: - exc = b"TestError: