Skip to content

Commit

Permalink
Replace path/path.py with pathlib & os
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbannister committed Oct 4, 2024
1 parent f6a541b commit b274dd8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pytest-shutil/pytest_shutil/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def run_in_subprocess(fn, python=sys.executable, cd=None, timeout=None):
Raises execnet.RemoteError on exception.
"""
pkl_fn, preargs = (_evaluate_fn_source, (fn,)) if isinstance(fn, str) else _make_pickleable(fn)
spec = '//'.join(filter(None, ['popen', 'python=' + python, 'chdir=' + cd if cd else None]))
spec = '//'.join(filter(None, ['popen', 'python=' + python, 'chdir=' + str(cd) if cd else None]))

def inner(*args, **kwargs):
# execnet sends stdout to /dev/null :(
Expand Down
19 changes: 7 additions & 12 deletions pytest-shutil/pytest_shutil/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
import logging
import subprocess

try:
from path import Path
except ImportError:
from path import path as Path

from pathlib import Path
import pytest
from six import string_types

from . import cmdline

Expand All @@ -23,15 +18,15 @@
@pytest.yield_fixture()
def workspace():
""" Function-scoped temporary workspace that cleans up on exit.
Attributes
----------
workspace (`path.path`): Path to the workspace directory.
debug (bool): If set to True, will log more debug when running commands.
delete (bool): If True, will always delete the workspace on teardown;
.. If None, delete the workspace unless teardown occurs via an exception;
delete (bool): If True, will always delete the workspace on teardown;
.. If None, delete the workspace unless teardown occurs via an exception;
.. If False, never delete the workspace on teardown.
"""
ws = Workspace()
yield ws
Expand Down Expand Up @@ -99,7 +94,7 @@ def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs)
cd : `str`
Path to chdir to, defaults to workspace root
"""
if isinstance(cmd, string_types):
if isinstance(cmd, str):
shell = True
else:
# Some of the command components might be path objects or numbers
Expand All @@ -116,7 +111,7 @@ def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs)
p = subprocess.Popen(cmd, shell=shell, **kwargs)
(out, _) = p.communicate()

if out is not None and not isinstance(out, string_types):
if out is not None and not isinstance(out, str):
out = out.decode('utf-8')

if self.debug and capture:
Expand Down
4 changes: 0 additions & 4 deletions pytest-shutil/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

install_requires = ['six',
'execnet',
'contextlib2;python_version<"3"',
'pytest',
'path>=16.12.0; python_version >= "3.5"',
'path.py; python_version < "3.5"',
'mock; python_version<"3.3"',
'termcolor'
]

Expand Down
7 changes: 3 additions & 4 deletions pytest-shutil/tests/unit/test_cmdline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import stat
import os

from pytest_shutil import cmdline
Expand All @@ -16,7 +15,7 @@ def test_pretty_formatter():
f.hr()
f.p('A Paragraph', 'red')
assert f.buffer == [
'\x1b[1m\x1b[34m A Title\x1b[0m',
'\x1b[1m\x1b[34m A Title\x1b[0m',
'\x1b[1m\x1b[34m--------------------------------------------------------------------------------\x1b[0m',
'\x1b[31mA Paragraph\x1b[0m'
]
Expand All @@ -32,8 +31,8 @@ def test_tempdir():
def test_copy_files(workspace):
d1 = workspace.workspace / 'd1'
d2 = workspace.workspace / 'd2'
d1.makedirs()
d2.makedirs()
os.makedirs(d1)
os.makedirs(d2)
(d1 / 'foo').touch()
(d1 / 'bar').touch()
cmdline.copy_files(d1, d2)
Expand Down

0 comments on commit b274dd8

Please sign in to comment.