Skip to content

Commit

Permalink
manual: remove dependence on six
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored and nicoddemus committed Jun 3, 2019
1 parent ca1efd5 commit 5dcf85c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 56 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# remove _width_of_current_line in terminal.py
INSTALL_REQUIRES = [
"py>=1.5.0",
"six>=1.10.0",
"packaging",
"attrs>=17.4.0",
"more-itertools>=4.0.0",
Expand Down
3 changes: 1 addition & 2 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import atomicwrites
import py
import six

from _pytest._io.saferepr import saferepr
from _pytest.assertion import util
Expand Down Expand Up @@ -612,7 +611,7 @@ def run(self, mod):
# Insert some special imports at the top of the module but after any
# docstrings and __future__ imports.
aliases = [
ast.alias(six.moves.builtins.__name__, "@py_builtins"),
ast.alias("builtins", "@py_builtins"),
ast.alias("_pytest.assertion.rewrite", "@pytest_ar"),
]
doc = getattr(mod, "docstring", None)
Expand Down
10 changes: 5 additions & 5 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import attr
import py
import six

import _pytest
from _pytest import nodes
Expand Down Expand Up @@ -848,10 +847,10 @@ def finish(self, request):
except: # noqa
exceptions.append(sys.exc_info())
if exceptions:
e = exceptions[0]
_, val, tb = exceptions[0]
# Ensure to not keep frame references through traceback.
del exceptions
six.reraise(*e)
raise val.with_traceback(tb)
finally:
hook = self._fixturemanager.session.gethookproxy(request.node.fspath)
hook.pytest_fixture_post_finalizer(fixturedef=self, request=request)
Expand All @@ -877,7 +876,8 @@ def execute(self, request):
result, cache_key, err = cached_result
if my_cache_key == cache_key:
if err is not None:
six.reraise(*err)
_, val, tb = err
raise val.with_traceback(tb)
else:
return result
# we have a previous but differently parametrized fixture instance
Expand Down Expand Up @@ -950,7 +950,7 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
name=fixture_marker.name or function.__name__
)

@six.wraps(function)
@functools.wraps(function)
def result(*args, **kwargs):
fail(message, pytrace=False)

Expand Down
51 changes: 23 additions & 28 deletions src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from contextlib import contextmanager

import py
import six

import pytest
from _pytest.compat import dummy_context_manager
Expand Down Expand Up @@ -66,34 +65,31 @@ def format(self, record):
return super().format(record)


if not six.PY2:
# Formatter classes don't support format styles in PY2
class PercentStyleMultiline(logging.PercentStyle):
"""A logging style with special support for multiline messages.
class PercentStyleMultiline(logging.PercentStyle):
"""A logging style with special support for multiline messages.
If the message of a record consists of multiple lines, this style
formats the message as if each line were logged separately.
"""

If the message of a record consists of multiple lines, this style
formats the message as if each line were logged separately.
"""
@staticmethod
def _update_message(record_dict, message):
tmp = record_dict.copy()
tmp["message"] = message
return tmp

@staticmethod
def _update_message(record_dict, message):
tmp = record_dict.copy()
tmp["message"] = message
return tmp

def format(self, record):
if "\n" in record.message:
lines = record.message.splitlines()
formatted = self._fmt % self._update_message(record.__dict__, lines[0])
# TODO optimize this by introducing an option that tells the
# logging framework that the indentation doesn't
# change. This allows to compute the indentation only once.
indentation = _remove_ansi_escape_sequences(formatted).find(lines[0])
lines[0] = formatted
return ("\n" + " " * indentation).join(lines)
else:
return self._fmt % record.__dict__
def format(self, record):
if "\n" in record.message:
lines = record.message.splitlines()
formatted = self._fmt % self._update_message(record.__dict__, lines[0])
# TODO optimize this by introducing an option that tells the
# logging framework that the indentation doesn't
# change. This allows to compute the indentation only once.
indentation = _remove_ansi_escape_sequences(formatted).find(lines[0])
lines[0] = formatted
return ("\n" + " " * indentation).join(lines)
else:
return self._fmt % record.__dict__


def get_option_ini(config, *names):
Expand Down Expand Up @@ -464,8 +460,7 @@ def _create_formatter(self, log_format, log_date_format):
else:
formatter = logging.Formatter(log_format, log_date_format)

