Skip to content

Commit

Permalink
Replace all uses of py.path with pathlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Oct 28, 2024
1 parent 00a2d08 commit 61229eb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/pytest_benchmark/csv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import csv
import operator

import py
from pathlib import Path


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

def render(self, output_file, groups):
output_file = py.path.local(output_file)
if not output_file.ext:
output_file = output_file.new(ext='csv')
with output_file.open('w', ensure=True) as stream:
output_file = Path(output_file)
output_file.parent.mkdir(exist_ok=True, parents=True)

if not output_file.suffix:
output_file = output_file.with_suffix('.csv')
with output_file.open('w') as stream:
writer = csv.writer(stream)
params = sorted(
{param for group, benchmarks in groups for benchmark in benchmarks for param in benchmark.get('params', {}) or ()}
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_benchmark/histogram.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Iterable

import py
from pathlib import Path

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

output_file = py.path.local(path).ensure()
output_file = Path(path)
output_file.parent.mkdir(exist_ok=True, parents=True)

plot = make_plot(
benchmarks=benchmarks,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys
from collections import namedtuple
from pathlib import Path

import py
import pytest
from _pytest.pytester import LineMatcher

pytest_plugins = ('pytester',)

THIS = py.path.local(__file__)
STORAGE = THIS.dirpath('test_storage')
THIS = Path(__file__)
STORAGE = THIS.with_name('test_storage')


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/test_elasticsearch_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os
from io import BytesIO
from io import StringIO
from pathlib import Path

import elasticsearch
import py
import pytest
from freezegun import freeze_time

Expand All @@ -25,8 +25,8 @@

logger = logging.getLogger(__name__)

THIS = py.path.local(__file__)
BENCHFILE = THIS.dirpath('test_storage/0030_5b78858eb718649a31fb93d8dc96ca2cee41a4cd_20150815_030419_uncommitted-changes.json')
THIS = Path(__file__)
BENCHFILE = THIS.with_name('test_storage') / '0030_5b78858eb718649a31fb93d8dc96ca2cee41a4cd_20150815_030419_uncommitted-changes.json'
SAVE_DATA = json.loads(BENCHFILE.read_text(encoding='utf8'))
SAVE_DATA['machine_info'] = {'foo': 'bar'}
SAVE_DATA['commit_info'] = {'foo': 'bar'}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
pytest_plugins = 'pytester'


THIS = py.path.local(__file__)
STORAGE = THIS.dirpath(THIS.purebasename)
THIS = Path(__file__)
STORAGE = THIS.with_suffix('')

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

0 comments on commit 61229eb

Please sign in to comment.