Skip to content

Commit

Permalink
refactor: pyupgrade --py37-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 4, 2022
1 parent aa02ed7 commit 7c2f9fc
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
15 changes: 7 additions & 8 deletions django_coverage_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from django.template.base import Lexer, NodeList, Template, TextNode
from django.template.defaulttags import VerbatimNode
from django.templatetags.i18n import BlockTranslateNode
from six.moves import range

try:
from django.template.base import TokenType
Expand Down Expand Up @@ -165,7 +164,7 @@ def sys_info(self):
return [
("django_template_dir", self.django_template_dir),
("environment", sorted(
("%s = %s" % (k, v))
("{} = {}".format(k, v))
for k, v in os.environ.items()
if "DJANGO" in k
)),
Expand Down Expand Up @@ -239,7 +238,7 @@ def line_number_range(self, frame):
return -1, -1

if SHOW_TRACING:
print("{!r}: {}".format(render_self, position))
print(f"{render_self!r}: {position}")
s_start, s_end = position
if isinstance(render_self, TextNode):
first_line = render_self.s.splitlines(True)[0]
Expand Down Expand Up @@ -294,7 +293,7 @@ def get_line_map(self, filename):

class FileReporter(coverage.plugin.FileReporter):
def __init__(self, filename):
super(FileReporter, self).__init__(filename)
super().__init__(filename)
# TODO: html filenames are absolute.

self._source = None
Expand All @@ -303,15 +302,15 @@ def source(self):
if self._source is None:
try:
self._source = read_template_source(self.filename)
except (IOError, UnicodeError) as exc:
raise NoSource("Couldn't read {}: {}".format(self.filename, exc))
except (OSError, UnicodeError) as exc:
raise NoSource(f"Couldn't read {self.filename}: {exc}")
return self._source

def lines(self):
source_lines = set()

if SHOW_PARSING:
print("-------------- {}".format(self.filename))
print(f"-------------- {self.filename}")

if django.VERSION >= (1, 9):
lexer = Lexer(self.source())
Expand Down Expand Up @@ -389,7 +388,7 @@ def lines(self):
source_lines.update(range(lineno, lineno+num_lines))

if SHOW_PARSING:
print("\t\t\tNow source_lines is: {!r}".format(source_lines))
print(f"\t\t\tNow source_lines is: {source_lines!r}")

return source_lines

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

import io
import re
from os.path import dirname, join

Expand All @@ -19,7 +18,7 @@ def read(*names, **kwargs):
Parameter: encoding kwarg may be set
"""
return io.open(
return open(
join(dirname(__file__), *names),
encoding=kwargs.get('encoding', 'utf8')
).read()
Expand Down
8 changes: 4 additions & 4 deletions tests/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class DjangoPluginTestCase(StdStreamCapturingMixin, TempDirMixin, TestCase):
"""A base class for all our tests."""

def setUp(self):
super(DjangoPluginTestCase, self).setUp()
super().setUp()
self.template_directory = "templates"

def _path(self, name=None):
return "{}/{}".format(self.template_directory, name or self.template_file)
return f"{self.template_directory}/{name or self.template_file}"

def make_template(self, text, name=None):
"""Make a template with `text`.
Expand Down Expand Up @@ -191,14 +191,14 @@ def assert_analysis(self, executable, missing=None, name=None):
self.assertEqual(
executable,
actual_executable,
"Executable lines aren't as expected: %r != %r" % (
"Executable lines aren't as expected: {!r} != {!r}".format(
executable, actual_executable,
),
)
self.assertEqual(
missing or [],
actual_missing,
"Missing lines aren't as expected: %r != %r" % (
"Missing lines aren't as expected: {!r} != {!r}".format(
missing, actual_missing,
),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class MultipleEngineTests(DjangoPluginTestCase):
def setUp(self):
super(MultipleEngineTests, self).setUp()
super().setUp()

engine = {
'NAME': 'other',
Expand Down
1 change: 0 additions & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf8
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt

Expand Down
11 changes: 5 additions & 6 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf8
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/django_coverage_plugin/blob/master/NOTICE.txt

Expand All @@ -7,7 +6,7 @@
from .plugin_test import DjangoPluginTestCase

# 200 Unicode chars: snowman + poo.
UNIUNI = u"\u26C4\U0001F4A9"*100
UNIUNI = "\u26C4\U0001F4A9"*100
if isinstance(UNIUNI, str):
UNISTR = UNIUNI
else:
Expand Down Expand Up @@ -64,8 +63,8 @@ def test_non_ascii(self):
υηιcσɗє ιѕ тяιcку
{{more}}!
""")
text = self.run_django_coverage(context={'more': u'ɘboɔinU'})
self.assertEqual(text, u'υηιcσɗє ιѕ тяιcку\nɘboɔinU!\n')
text = self.run_django_coverage(context={'more': 'ɘboɔinU'})
self.assertEqual(text, 'υηιcσɗє ιѕ тяιcку\nɘboɔinU!\n')
self.assert_analysis([1, 2])
self.assertEqual(self.get_html_report(), 100)
self.assertEqual(self.get_xml_report(), 100)
Expand Down Expand Up @@ -215,8 +214,8 @@ def test_verbatim(self):
text = self.run_django_coverage()
self.assertEqual(
text,
u"1\n\n{{if dying}}Alive.{{/if}}\nsecond.\n"
u"{%third%}.UNIUNI\n\n7\n".replace(u"UNIUNI", UNIUNI)
"1\n\n{{if dying}}Alive.{{/if}}\nsecond.\n"
"{%third%}.UNIUNI\n\n7\n".replace("UNIUNI", UNIUNI)
)
self.assert_analysis([1, 2, 3, 4, 5, 7])

Expand Down
6 changes: 3 additions & 3 deletions tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_non_utf8_error(self):
text = self.run_django_coverage(name="main.html")
self.assertEqual(text, "Hello")

self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
self.assert_measured_files("main.html", f"static{os.sep}changelog.txt")
self.assert_analysis([1], name="main.html")
with self.assertRaisesRegex(NoSource, r"changelog.txt.*invalid start byte"):
self.cov.html_report()
Expand All @@ -110,7 +110,7 @@ def test_non_utf8_omitted(self):
text = self.run_django_coverage(name="main.html")
self.assertEqual(text, "Hello")

self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
self.assert_measured_files("main.html", f"static{os.sep}changelog.txt")
self.assert_analysis([1], name="main.html")
self.cov.html_report()

Expand All @@ -131,7 +131,7 @@ def test_non_utf8_ignored(self):
text = self.run_django_coverage(name="main.html")
self.assertEqual(text, "Hello")

self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
self.assert_measured_files("main.html", f"static{os.sep}changelog.txt")
self.assert_analysis([1], name="main.html")
warn_msg = (
"'utf-8' codec can't decode byte 0xf6 in position 2: " +
Expand Down

0 comments on commit 7c2f9fc

Please sign in to comment.