Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove six dependency #324

Merged
merged 7 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions gabbi/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
from collections import OrderedDict
import copy
import functools
import http.cookies
a-detiste marked this conversation as resolved.
Show resolved Hide resolved
import os
import re
import sys
import time
import unittest
import urllib. parse as urlparse
a-detiste marked this conversation as resolved.
Show resolved Hide resolved
from unittest import result as unitresult

import six
from six.moves import http_cookies
from six.moves.urllib import parse as urlparse
import wsgi_intercept

from gabbi import __version__
Expand Down Expand Up @@ -299,7 +298,7 @@ def _cookie_replacer(self, match):
else:
referred_case = self.prior
response_cookies = referred_case.response['set-cookie']
cookies = http_cookies.SimpleCookie()
cookies = http.cookies.SimpleCookie()
cookies.load(response_cookies)
cookie_string = cookies.output(attrs=[], header='', sep=',').strip()
return cookie_string
Expand Down Expand Up @@ -482,7 +481,7 @@ def _response_replacer(self, match, preserve=False):
return self._cast_value(result, match.string)
return result
else:
return six.text_type(result)
return str(result)

def _run_request(
self,
Expand Down Expand Up @@ -514,7 +513,7 @@ def _run_request(
)
except wsgi_intercept.WSGIAppError as exc:
# Extract and re-raise the wrapped exception.
six.reraise(exc.exception_type, exc.exception_value,
raise (exc.exception_type, exc.exception_value,
exc.traceback)

# Set headers and location attributes for follow on requests
Expand Down Expand Up @@ -582,7 +581,7 @@ def _run_test(self):

# ensure body is bytes, encoding as UTF-8 because that's
# what we do here
if isinstance(body, six.text_type):
if isinstance(body, str):
body = body.encode('UTF-8')

if test['poll']:
Expand Down Expand Up @@ -637,10 +636,10 @@ def _test_data_to_string(self, data, content_type):
"""
dumper_class = self.get_content_handler(content_type)
if not _is_complex_type(data):
if isinstance(data, six.string_types) and data.startswith('<@'):
if isinstance(data, str) and data.startswith('<@'):
info = self.load_data_file(data.replace('<@', '', 1))
if utils.not_binary(content_type):
data = six.text_type(info, 'UTF-8')
data = str(info, 'UTF-8')
else:
# Return early we are binary content
return info
Expand All @@ -661,7 +660,7 @@ def _test_data_to_string(self, data, content_type):

# If the result after template handling is not a string, dump
# it if there is a suitable dumper.
if dumper_class and not isinstance(data, six.string_types):
if dumper_class and not isinstance(data, str):
# If there are errors dumping we want them to raise to the
# test harness.
data = dumper_class.dumps(data, test=self)
Expand Down
8 changes: 3 additions & 5 deletions gabbi/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
import sys
from unittest import case

import six


class GabbiFixtureError(Exception):
"""Generic exception for GabbiFixture."""
pass


class GabbiFixture(object):
class GabbiFixture:
"""A context manager that operates as a fixture.

Subclasses must implement ``start_fixture`` and ``stop_fixture``, each
Expand Down Expand Up @@ -86,7 +84,7 @@ def nest(fixtures):
contexts.append(enter_func())
exits.append(exit_func)
yield contexts
except Exception:
except Exception as e:
a-detiste marked this conversation as resolved.
Show resolved Hide resolved
exc = sys.exc_info()
finally:
while exits:
Expand All @@ -97,4 +95,4 @@ def nest(fixtures):
except Exception:
exc = sys.exc_info()
if exc != (None, None, None):
six.reraise(exc[0], exc[1], exc[2])
raise exc[0]
2 changes: 1 addition & 1 deletion gabbi/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from gabbi.exception import GabbiFormatError


class ResponseHandler(object):
class ResponseHandler:
"""Add functionality for making assertions about an HTTP response.

A subclass may implement two methods: ``action`` and ``preprocess``.
Expand Down
10 changes: 4 additions & 6 deletions gabbi/handlers/jsonhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import json

import six

from gabbi.exception import GabbiDataLoadError
from gabbi.handlers import base
from gabbi import json_parser
Expand Down Expand Up @@ -68,7 +66,7 @@ def loads(data):
@staticmethod
def load_data_file(test, file_path):
info = test.load_data_file(file_path)
info = six.text_type(info, 'UTF-8')
info = str(info, 'UTF-8')
return json.loads(info)

@staticmethod
Expand Down Expand Up @@ -103,7 +101,7 @@ def action(self, test, path, value=None):
'%s' % (path, test.response_data))

# read data from disk if the value starts with '<@'
if isinstance(value, six.string_types) and value.startswith('<@'):
if isinstance(value, str) and value.startswith('<@'):
# Do template expansion in the rhs if rhs_path is provided.
if ':' in value:
value, rhs_path = value.split(':$', 1)
Expand All @@ -120,7 +118,7 @@ def action(self, test, path, value=None):
'match %s' % (rhs_path, value))

# If expected is a string, check to see if it is a regex.
is_regex = (isinstance(value, six.string_types) and
is_regex = (isinstance(value, str) and
value.startswith('/') and
value.endswith('/') and
len(value) > 1)
Expand All @@ -130,7 +128,7 @@ def action(self, test, path, value=None):
if is_regex and not rhs_match:
expected = expected[1:-1]
# match may be a number so stringify
match = six.text_type(match)
match = str(match)
test.assertRegex(
match, expected,
'Expect jsonpath %s to match /%s/, got %s' %
Expand Down
4 changes: 1 addition & 3 deletions gabbi/handlers/yaml_disk_loading_jsonhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import yaml

import six

from gabbi.handlers import jsonhandler


Expand All @@ -36,5 +34,5 @@ class YAMLDiskLoadingJSONHandler(jsonhandler.JSONHandler):
@staticmethod
def load_data_file(test, file_path):
info = test.load_data_file(file_path)
info = six.text_type(info, 'UTF-8')
info = str(info, 'UTF-8')
return yaml.safe_load(info)
5 changes: 1 addition & 4 deletions gabbi/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import print_function

import os
import sys

import certifi
import six
import urllib3

from gabbi.handlers import jsonhandler
Expand Down Expand Up @@ -154,7 +151,7 @@ def _print_body(self, headers, content):
content_type = utils.extract_content_type(headers, 'text/plain')[0]
if self._show_body and utils.not_binary(content_type):
content = utils.decode_response_content(headers, content)
if isinstance(content, six.binary_type):
if isinstance(content, bytes):
content = content.decode('utf-8')
# TODO(cdent): Using the JSONHandler here instead of
# just the json module to make it clear that eventually
Expand Down
2 changes: 0 additions & 2 deletions gabbi/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# under the License.
"""Implementation of a command-line runner for gabbi files (AKA suites)."""

from __future__ import print_function

import argparse
from importlib import import_module
import os
Expand Down
2 changes: 1 addition & 1 deletion gabbi/suitemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from gabbi import suite


class TestMaker(object):
class TestMaker:
"""A class for encapsulating test invariants.

All of the tests in a single gabbi file have invariants which are
Expand Down
4 changes: 0 additions & 4 deletions gabbi/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import six

six.add_move(six.MovedModule('mock', 'mock', 'unittest.mock'))
a-detiste marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions gabbi/tests/simple_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
"""

import json

from six.moves.urllib import parse as urlparse
import urllib.parse as urlparse


CURRENT_POLL = 0
METHODS = ['GET', 'PUT', 'POST', 'DELETE', 'PATCH']


class SimpleWsgi(object):
class SimpleWsgi:
"""A simple wsgi application to use in tests."""

def __call__(self, environ, start_response):
Expand Down
3 changes: 1 addition & 2 deletions gabbi/tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
"""Use mocks to confirm that fixtures operate as context managers.
"""

import mock
a-detiste marked this conversation as resolved.
Show resolved Hide resolved
import unittest

from six.moves import mock

from gabbi import fixture


Expand Down
2 changes: 1 addition & 1 deletion gabbi/tests/test_inner_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def stop_fixture(self):
assert COUNT_OUTER == 1


class InnerFixture(object):
class InnerFixture:
"""Test that setUp is called 3 times."""

def setUp(self):
Expand Down
3 changes: 1 addition & 2 deletions gabbi/tests/test_load_data_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
"""Test loading data from files with <@.
"""

import mock
import unittest

from six.moves import mock

from gabbi import case


Expand Down
2 changes: 1 addition & 1 deletion gabbi/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import sys
import unittest
from io import StringIO
from uuid import uuid4

from six import StringIO
from wsgi_intercept.interceptor import Urllib3Interceptor

from gabbi import exception
Expand Down
3 changes: 1 addition & 2 deletions gabbi/tests/test_use_prior_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
"""

import copy
import mock
import unittest

from six.moves import mock

from gabbi import case


Expand Down
12 changes: 3 additions & 9 deletions gabbi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@

import io
import os
import urllib.parse as urlparse

import colorama
import six
from six.moves.urllib import parse as urlparse
import yaml


try: # Python 3
ConnectionRefused = ConnectionRefusedError
except NameError: # Python 2
import socket
ConnectionRefused = socket.error
ConnectionRefused = ConnectionRefusedError


def create_url(base_url, host, port=None, prefix='', ssl=False):
Expand Down Expand Up @@ -72,7 +66,7 @@ def decode_response_content(header_dict, content):
"""Decode content to a proper string."""
content_type, charset = extract_content_type(header_dict)

if not_binary(content_type) and isinstance(content, six.binary_type):
if not_binary(content_type) and isinstance(content, bytes):
return content.decode(charset)
else:
return content
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pbr
pytest
six
PyYAML
urllib3>=1.26.9,<2.0.0
certifi
Expand Down