Skip to content

Commit

Permalink
all: Remove all Python 2 requirements, such as six
Browse files Browse the repository at this point in the history
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 man-group#209
  • Loading branch information
s-t-e-v-e-n-k committed Nov 13, 2024
1 parent 5480ab9 commit 5b7dbb4
Show file tree
Hide file tree
Showing 32 changed files with 87 additions and 170 deletions.
4 changes: 2 additions & 2 deletions pytest-devpi-server/_pytest_devpi_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
@author: eeaston
'''
import io
import os
import sys
import zipfile
import logging
from six.moves import cStringIO

from pytest import yield_fixture, fixture
import devpi_server as _devpi_server
Expand Down Expand Up @@ -105,7 +105,7 @@ def api(self, *args):
client_args.extend(args)
client_args.extend(['--clientdir', str(self.client_dir)])
log.info(' '.join(client_args))
captured = cStringIO()
captured = io.StringIO()
stdout = sys.stdout
sys.stdout = captured
try:
Expand Down
1 change: 0 additions & 1 deletion pytest-devpi-server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
'pytest',
'devpi-server>=3.0.1',
'devpi-client',
'six',
'ruamel.yaml>=0.15',
]

Expand Down
3 changes: 1 addition & 2 deletions pytest-fixture-config/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

install_requires = ['pytest']

tests_require = ['six',
]
tests_require = []

if __name__ == '__main__':
kwargs = common_setup('pytest_fixture_config')
Expand Down
5 changes: 3 additions & 2 deletions pytest-fixture-config/tests/unit/test_fixture_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import importlib

import pytest
from six.moves import reload_module

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

from pytest_fixture_config import Config, requires_config, yield_requires_config

Expand Down
9 changes: 4 additions & 5 deletions pytest-listener/pytest_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import collections
import json
import logging
import pickle
import socket
import time
from threading import Thread, Event
from time import sleep

import pytest
from six import string_types
from six.moves import cPickle
from pytest_server_fixtures.base import get_ephemeral_port, get_ephemeral_host

TERMINATOR = json.dumps(['STOP']).encode('utf-8')
Expand Down Expand Up @@ -59,7 +58,7 @@ def __str__(self):
return 'TimedMsg: %s (@ %s)' % (str(self.value), self.time)

def pickled(self):
return cPickle.dumps(self)
return pickle.dumps(self)


class Listener(Thread):
Expand Down Expand Up @@ -114,7 +113,7 @@ def get_data(self):
return None, None

try:
data = cPickle.loads(data)
data = pickle.loads(data)
except:
try:
data = data.decode('utf-8')
Expand All @@ -128,7 +127,7 @@ def get_data(self):
if isinstance(data, TimedMsg):
d = data.value
t = data.time
elif isinstance(data, string_types):
elif isinstance(data, str):
try:
d = json.loads(data)
except:
Expand Down
3 changes: 1 addition & 2 deletions pytest-listener/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
'Programming Language :: Python :: 3.7',
]

install_requires = ['six',
'pytest',
install_requires = ['pytest',
'pytest-server-fixtures'
]

Expand Down
7 changes: 2 additions & 5 deletions pytest-profiling/pytest_profiling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""pytest: avoid already-imported warning: PYTEST_DONT_REWRITE."""

from __future__ import absolute_import

import sys
import os
import cProfile
Expand All @@ -10,16 +8,15 @@
from hashlib import md5
import subprocess

import six
import pytest

LARGE_FILENAME_HASH_LEN = 8


def clean_filename(s):
forbidden_chars = set(r'/?<>\:*|"')
return six.text_type("".join(c if c not in forbidden_chars and ord(c) < 127 else '_'
for c in s))
return str("".join(c if c not in forbidden_chars and ord(c) < 127 else '_'
for c in s))


class Profiling(object):
Expand Down
3 changes: 1 addition & 2 deletions pytest-profiling/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
'Programming Language :: Python :: 3.12',
]

install_requires = ['six',
'pytest',
install_requires = ['pytest',
'gprof2dot',
]

Expand Down
4 changes: 2 additions & 2 deletions pytest-profiling/tests/unit/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# the top-level code in pytest_profiling will be omitted from
# coverage, so force it to be reloaded within this test unit under coverage

import importlib
import os.path
from six.moves import reload_module # @UnresolvedImport

import pytest_profiling

reload_module(pytest_profiling)
importlib.reload(pytest_profiling)

import os
import subprocess
Expand Down
2 changes: 1 addition & 1 deletion pytest-pyramid-server/pytest_pyramid_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
@author: eeaston
'''
import configparser
import os
from six.moves import configparser
import sys
import socket
import glob
Expand Down
1 change: 0 additions & 1 deletion pytest-pyramid-server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
'pytest',
'pyramid',
'waitress',
'six',
]

