Skip to content

Commit cdb1bda

Browse files
authored
Add pyupgrade tool to pre-commit hooks (#416)
* `pyupgrade --py36-plus tests/**/*.py pytest_bdd/**/*.py setup.py` * add pyupgrade to pre-commit config
1 parent 26adcc4 commit cdb1bda

File tree

13 files changed

+36
-37
lines changed

13 files changed

+36
-37
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ repos:
1212
- id: end-of-file-fixer
1313
- id: check-yaml
1414
- id: check-added-large-files
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v2.12.0
17+
hooks:
18+
- id: pyupgrade
19+
args: [--py36-plus]

pytest_bdd/cucumber_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def unconfigure(config):
4444
config.pluginmanager.unregister(xml)
4545

4646

47-
class LogBDDCucumberJSON(object):
47+
class LogBDDCucumberJSON:
4848

4949
"""Logging plugin for cucumber like json output."""
5050

@@ -90,7 +90,7 @@ def _serialize_tags(self, item):
9090

9191
def _format_name(self, name, keys, values):
9292
for param, value in zip(keys, values):
93-
name = name.replace("<{}>".format(param), str(value))
93+
name = name.replace(f"<{param}>", str(value))
9494
return name
9595

9696
def _format_step_name(self, report, step):

pytest_bdd/generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def print_missing_code(scenarios, steps):
102102
tw.line()
103103

104104
features = sorted(
105-
set(scenario.feature for scenario in scenarios), key=lambda feature: feature.name or feature.filename
105+
{scenario.feature for scenario in scenarios}, key=lambda feature: feature.name or feature.filename
106106
)
107107
code = generate_code(features, scenarios, steps)
108108
tw.write(code)

pytest_bdd/parser.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def parse_feature(basedir, filename, encoding="utf-8"):
101101
multiline_step = False
102102
prev_line = None
103103

104-
with io.open(abs_filename, "rt", encoding=encoding) as f:
104+
with open(abs_filename, encoding=encoding) as f:
105105
content = f.read()
106106

107107
for line_number, line in enumerate(content.splitlines(), start=1):
@@ -170,14 +170,14 @@ def parse_feature(basedir, filename, encoding="utf-8"):
170170
except exceptions.ExamplesNotValidError as exc:
171171
if scenario:
172172
raise exceptions.FeatureError(
173-
"""Scenario has not valid examples. {0}""".format(exc.args[0]),
173+
f"Scenario has not valid examples. {exc.args[0]}",
174174
line_number,
175175
clean_line,
176176
filename,
177177
)
178178
else:
179179
raise exceptions.FeatureError(
180-
"""Feature has not valid examples. {0}""".format(exc.args[0]),
180+
f"Feature has not valid examples. {exc.args[0]}",
181181
line_number,
182182
clean_line,
183183
filename,
@@ -195,7 +195,7 @@ def parse_feature(basedir, filename, encoding="utf-8"):
195195
return feature
196196

197197

198-
class Feature(object):
198+
class Feature:
199199
"""Feature."""
200200

201201
def __init__(self, scenarios, filename, rel_filename, name, tags, examples, background, line_number, description):
@@ -213,7 +213,7 @@ def __init__(self, scenarios, filename, rel_filename, name, tags, examples, back
213213
self.background = background
214214

215215

216-
class Scenario(object):
216+
class Scenario:
217217

218218
"""Scenario."""
219219

@@ -283,14 +283,14 @@ def validate(self):
283283
example_params = self.get_example_params()
284284
if params and example_params and params != example_params:
285285
raise exceptions.ScenarioExamplesNotValidError(
286-
"""Scenario "{0}" in the feature "{1}" has not valid examples. """
287-
"""Set of step parameters {2} should match set of example values {3}.""".format(
286+
"""Scenario "{}" in the feature "{}" has not valid examples. """
287+
"""Set of step parameters {} should match set of example values {}.""".format(
288288
self.name, self.feature.filename, sorted(params), sorted(example_params)
289289
)
290290
)
291291

292292

293-
class Step(object):
293+
class Step:
294294

295295
"""Step."""
296296

@@ -345,15 +345,15 @@ def name(self, value):
345345

346346
def __str__(self):
347347
"""Full step name including the type."""
348-
return '{type} "{name}"'.format(type=self.type.capitalize(), name=self.name)
348+
return f'{self.type.capitalize()} "{self.name}"'
349349

350350
@property
351351
def params(self):
352352
"""Get step params."""
353353
return tuple(frozenset(STEP_PARAM_RE.findall(self.name)))
354354

355355

356-
class Background(object):
356+
class Background:
357357

358358
"""Background."""
359359

@@ -373,7 +373,7 @@ def add_step(self, step):
373373
self.steps.append(step)
374374

375375

376-
class Examples(object):
376+
class Examples:
377377

378378
"""Example table."""
379379

@@ -407,7 +407,7 @@ def add_example_row(self, param, values):
407407
"""
408408
if param in self.example_params:
409409
raise exceptions.ExamplesNotValidError(
410-
"""Example rows should contain unique parameters. "{0}" appeared more than once""".format(param)
410+
f"""Example rows should contain unique parameters. "{param}" appeared more than once"""
411411
)
412412
self.example_params.append(param)
413413
self.vertical_examples.append(values)
@@ -454,7 +454,7 @@ def get_tags(line):
454454
"""
455455
if not line or not line.strip().startswith("@"):
456456
return set()
457-
return set((tag.lstrip("@") for tag in line.strip().split(" @") if len(tag) > 1))
457+
return {tag.lstrip("@") for tag in line.strip().split(" @") if len(tag) > 1}
458458

459459

460460
STEP_PARAM_RE = re.compile(r"\<(.+?)\>")

pytest_bdd/parsers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Step parsers."""
22

3-
from __future__ import absolute_import
43

54
import re as base_re
65
from functools import partial
@@ -9,7 +8,7 @@
98
from parse_type import cfparse as base_cfparse
109

1110

12-
class StepParser(object):
11+
class StepParser:
1312
"""Parser of the individual step."""
1413

1514
def __init__(self, name):
@@ -32,7 +31,7 @@ class re(StepParser):
3231

3332
def __init__(self, name, *args, **kwargs):
3433
"""Compile regex."""
35-
super(re, self).__init__(name)
34+
super().__init__(name)
3635
self.regex = base_re.compile(self.name, *args, **kwargs)
3736

3837
def parse_arguments(self, name):
@@ -52,7 +51,7 @@ class parse(StepParser):
5251

5352
def __init__(self, name, *args, **kwargs):
5453
"""Compile parse expression."""
55-
super(parse, self).__init__(name)
54+
super().__init__(name)
5655
self.parser = base_parse.compile(self.name, *args, **kwargs)
5756

5857
def parse_arguments(self, name):

pytest_bdd/reporting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .utils import get_parametrize_markers_args
1010

1111

12-
class StepReport(object):
12+
class StepReport:
1313
"""Step excecution report."""
1414

1515
failed = False
@@ -59,7 +59,7 @@ def duration(self):
5959
return self.stopped - self.started
6060

6161

62-
class ScenarioReport(object):
62+
class ScenarioReport:
6363
"""Scenario execution report."""
6464

6565
def __init__(self, scenario, node):

pytest_bdd/scenario.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _execute_step_function(request, scenario, step, step_func):
9797
kw["step_func_args"] = {}
9898
try:
9999
# Get the step argument values.
100-
kwargs = dict((arg, request.getfixturevalue(arg)) for arg in get_args(step_func))
100+
kwargs = {arg: request.getfixturevalue(arg) for arg in get_args(step_func)}
101101
kw["step_func_args"] = kwargs
102102

103103
request.config.hook.pytest_bdd_before_step_call(**kw)
@@ -255,12 +255,12 @@ def get_python_name_generator(name):
255255
index = 0
256256

257257
def get_name():
258-
return "test_{0}{1}".format(python_name, suffix)
258+
return f"test_{python_name}{suffix}"
259259

260260
while True:
261261
yield get_name()
262262
index += 1
263-
suffix = "_{0}".format(index)
263+
suffix = f"_{index}"
264264

265265

266266
def scenarios(*feature_paths, **kwargs):

pytest_bdd/scripts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ def migrate_tests_in_file(file_path):
3030
new_content = new_content.rstrip("\n") + "\n"
3131
fd.seek(0)
3232
fd.write(new_content)
33-
print("migrated: {0}".format(file_path))
33+
print(f"migrated: {file_path}")
3434
else:
35-
print("skipped: {0}".format(file_path))
36-
except IOError:
35+
print(f"skipped: {file_path}")
36+
except OSError:
3737
pass
3838

3939

4040
def check_existense(file_name):
4141
"""Check file or directory name for existence."""
4242
if not os.path.exists(file_name):
43-
raise argparse.ArgumentTypeError("{0} is an invalid file or directory name".format(file_name))
43+
raise argparse.ArgumentTypeError(f"{file_name} is an invalid file or directory name")
4444
return file_name
4545

4646

pytest_bdd/steps.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ def given_beautiful_article(article):
3535
3636
"""
3737

38-
from __future__ import absolute_import
39-
4038
import pytest
4139

4240
try:

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, unicode_literals
21
import pytest
32

43
from tests.utils import PYTEST_6

0 commit comments

Comments
 (0)