Skip to content

Commit 0a48192

Browse files
committed
Remove dead python 2 code and update some tests.
1 parent a22a367 commit 0a48192

File tree

16 files changed

+50
-987
lines changed

16 files changed

+50
-987
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
exclude: '^(\.tox|ci/templates|\.bumpversion\.cfg)(/|$)'
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: master
8+
rev: v4.3.0
99
hooks:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
1212
- id: debug-statements
1313
- repo: https://github.com/timothycrosley/isort
14-
rev: master
14+
rev: 5.10.1
1515
hooks:
1616
- id: isort
1717
- repo: https://gitlab.com/pycqa/flake8
18-
rev: master
18+
rev: 3.9.2
1919
hooks:
2020
- id: flake8

CHANGELOG.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
Changelog
33
=========
44

5-
3.4.3 (????-??-??)
5+
4.0.0 (2022-10-25)
66
------------------
7+
8+
* Dropped support for legacy Pythons (2.7, 3.6 or older).
9+
* Switched CI to GitHub Actions.
710
* Fix skipping test in `test_utils.py` if appropriate VCS not available. Also fix typo.
811
Contributed by Sam James in `#211 <https://github.com/ionelmc/pytest-benchmark/pull/211>`_.
912
* Use ``pytest.hookimpl`` and ``pytest.hookspec`` to configure hooks,
1013
avoiding a deprecation warning in the upcoming pytest 7.2.0.
1114
Contributed by Florian Bruhin in `#224 <https://github.com/ionelmc/pytest-benchmark/pull/224>`_.
12-
13-
3.4.2 (2021-06-15)
14-
------------------
15-
1615
* Don't save if ``--benchmark-disable`` is used.
1716
Fixes `#205 <https://github.com/ionelmc/pytest-benchmark/issues/205`_.
1817
Contributed by Friedrich Delgado in `#207 <https://github.com/ionelmc/pytest-benchmark/pull/207>`_.
@@ -169,7 +168,7 @@ Changelog
169168
* Added a command line tool to compare previous data: ``py.test-benchmark``. It has two commands:
170169

171170
* ``list`` - Lists all the available files.
172-
* ``compare`` - Displays result tables. Takes optional arguments:
171+
* ``compare`` - Displays result tables. Takes options:
173172

174173
* ``--sort=COL``
175174
* ``--group-by=LABEL``

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,3 @@ Indices and tables
8787
* :ref:`genindex`
8888
* :ref:`modindex`
8989
* :ref:`search`
90-

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ The compare ``command`` takes almost all the ``--benchmark`` options, minus the
193193
glob_or_file Glob or exact path for json files. If not specified
194194
all runs are loaded.
195195

196-
optional arguments:
196+
options:
197197
-h, --help show this help message and exit
198198
--sort=COL Column to sort on. Can be one of: 'min', 'max',
199199
'mean', 'stddev', 'name', 'fullname'. Default: 'min'

src/pytest_benchmark/compat.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,3 @@
11
import sys
22

3-
try:
4-
from collections.abc import Iterable
5-
except ImportError:
6-
from collections import Iterable # noqa
7-
8-
PY3 = sys.version_info[0] == 3
9-
PY38 = PY3 and sys.version_info[1] >= 8
10-
11-
XRANGE = range if PY3 else xrange # noqa
12-
INT = (int,) if PY3 else (int, long) # noqa
13-
14-
if PY3:
15-
import builtins
16-
exec_ = getattr(builtins, "exec")
17-
18-
def reraise(tp, value, tb=None):
19-
try:
20-
if value is None:
21-
value = tp()
22-
if value.__traceback__ is not tb:
23-
raise value.with_traceback(tb)
24-
raise value
25-
finally:
26-
value = None
27-
tb = None
28-
29-
else:
30-
def exec_(_code_, _globs_=None, _locs_=None):
31-
"""Execute code in a namespace."""
32-
if _globs_ is None:
33-
frame = sys._getframe(1)
34-
_globs_ = frame.f_globals
35-
if _locs_ is None:
36-
_locs_ = frame.f_locals
37-
del frame
38-
elif _locs_ is None:
39-
_locs_ = _globs_
40-
exec("""exec _code_ in _globs_, _locs_""")
41-
42-
exec_("""def reraise(tp, value, tb=None):
43-
try:
44-
raise tp, value, tb
45-
finally:
46-
tb = None
47-
""")
3+
PY38 = sys.version_info[0] == 3 and sys.version_info[1] >= 8

