Skip to content

Commit 0018cc5

Browse files
s-t-e-v-e-n-kjonbannister
authored andcommitted
all: Remove all Python 2 requirements, such as six
Now that the minimum version of Python required is 3.6, we can remove all uses of six and future, along with some other test changes that still support Python 2. Fixes #209
1 parent ce6b157 commit 0018cc5

File tree

32 files changed

+87
-170
lines changed

32 files changed

+87
-170
lines changed

pytest-devpi-server/_pytest_devpi_server/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
44
@author: eeaston
55
'''
6+
import io
67
import os
78
import sys
89
import zipfile
910
import logging
10-
from six.moves import cStringIO
1111

1212
from pytest import yield_fixture, fixture
1313
import devpi_server as _devpi_server
@@ -105,7 +105,7 @@ def api(self, *args):
105105
client_args.extend(args)
106106
client_args.extend(['--clientdir', str(self.client_dir)])
107107
log.info(' '.join(client_args))
108-
captured = cStringIO()
108+
captured = io.StringIO()
109109
stdout = sys.stdout
110110
sys.stdout = captured
111111
try:

pytest-devpi-server/setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'pytest',
2323
'devpi-server>=3.0.1',
2424
'devpi-client',
25-
'six',
2625
'ruamel.yaml>=0.15',
2726
]
2827

pytest-fixture-config/setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
install_requires = ['pytest']
2222

23-
tests_require = ['six',
24-
]
23+
tests_require = []
2524

2625
if __name__ == '__main__':
2726
kwargs = common_setup('pytest_fixture_config')

pytest-fixture-config/tests/unit/test_fixture_config.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import importlib
2+
13
import pytest
2-
from six.moves import reload_module
34

45
# HACK: if the plugin is imported before the coverage plugin then all
56
# the top-level code will be omitted from coverage, so force it to be
67
# reloaded within this unit test under coverage
78
import pytest_fixture_config
8-
reload_module(pytest_fixture_config)
9+
importlib.reload(pytest_fixture_config)
910

1011
from pytest_fixture_config import Config, requires_config, yield_requires_config
1112

pytest-listener/pytest_listener.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import collections
44
import json
55
import logging
6+
import pickle
67
import socket
78
import time
89
from threading import Thread, Event
910
from time import sleep
1011

1112
import pytest
12-
from six import string_types
13-
from six.moves import cPickle
1413
from pytest_server_fixtures.base import get_ephemeral_port, get_ephemeral_host
1514

1615
TERMINATOR = json.dumps(['STOP']).encode('utf-8')
@@ -64,7 +63,7 @@ def __str__(self):
6463
return 'TimedMsg: %s (@ %s)' % (str(self.value), self.time)
6564

6665
def pickled(self):
67-
return cPickle.dumps(self)
66+
return pickle.dumps(self)
6867

6968

7069
class Listener(Thread):
@@ -119,7 +118,7 @@ def get_data(self):
119118
return None, None
120119

121120
try:
122-
data = cPickle.loads(data)
121+
data = pickle.loads(data)
123122
except:
124123
try:
125124
data = data.decode('utf-8')
@@ -133,7 +132,7 @@ def get_data(self):
133132
if isinstance(data, TimedMsg):
134133
d = data.value
135134
t = data.time
136-
elif isinstance(data, string_types):
135+
elif isinstance(data, str):
137136
try:
138137
d = json.loads(data)
139138
except:

pytest-listener/setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
'Programming Language :: Python :: 3.7',
1919
]
2020

21-
install_requires = ['six',
22-
'pytest',
21+
install_requires = ['pytest',
2322
'pytest-server-fixtures'
2423
]
2524

pytest-profiling/pytest_profiling.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""pytest: avoid already-imported warning: PYTEST_DONT_REWRITE."""
22

3-
from __future__ import absolute_import
4-
53
import sys
64
import os
75
import cProfile
@@ -10,16 +8,15 @@
108
from hashlib import md5
119
import subprocess
1210

13-
import six
1411
import pytest
1512

1613
LARGE_FILENAME_HASH_LEN = 8
1714

1815

1916
def clean_filename(s):
2017
forbidden_chars = set(r'/?<>\:*|"')
21-
return six.text_type("".join(c if c not in forbidden_chars and ord(c) < 127 else '_'
22-
for c in s))
18+
return str("".join(c if c not in forbidden_chars and ord(c) < 127 else '_'
19+
for c in s))
2320

2421

2522
class Profiling(object):

pytest-profiling/setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
'Programming Language :: Python :: 3.12',
2525
]
2626

27-
install_requires = ['six',
28-
'pytest',
27+
install_requires = ['pytest',
2928
'gprof2dot',
3029
]
3130

pytest-profiling/tests/unit/test_profile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# the top-level code in pytest_profiling will be omitted from
33
# coverage, so force it to be reloaded within this test unit under coverage
44

5+
import importlib
56
import os.path
6-
from six.moves import reload_module # @UnresolvedImport
77

88
import pytest_profiling
99

10-
reload_module(pytest_profiling)
10+
importlib.reload(pytest_profiling)
1111

1212
import os
1313
import subprocess

pytest-pyramid-server/pytest_pyramid_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
@author: eeaston
55
'''
6+
import configparser
67
import os
7-
from six.moves import configparser
88
import sys
99
import socket
1010
import glob

