Skip to content

Commit

Permalink
Merge pull request #5368 from asottile/pyupgrade
Browse files Browse the repository at this point in the history
Automated / semi-automated python3 upgrades
  • Loading branch information
asottile committed Jun 3, 2019
2 parents b8781ff + ce78c9a commit 5976f36
Show file tree
Hide file tree
Showing 191 changed files with 820 additions and 1,517 deletions.
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Expand Up @@ -7,17 +7,18 @@ repos:
args: [--safe, --quiet]
language_version: python3
- repo: https://github.com/asottile/blacken-docs
rev: v0.5.0
rev: v1.0.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.2
rev: v2.2.3
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: check-yaml
- id: debug-statements
exclude: _pytest/debugging.py
Expand All @@ -31,14 +32,14 @@ repos:
rev: v1.4.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src']
args: ['--application-directories=.:src', --py3-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v1.15.0
rev: v1.18.0
hooks:
- id: pyupgrade
args: [--keep-percent-format]
args: [--py3-plus]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.3.0
rev: v1.4.0
hooks:
- id: rst-backticks
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
- test $(python -c 'import sys; print("%d%d" % sys.version_info[0:2])') = 37

# Full run of latest supported version, without xdist.
- env: TOXENV=py37
- env: TOXENV=py37 PYTEST_COVERAGE=1
python: '3.7'

# Coverage tracking is slow with pypy, skip it.
Expand Down
1 change: 0 additions & 1 deletion bench/bench.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys

if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion bench/bench_argcomplete.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# 10000 iterations, just for relative comparison
# 2.7.5 3.3.2
# FilesCompleter 75.1109 69.2116
Expand Down
1 change: 0 additions & 1 deletion bench/empty.py
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
for i in range(1000):
exec("def test_func_%d(): pass" % i)
1 change: 0 additions & 1 deletion bench/manyparam.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest


Expand Down
3 changes: 0 additions & 3 deletions bench/skip.py
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from six.moves import range

import pytest

SKIP = True
Expand Down
1 change: 0 additions & 1 deletion doc/en/_themes/flask_theme_support.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flasky extensions. flasky pygments style based on tango style
from pygments.style import Style
from pygments.token import Comment
Expand Down
19 changes: 9 additions & 10 deletions doc/en/conf.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# pytest documentation build configuration file, created by
# sphinx-quickstart on Fri Oct 8 17:54:28 2010.
Expand Down Expand Up @@ -63,9 +62,9 @@
master_doc = "contents"

# General information about the project.
project = u"pytest"
project = "pytest"
year = datetime.datetime.utcnow().year
copyright = u"2015–2019 , holger krekel and pytest-dev team"
copyright = "2015–2019 , holger krekel and pytest-dev team"


# The language for content autogenerated by Sphinx. Refer to documentation
Expand Down Expand Up @@ -233,8 +232,8 @@
(
"contents",
"pytest.tex",
u"pytest Documentation",
u"holger krekel, trainer and consultant, http://merlinux.eu",
"pytest Documentation",
"holger krekel, trainer and consultant, http://merlinux.eu",
"manual",
)
]
Expand Down Expand Up @@ -266,16 +265,16 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("usage", "pytest", u"pytest usage", [u"holger krekel at merlinux eu"], 1)]
man_pages = [("usage", "pytest", "pytest usage", ["holger krekel at merlinux eu"], 1)]


# -- Options for Epub output ---------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = u"pytest"
epub_author = u"holger krekel at merlinux eu"
epub_publisher = u"holger krekel at merlinux eu"
epub_copyright = u"2013, holger krekel et alii"
epub_title = "pytest"
epub_author = "holger krekel at merlinux eu"
epub_publisher = "holger krekel at merlinux eu"
epub_copyright = "2013, holger krekel et alii"

# The language of the text. It defaults to the language option
# or en if the language is not set.
Expand Down
1 change: 0 additions & 1 deletion doc/en/conftest.py
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
collect_ignore = ["conf.py"]
31 changes: 15 additions & 16 deletions doc/en/example/assertion/failure_demo.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import _pytest._code
import pytest
from pytest import raises
Expand All @@ -21,7 +20,7 @@ def test_generative(param1, param2):
assert param1 * 2 < param2


class TestFailing(object):
class TestFailing:
def test_simple(self):
def f():
return 42
Expand All @@ -41,7 +40,7 @@ def f():
assert not f()


class TestSpecialisedExplanations(object):
class TestSpecialisedExplanations:
def test_eq_text(self):
assert "spam" == "eggs"

Expand Down Expand Up @@ -101,7 +100,7 @@ def test_eq_dataclass(self):
from dataclasses import dataclass

@dataclass
class Foo(object):
class Foo:
a: int
b: str

Expand All @@ -113,7 +112,7 @@ def test_eq_attrs(self):
import attr

@attr.s
class Foo(object):
class Foo:
a = attr.ib()
b = attr.ib()

Expand All @@ -123,22 +122,22 @@ class Foo(object):


def test_attribute():
class Foo(object):
class Foo:
b = 1

i = Foo()
assert i.b == 2


def test_attribute_instance():
class Foo(object):
class Foo:
b = 1