if not six.PY2:
formatter._style = PercentStyleMultiline(formatter._style._fmt)
formatter._style = PercentStyleMultiline(formatter._style._fmt)
return formatter

def _setup_cli_logging(self):
Expand Down
10 changes: 6 additions & 4 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from time import time

import attr
import six

from .reports import CollectErrorRepr
from .reports import CollectReport
Expand Down Expand Up @@ -304,7 +303,8 @@ def _callfinalizers(self, colitem):
if exc is None:
exc = sys.exc_info()
if exc:
six.reraise(*exc)
_, val, tb = exc
raise val.with_traceback(tb)

def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem)
Expand Down Expand Up @@ -339,7 +339,8 @@ def _teardown_towards(self, needed_collectors):
if exc is None:
exc = sys.exc_info()
if exc:
six.reraise(*exc)
_, val, tb = exc
raise val.with_traceback(tb)

def prepare(self, colitem):
""" setup objects along the collector chain to the test-method
Expand All @@ -350,7 +351,8 @@ def prepare(self, colitem):
# check if the last collection node has raised an error
for col in self.stack:
if hasattr(col, "_prepare_exc"):
six.reraise(*col._prepare_exc)
_, val, tb = col._prepare_exc
raise val.with_traceback(tb)
for col in needed_collectors[len(self.stack) :]:
self.stack.append(col)
try:
Expand Down
2 changes: 0 additions & 2 deletions testing/code/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import inspect
import sys

import six

import _pytest._code
import pytest
from _pytest._code import Source
Expand Down
5 changes: 0 additions & 5 deletions testing/logging/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging

import py.io
import six

import pytest
from _pytest.logging import ColoredLevelFormatter


Expand Down Expand Up @@ -38,9 +36,6 @@ class option:
assert output == ("dummypath 10 INFO Test Message")


@pytest.mark.skipif(
six.PY2, reason="Formatter classes don't support format styles in PY2"
)
def test_multiline_message():
from _pytest.logging import PercentStyleMultiline

Expand Down
5 changes: 2 additions & 3 deletions testing/logging/test_reporting.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import io
import os
import re

import six

import pytest


Expand Down Expand Up @@ -885,7 +884,7 @@ def global_and_fixture_disabled(self):
yield
self.calls.append("exit disabled")

class DummyTerminal(six.StringIO):
class DummyTerminal(io.StringIO):
def section(self, *args, **kwargs):
pass

Expand Down
5 changes: 2 additions & 3 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,8 @@ def test_hello(item, fm):

def test_parsefactories_conftest_and_module_and_class(self, testdir):
testdir.makepyfile(
"""
"""\
import pytest
import six
@pytest.fixture
def hello(request):
Expand All @@ -1376,7 +1375,7 @@ def test_hello(self, item, fm):
assert faclist[0].func(item._request) == "conftest"
assert faclist[1].func(item._request) == "module"
assert faclist[2].func(item._request) == "class"
"""
"""
)
reprec = testdir.inline_run("-s")
reprec.assertoutcome(passed=1)
Expand Down
4 changes: 2 additions & 2 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def test_attributes(self, testdir):
p = testdir.makepyfile(
"""
# assumes that generate/provide runs in the same process
import sys, pytest, six
import sys, pytest
def pytest_generate_tests(metafunc):
metafunc.parametrize('metafunc', [metafunc])
Expand All @@ -910,7 +910,7 @@ class TestClass(object):
def test_method(self, metafunc, pytestconfig):
assert metafunc.config == pytestconfig
assert metafunc.module.__name__ == __name__
unbound = six.get_unbound_function(TestClass.test_method)
unbound = TestClass.test_method
assert metafunc.function == unbound
assert metafunc.cls == TestClass
"""
Expand Down
2 changes: 1 addition & 1 deletion testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ def test_should_not_run(self):


@pytest.mark.parametrize(
"base", ["six.moves.builtins.object", "unittest.TestCase", "unittest2.TestCase"]
"base", ["builtins.object", "unittest.TestCase", "unittest2.TestCase"]
)
def test_usefixtures_marker_on_unittest(base, testdir):
"""#3498"""
Expand Down

0 comments on commit 5dcf85c

Please sign in to comment.