tests_require = [
Expand Down
4 changes: 1 addition & 3 deletions pytest-server-fixtures/pytest_server_fixtures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import random
import errno

from six import string_types

from pytest_server_fixtures import CONFIG
from pytest_shutil.workspace import Workspace

Expand Down Expand Up @@ -112,7 +110,7 @@ def __init__(self, process, stream, stderr):
def run(self):
while self.process.poll() is None:
l = self.stream.readline()
if not isinstance(l, string_types):
if not isinstance(l, str):
l = l.decode('utf-8')

if l.strip():
Expand Down
8 changes: 3 additions & 5 deletions pytest-server-fixtures/pytest_server_fixtures/http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function

import http.client
import os
import socket
import logging
Expand All @@ -9,7 +8,6 @@
import pytest
import requests
from contextlib import contextmanager
from six.moves import http_client

from pytest_shutil.env import unset_env
from pytest_server_fixtures import CONFIG
Expand Down Expand Up @@ -83,7 +81,7 @@ def get(self, path, as_json=False, attempts=25):
with self.handle_proxy():
returned = requests.get('http://%s:%d/%s' % (self.hostname, self.port, path))
return returned.json() if as_json else returned
except (http_client.BadStatusLine, requests.ConnectionError) as e:
except (http.client.BadStatusLine, requests.ConnectionError) as e:
time.sleep(int(i) / 10)
pass
raise e
Expand All @@ -109,7 +107,7 @@ def post(self, path, data=None, attempts=25, as_json=False, headers=None):
with self.handle_proxy():
returned = requests.post('http://%s:%d/%s' % (self.hostname, self.port, path), data=data, headers=headers)
return returned.json() if as_json else returned
except (http_client.BadStatusLine, requests.ConnectionError) as e:
except (http.client.BadStatusLine, requests.ConnectionError) as e:
time.sleep(int(i) / 10)
pass
raise e
Expand Down
5 changes: 1 addition & 4 deletions pytest-server-fixtures/pytest_server_fixtures/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
@author: eeaston
'''
from __future__ import absolute_import

import os.path
import shutil

import pytest
import six

from pytest_server_fixtures import CONFIG
from pytest_fixture_config import yield_requires_config
Expand Down Expand Up @@ -95,7 +92,7 @@ def load_plugins(self, plugins_repo, plugins=None):
if plugins is None:
plugins = available_plugins.keys()
else:
if isinstance(plugins, six.string_types):
if isinstance(plugins, str):
plugins = [plugins]

errors = []
Expand Down
7 changes: 2 additions & 5 deletions pytest-server-fixtures/pytest_server_fixtures/postgres.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# coding: utf-8

from __future__ import absolute_import, division, print_function, unicode_literals

import os
import logging
import subprocess

import errno
import pytest
from six import text_type

from pytest_server_fixtures import CONFIG
from pytest_fixture_config import requires_config
Expand Down Expand Up @@ -65,7 +62,7 @@ def pre_setup(self):
try:
self.pg_bin = subprocess.check_output([CONFIG.pg_config_executable, "--bindir"]).decode('utf-8').rstrip()
except OSError as e:
msg = "Failed to get pg_config --bindir: " + text_type(e)
msg = "Failed to get pg_config --bindir: " + str(e)
print(msg)
self._fail(msg)
initdb_path = self.pg_bin + '/initdb'
Expand All @@ -76,7 +73,7 @@ def pre_setup(self):
try:
subprocess.check_call([initdb_path, str(self.workspace / 'db')])
except OSError as e:
msg = "Failed to launch postgres: " + text_type(e)
msg = "Failed to launch postgres: " + str(e)
print(msg)
self._fail(msg)

Expand Down
1 change: 0 additions & 1 deletion pytest-server-fixtures/pytest_server_fixtures/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@author: eeaston
'''
from __future__ import absolute_import
import socket

import pytest
Expand Down
7 changes: 2 additions & 5 deletions pytest-server-fixtures/pytest_server_fixtures/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
Pytest fixtures to launch a minio S3 server and get a bucket for it.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

import uuid
from collections import namedtuple
import logging
import os

import pytest
from future.utils import text_type
from pytest_fixture_config import requires_config

from . import CONFIG
Expand Down Expand Up @@ -47,7 +44,7 @@ def s3_bucket(s3_server): # pylint: disable=redefined-outer-name
returning a BucketInfo namedtuple with `s3_bucket.client` and `s3_bucket.name` fields
"""
client = s3_server.get_s3_client()
bucket_name = text_type(uuid.uuid4())
bucket_name = str(uuid.uuid4())
client.create_bucket(Bucket=bucket_name)
return BucketInfo(client, bucket_name)

Expand Down Expand Up @@ -96,6 +93,6 @@ def run_cmd(self):
"server",
"--address",
"{}:{}".format(self.hostname, self.port),
text_type(self.datadir),
str(self.datadir),
]
return cmdargs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Implementation of how a server fixture will run.
"""
# flake8: noqa
from __future__ import absolute_import

def create_server(server_class, **kwargs):
if server_class == 'thread':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Docker server class implementation.
"""
from __future__ import absolute_import

import logging
import docker

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Kubernetes server class implementation.
"""
from __future__ import absolute_import

import os
import logging
Expand Down
2 changes: 0 additions & 2 deletions pytest-server-fixtures/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
install_requires = ['pytest',
'pytest-shutil',
'pytest-fixture-config',
'six',
'future',
'requests',
'retry',
'psutil',
Expand Down
2 changes: 0 additions & 2 deletions pytest-server-fixtures/tests/integration/test_s3_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8

from __future__ import absolute_import, division, print_function, unicode_literals


def test_connection(s3_bucket):
client, bucket_name = s3_bucket
Expand Down
6 changes: 0 additions & 6 deletions pytest-shutil/pytest_shutil/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
from tempfile import mkdtemp


try: # Python 2
str_type = basestring
except NameError: # Python 3
str_type = str


def get_log():
return logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit 5b7dbb4

Please sign in to comment.