assert Foo().b == 2


def test_attribute_failure():
class Foo(object):
class Foo:
def _get_b(self):
raise Exception("Failed to get attrib")

Expand All @@ -149,10 +148,10 @@ def _get_b(self):


def test_attribute_multiple():
class Foo(object):
class Foo:
b = 1

class Bar(object):
class Bar:
b = 2

assert Foo().b == Bar().b
Expand All @@ -162,7 +161,7 @@ def globf(x):
return x + 1


class TestRaises(object):
class TestRaises:
def test_raises(self):
s = "qwe"
raises(TypeError, int, s)
Expand Down Expand Up @@ -203,7 +202,7 @@ def test_dynamic_compile_shows_nicely():
module.foo()


class TestMoreErrors(object):
class TestMoreErrors:
def test_complex_error(self):
def f():
return 44
Expand Down Expand Up @@ -253,16 +252,16 @@ def test_try_finally(self):
x = 0


class TestCustomAssertMsg(object):
class TestCustomAssertMsg:
def test_single_line(self):
class A(object):
class A:
a = 1

b = 2
assert A.a == b, "A.a appears not to be b"

def test_multiline(self):
class A(object):
class A:
a = 1

b = 2
Expand All @@ -271,7 +270,7 @@ class A(object):
), "A.a appears not to be b\nor does not appear to be b\none of those"

def test_custom_repr(self):
class JSON(object):
class JSON:
a = 1

def __repr__(self):
Expand Down
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import py

import pytest
Expand Down
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
hello = "world"


Expand Down
1 change: 0 additions & 1 deletion doc/en/example/assertion/test_failures.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import py

failure_demo = py.path.local(__file__).dirpath("failure_demo.py")
Expand Down
3 changes: 1 addition & 2 deletions doc/en/example/assertion/test_setup_flow_example.py
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
def setup_module(module):
module.TestStateFullThing.classcount = 0


class TestStateFullThing(object):
class TestStateFullThing:
def setup_class(cls):
cls.classcount += 1

Expand Down
1 change: 0 additions & 1 deletion doc/en/example/conftest.py
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
collect_ignore = ["nonpython"]
3 changes: 1 addition & 2 deletions doc/en/example/costlysetup/conftest.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest


Expand All @@ -9,7 +8,7 @@ def setup(request):
setup.finalize()


class CostlySetup(object):
class CostlySetup:
def __init__(self):
import time

Expand Down
1 change: 0 additions & 1 deletion doc/en/example/costlysetup/sub_a/__init__.py
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
#
1 change: 0 additions & 1 deletion doc/en/example/costlysetup/sub_a/test_quick.py
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
def test_quick(setup):
pass
1 change: 0 additions & 1 deletion doc/en/example/costlysetup/sub_b/__init__.py
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
#
1 change: 0 additions & 1 deletion doc/en/example/costlysetup/sub_b/test_two.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
def test_something(setup):
assert setup.timecostly == 1

Expand Down
3 changes: 1 addition & 2 deletions doc/en/example/multipython.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
module containing a parametrized tests testing cross-python
serialization via the pickle module.
Expand All @@ -23,7 +22,7 @@ def python2(request, python1):
return Python(request.param, python1.picklefile)


class Python(object):
class Python:
def __init__(self, version, picklefile):
self.pythonpath = distutils.spawn.find_executable(version)
if not self.pythonpath:
Expand Down
3 changes: 1 addition & 2 deletions doc/en/example/nonpython/conftest.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# content of conftest.py
import pytest

Expand All @@ -19,7 +18,7 @@ def collect(self):

class YamlItem(pytest.Item):
def __init__(self, name, parent, spec):
super(YamlItem, self).__init__(name, parent)
super().__init__(name, parent)
self.spec = spec

def runtest(self):
Expand Down
1 change: 0 additions & 1 deletion doc/en/example/py2py3/conftest.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys

import pytest
Expand Down
1 change: 0 additions & 1 deletion doc/en/example/py2py3/test_py3.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
def test_exception_syntax():
try:
0 / 0
Expand Down
3 changes: 1 addition & 2 deletions doc/en/example/pythoncollection.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# run this with $ pytest --collect-only test_collectonly.py
#

Expand All @@ -7,7 +6,7 @@ def test_function():
pass


class TestClass(object):
class TestClass:
def test_method(self):
pass

Expand Down
1 change: 0 additions & 1 deletion doc/en/example/xfail_demo.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import pytest

xfail = pytest.mark.xfail
Expand Down
2 changes: 0 additions & 2 deletions doc/en/writing_plugins.rst
Expand Up @@ -335,8 +335,6 @@ string value of ``Hello World!`` if we do not supply a value or ``Hello

.. code-block:: python
# -*- coding: utf-8 -*-
import pytest
Expand Down
1 change: 0 additions & 1 deletion extra/get_issues.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import json

import py
Expand Down
1 change: 0 additions & 1 deletion extra/setup-py.test/setup.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys
from distutils.core import setup

Expand Down
1 change: 0 additions & 1 deletion scripts/release.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Invoke development tasks.
"""
Expand Down

0 comments on commit 5976f36

Please sign in to comment.