src/pytest_benchmark/fixture.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import traceback
1010
from math import ceil
1111

12-
from .compat import INT
13-
from .compat import XRANGE
1412
from .timers import compute_timer_precision
1513
from .utils import NameWrapper
1614
from .utils import format_time
@@ -160,9 +158,9 @@ def _raw(self, function_to_benchmark, *args, **kwargs):
160158
if self._warmup:
161159
warmup_rounds = min(rounds, max(1, int(self._warmup / iterations)))
162160
self._logger.debug(" Warmup %s rounds x %s iterations ..." % (warmup_rounds, iterations))
163-
for _ in XRANGE(warmup_rounds):
161+
for _ in range(warmup_rounds):
164162
runner(loops_range)
165-
for _ in XRANGE(rounds):
163+
for _ in range(rounds):
166164
stats.update(runner(loops_range))
167165
self._logger.debug(" Ran for %ss." % format_time(time.time() - run_start), yellow=True, bold=True)
168166
if self.enabled and self.cprofile:
@@ -179,13 +177,13 @@ def _raw_pedantic(self, target, args=(), kwargs=None, setup=None, rounds=1, warm
179177

180178
has_args = bool(args or kwargs)
181179

182-
if not isinstance(iterations, INT) or iterations < 1:
180+
if not isinstance(iterations, int) or iterations < 1:
183181
raise ValueError("Must have positive int for `iterations`.")
184182

185-
if not isinstance(rounds, INT) or rounds < 1:
183+
if not isinstance(rounds, int) or rounds < 1:
186184
raise ValueError("Must have positive int for `rounds`.")
187185

188-
if not isinstance(warmup_rounds, INT) or warmup_rounds < 0:
186+
if not isinstance(warmup_rounds, int) or warmup_rounds < 0:
189187
raise ValueError("Must have positive int for `warmup_rounds`.")
190188

191189
if iterations > 1 and setup:
@@ -205,14 +203,14 @@ def make_arguments(args=args, kwargs=kwargs):
205203
return target(*args, **kwargs)
206204

207205
stats = self._make_stats(iterations)
208-
loops_range = XRANGE(iterations) if iterations > 1 else None
209-
for _ in XRANGE(warmup_rounds):
206+
loops_range = range(iterations) if iterations > 1 else None
207+
for _ in range(warmup_rounds):
210208
args, kwargs = make_arguments()
211209

212210
runner = self._make_runner(target, args, kwargs)
213211
runner(loops_range)
214212

215-
for _ in XRANGE(rounds):
213+
for _ in range(rounds):
216214
args, kwargs = make_arguments()
217215

218216
runner = self._make_runner(target, args, kwargs)
@@ -273,7 +271,7 @@ def _calibrate_timer(self, runner):
273271

274272
loops = 1
275273
while True:
276-
loops_range = XRANGE(loops)
274+
loops_range = range(loops)
277275
duration = runner(loops_range)
278276
if self._warmup:
279277
warmup_start = time.time()
@@ -299,7 +297,7 @@ def _calibrate_timer(self, runner):
299297
if loops == 1:
300298
# If we got a single loop then bail early - nothing to calibrate if the the
301299
# test function is 100 times slower than the timer resolution.
302-
loops_range = XRANGE(loops)
300+
loops_range = range(loops)
303301
break
304302
else:
305303
loops *= 10

src/pytest_benchmark/histogram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from collections.abc import Iterable
2+
13
import py
24

3-
from .compat import Iterable
45
from .utils import TIME_UNITS
56
from .utils import slugify
67

src/pytest_benchmark/hookspec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
34
@pytest.hookspec(firstresult=True)
45
def pytest_benchmark_scale_unit(config, unit, benchmarks, best, worst, sort):
56
"""

0 commit comments

Comments
 (0)