pytest-pyramid-server/setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
'pytest',
2424
'pyramid',
2525
'waitress',
26-
'six',
2726
]
2827

2928
tests_require = [

pytest-server-fixtures/pytest_server_fixtures/base.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import random
1515
import errno
1616

17-
from six import string_types
18-
1917
from pytest_server_fixtures import CONFIG
2018
from pytest_shutil.workspace import Workspace
2119

@@ -112,7 +110,7 @@ def __init__(self, process, stream, stderr):
112110
def run(self):
113111
while self.process.poll() is None:
114112
l = self.stream.readline()
115-
if not isinstance(l, string_types):
113+
if not isinstance(l, str):
116114
l = l.decode('utf-8')
117115

118116
if l.strip():

pytest-server-fixtures/pytest_server_fixtures/http.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import print_function
2-
1+
import http.client
32
import os
43
import socket
54
import logging
@@ -9,7 +8,6 @@
98
import pytest
109
import requests
1110
from contextlib import contextmanager
12-
from six.moves import http_client
1311

1412
from pytest_shutil.env import unset_env
1513
from pytest_server_fixtures import CONFIG
@@ -83,7 +81,7 @@ def get(self, path, as_json=False, attempts=25):
8381
with self.handle_proxy():
8482
returned = requests.get('http://%s:%d/%s' % (self.hostname, self.port, path))
8583
return returned.json() if as_json else returned
86-
except (http_client.BadStatusLine, requests.ConnectionError) as e:
84+
except (http.client.BadStatusLine, requests.ConnectionError) as e:
8785
time.sleep(int(i) / 10)
8886
pass
8987
raise e
@@ -109,7 +107,7 @@ def post(self, path, data=None, attempts=25, as_json=False, headers=None):
109107
with self.handle_proxy():
110108
returned = requests.post('http://%s:%d/%s' % (self.hostname, self.port, path), data=data, headers=headers)
111109
return returned.json() if as_json else returned
112-
except (http_client.BadStatusLine, requests.ConnectionError) as e:
110+
except (http.client.BadStatusLine, requests.ConnectionError) as e:
113111
time.sleep(int(i) / 10)
114112
pass
115113
raise e

pytest-server-fixtures/pytest_server_fixtures/jenkins.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
44
@author: eeaston
55
'''
6-
from __future__ import absolute_import
7-
86
import os.path
97
import shutil
108

119
import pytest
12-
import six
1310

1411
from pytest_server_fixtures import CONFIG
1512
from pytest_fixture_config import yield_requires_config
@@ -95,7 +92,7 @@ def load_plugins(self, plugins_repo, plugins=None):
9592
if plugins is None:
9693
plugins = available_plugins.keys()
9794
else:
98-
if isinstance(plugins, six.string_types):
95+
if isinstance(plugins, str):
9996
plugins = [plugins]
10097

10198
errors = []

pytest-server-fixtures/pytest_server_fixtures/postgres.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# coding: utf-8
22

3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
53
import os
64
import logging
75
import subprocess
86

97
import errno
108
import pytest
11-
from six import text_type
129

1310
from pytest_server_fixtures import CONFIG
1411
from pytest_fixture_config import requires_config
@@ -65,7 +62,7 @@ def pre_setup(self):
6562
try:
6663
self.pg_bin = subprocess.check_output([CONFIG.pg_config_executable, "--bindir"]).decode('utf-8').rstrip()
6764
except OSError as e:
68-
msg = "Failed to get pg_config --bindir: " + text_type(e)
65+
msg = "Failed to get pg_config --bindir: " + str(e)
6966
print(msg)
7067
self._fail(msg)
7168
initdb_path = self.pg_bin + '/initdb'
@@ -76,7 +73,7 @@ def pre_setup(self):
7673
try:
7774
subprocess.check_call([initdb_path, str(self.workspace / 'db')])
7875
except OSError as e:
79-
msg = "Failed to launch postgres: " + text_type(e)
76+
msg = "Failed to launch postgres: " + str(e)
8077
print(msg)
8178
self._fail(msg)
8279

pytest-server-fixtures/pytest_server_fixtures/redis.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
@author: eeaston
55
66
'''
7-
from __future__ import absolute_import
87
import socket
98

109
import pytest

pytest-server-fixtures/pytest_server_fixtures/s3.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
Pytest fixtures to launch a minio S3 server and get a bucket for it.
44
"""
55

6-
from __future__ import absolute_import, division, print_function, unicode_literals
7-
86
import uuid
97
from collections import namedtuple
108
import logging
119
import os
1210

1311
import pytest
14-
from future.utils import text_type
1512
from pytest_fixture_config import requires_config
1613

1714
from . import CONFIG
@@ -47,7 +44,7 @@ def s3_bucket(s3_server): # pylint: disable=redefined-outer-name
4744
returning a BucketInfo namedtuple with `s3_bucket.client` and `s3_bucket.name` fields
4845
"""
4946
client = s3_server.get_s3_client()
50-
bucket_name = text_type(uuid.uuid4())
47+
bucket_name = str(uuid.uuid4())
5148
client.create_bucket(Bucket=bucket_name)
5249
return BucketInfo(client, bucket_name)
5350

@@ -96,6 +93,6 @@ def run_cmd(self):
9693
"server",
9794
"--address",
9895
"{}:{}".format(self.hostname, self.port),
99-
text_type(self.datadir),
96+
str(self.datadir),
10097
]
10198
return cmdargs

