Skip to content

Commit 61229eb

Browse files
committed
Replace all uses of py.path with pathlib.
1 parent 00a2d08 commit 61229eb

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

src/pytest_benchmark/csv.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import csv
22
import operator
3-
4-
import py
3+
from pathlib import Path
54

65

76
class CSVResults:
@@ -11,10 +10,12 @@ def __init__(self, columns, sort, logger):
1110
self.logger = logger
1211

1312
def render(self, output_file, groups):
14-
output_file = py.path.local(output_file)
15-
if not output_file.ext:
16-
output_file = output_file.new(ext='csv')
17-
with output_file.open('w', ensure=True) as stream:
13+
output_file = Path(output_file)
14+
output_file.parent.mkdir(exist_ok=True, parents=True)
15+
16+
if not output_file.suffix:
17+
output_file = output_file.with_suffix('.csv')
18+
with output_file.open('w') as stream:
1819
writer = csv.writer(stream)
1920
params = sorted(
2021
{param for group, benchmarks in groups for benchmark in benchmarks for param in benchmark.get('params', {}) or ()}

src/pytest_benchmark/histogram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections.abc import Iterable
2-
3-
import py
2+
from pathlib import Path
43

54
from .utils import TIME_UNITS
65
from .utils import slugify
@@ -100,7 +99,8 @@ def make_histogram(output_prefix, name, benchmarks, unit, adjustment):
10099
path = f'{output_prefix}.svg'
101100
title = f'Speed in {TIME_UNITS[unit]}'
102101

103-
output_file = py.path.local(path).ensure()
102+
output_file = Path(path)
103+
output_file.parent.mkdir(exist_ok=True, parents=True)
104104

105105
plot = make_plot(
106106
benchmarks=benchmarks,

tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import sys
22
from collections import namedtuple
3+
from pathlib import Path
34

4-
import py
55
import pytest
66
from _pytest.pytester import LineMatcher
77

88
pytest_plugins = ('pytester',)
99

10-
THIS = py.path.local(__file__)
11-
STORAGE = THIS.dirpath('test_storage')
10+
THIS = Path(__file__)
11+
STORAGE = THIS.with_name('test_storage')
1212

1313

1414
@pytest.fixture

tests/test_elasticsearch_storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44
from io import BytesIO
55
from io import StringIO
6+
from pathlib import Path
67

78
import elasticsearch
8-
import py
99
import pytest
1010
from freezegun import freeze_time
1111

@@ -25,8 +25,8 @@
2525

2626
logger = logging.getLogger(__name__)
2727

28-
THIS = py.path.local(__file__)
29-
BENCHFILE = THIS.dirpath('test_storage/0030_5b78858eb718649a31fb93d8dc96ca2cee41a4cd_20150815_030419_uncommitted-changes.json')
28+
THIS = Path(__file__)
29+
BENCHFILE = THIS.with_name('test_storage') / '0030_5b78858eb718649a31fb93d8dc96ca2cee41a4cd_20150815_030419_uncommitted-changes.json'
3030
SAVE_DATA = json.loads(BENCHFILE.read_text(encoding='utf8'))
3131
SAVE_DATA['machine_info'] = {'foo': 'bar'}
3232
SAVE_DATA['commit_info'] = {'foo': 'bar'}

tests/test_storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
pytest_plugins = 'pytester'
2929

3030

31-
THIS = py.path.local(__file__)
32-
STORAGE = THIS.dirpath(THIS.purebasename)
31+
THIS = Path(__file__)
32+
STORAGE = THIS.with_suffix('')
3333

34-
JSON_DATA = json.loads(STORAGE.listdir('0030_*.json')[0].read_text(encoding='utf8'))
34+
JSON_DATA = json.loads(next(STORAGE.glob('0030_*.json')).read_text(encoding='utf8'))
3535
JSON_DATA['machine_info'] = {'foo': 'bar'}
3636
JSON_DATA['commit_info'] = {'foo': 'bar'}
3737
list(normalize_stats(bench['stats']) for bench in JSON_DATA['benchmarks'])

0 commit comments

Comments
 (0)