pytest-server-fixtures/pytest_server_fixtures/serverclass/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Implementation of how a server fixture will run.
33
"""
44
# flake8: noqa
5-
from __future__ import absolute_import
65

76
def create_server(server_class, **kwargs):
87
if server_class == 'thread':

pytest-server-fixtures/pytest_server_fixtures/serverclass/docker.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
22
Docker server class implementation.
33
"""
4-
from __future__ import absolute_import
5-
64
import logging
75
import docker
86

pytest-server-fixtures/pytest_server_fixtures/serverclass/kubernetes.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Kubernetes server class implementation.
33
"""
4-
from __future__ import absolute_import
54

65
import os
76
import logging

pytest-server-fixtures/setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
install_requires = ['pytest',
2121
'pytest-shutil',
2222
'pytest-fixture-config',
23-
'six',
24-
'future',
2523
'requests',
2624
'retry',
2725
'psutil',

pytest-server-fixtures/tests/integration/test_s3_server.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import absolute_import, division, print_function, unicode_literals
4-
53

64
def test_connection(s3_bucket):
75
client, bucket_name = s3_bucket

pytest-shutil/pytest_shutil/cmdline.py

-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
from tempfile import mkdtemp
1111

1212

13-
try: # Python 2
14-
str_type = basestring
15-
except NameError: # Python 3
16-
str_type = str
17-
18-
1913
def get_log():
2014
return logging.getLogger(__name__)
2115

0 commit comments

Comments
 (0)