Skip to content

Commit 01b3fb2

Browse files
authored
Merge pull request #226 from man-group/224-fix-shutil
#224: Fix the use of Path, which renamed isdir() to is_dir().
2 parents 00895eb + 1a74776 commit 01b3fb2

File tree

13 files changed

+57
-75
lines changed

13 files changed

+57
-75
lines changed

pytest-devpi-server/_pytest_devpi_server/__init__.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import logging
1010
from six.moves import cStringIO
1111

12-
import pkg_resources
1312
from pytest import yield_fixture, fixture
1413
import devpi_server as _devpi_server
1514
from devpi.main import main as devpi_client
@@ -20,16 +19,16 @@
2019

2120
@yield_fixture(scope='session')
2221
def devpi_server(request):
23-
""" Session-scoped Devpi server run in a subprocess, out of a temp dir.
22+
""" Session-scoped Devpi server run in a subprocess, out of a temp dir.
2423
Out-of-the-box it creates a single user an index for that user, then
2524
uses that index.
26-
25+
2726
Methods
2827
-------
29-
api(): Client API method, directly bound to the devpi-client command-line tool. Examples:
28+
api(): Client API method, directly bound to the devpi-client command-line tool. Examples:
3029
... api('index', '-c', 'myindex') to create an index called 'myindex'
3130
... api('getjson', '/user/myindex') to return the json string describing this index
32-
31+
3332
Attributes
3433
----------
3534
uri: Server URI
@@ -38,9 +37,9 @@ def devpi_server(request):
3837
index: Initially created index name
3938
server_dir: Path to server database
4039
client_dir: Path to client directory
41-
42-
.. also inherits all attributes from the `workspace` fixture
43-
40+
41+
.. also inherits all attributes from the `workspace` fixture
42+
4443
For more fine-grained control over these attributes, use the class directly and pass in
4544
constructor arguments.
4645
"""
@@ -51,7 +50,7 @@ def devpi_server(request):
5150

5251
@fixture
5352
def devpi_function_index(request, devpi_server):
54-
""" Creates and activates an index for your current test function.
53+
""" Creates and activates an index for your current test function.
5554
"""
5655
index_name = '/'.join((devpi_server.user, request.function.__name__))
5756
devpi_server.api('index', '-c', index_name)
@@ -70,7 +69,7 @@ def __init__(self, offline=True, debug=False, data=None, user="testuser", passwo
7069
Run in offline mode. Defaults to True
7170
data: `str`
7271
Filesystem path to a zipfile archive of the initial server data directory.
73-
If not set and in offline mode, it uses a pre-canned snapshot of a
72+
If not set and in offline mode, it uses a pre-canned snapshot of a
7473
newly-created empty server.
7574
"""
7675
self.debug = debug
@@ -89,7 +88,7 @@ def __init__(self, offline=True, debug=False, data=None, user="testuser", passwo
8988
@property
9089
def run_cmd(self):
9190
res = [sys.executable, '-c', 'import sys; from devpi_server.main import main; sys.exit(main())',
92-
'--serverdir', self.server_dir,
91+
'--serverdir', str(self.server_dir),
9392
'--host', self.hostname,
9493
'--port', str(self.port)
9594
]
@@ -104,7 +103,7 @@ def api(self, *args):
104103
"""
105104
client_args = ['devpi']
106105
client_args.extend(args)
107-
client_args.extend(['--clientdir', self.client_dir])
106+
client_args.extend(['--clientdir', str(self.client_dir)])
108107
log.info(' '.join(client_args))
109108
captured = cStringIO()
110109
stdout = sys.stdout
@@ -119,10 +118,10 @@ def api(self, *args):
119118
def pre_setup(self):
120119
if self.data:
121120
log.info("Extracting initial server data from {}".format(self.data))
122-
zipfile.ZipFile(self.data, 'r').extractall(self.server_dir)
121+
zipfile.ZipFile(self.data, 'r').extractall(str(self.server_dir))
123122
else:
124123
self.run([os.path.join(sys.exec_prefix, "bin", "devpi-init"),
125-
'--serverdir', self.server_dir,
124+
'--serverdir', str(self.server_dir),
126125
])
127126

128127

pytest-devpi-server/setup.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@
2323
'devpi-server>=3.0.1',
2424
'devpi-client',
2525
'six',
26-
'ruamel.yaml>=0.15;python_version == "2.7"',
27-
'ruamel.yaml>=0.15;python_version > "3.4"',
26+
'ruamel.yaml>=0.15',
2827
]
2928

30-
tests_require = []
31-
3229
entry_points = {
3330
'pytest11': [
3431
'devpi_server = _pytest_devpi_server',
@@ -44,7 +41,6 @@
4441
author_email='[email protected]',
4542
classifiers=classifiers,
4643
install_requires=install_requires,
47-
tests_require=tests_require,
4844
packages=find_packages(exclude='tests'),
4945
entry_points=entry_points,
5046
))

pytest-devpi-server/tests/integration/test_devpi_server.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
import os
3+
from pathlib import Path
24

35
NEW_INDEX = {
46
u"result": {
@@ -23,8 +25,8 @@ def test_server(devpi_server):
2325

2426

2527
def test_upload(devpi_server):
26-
pkg_dir = devpi_server.workspace / "pkg"
27-
pkg_dir.mkdir_p()
28+
pkg_dir: Path = devpi_server.workspace / "pkg"
29+
pkg_dir.mkdir(parents=True, exist_ok=True)
2830
setup_py = pkg_dir / "setup.py"
2931
setup_py.write_text(
3032
"""
@@ -33,12 +35,16 @@ def test_upload(devpi_server):
3335
version='1.2.3')
3436
"""
3537
)
36-
pkg_dir.chdir()
37-
devpi_server.api("upload")
38-
res = devpi_server.api(
39-
"getjson", "/{}/{}".format(devpi_server.user, devpi_server.index)
40-
)
41-
assert json.loads(res)["result"]["projects"] == ["test-foo"]
38+
orig_dir = os.getcwd()
39+
try:
40+
os.chdir(pkg_dir)
41+
devpi_server.api("upload")
42+
res = devpi_server.api(
43+
"getjson", "/{}/{}".format(devpi_server.user, devpi_server.index)
44+
)
45+
assert json.loads(res)["result"]["projects"] == ["test-foo"]
46+
finally:
47+
os.chdir(orig_dir)
4248

4349

4450
def test_function_index(devpi_server, devpi_function_index):

pytest-profiling/tests/integration/test_profile_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def virtualenv():
1919

2020
venv.install_package("pytest-cov")
2121
venv.install_package("pytest-profiling")
22-
copy_tree(test_dir, venv.workspace)
22+
copy_tree(str(test_dir), str(venv.workspace))
2323
shutil.rmtree(
2424
venv.workspace / "tests" / "unit" / "__pycache__", ignore_errors=True
2525
)
@@ -44,7 +44,7 @@ def test_profile_generates_svg(pytestconfig, virtualenv):
4444
assert any(
4545
[
4646
"test_example:1:test_foo" in i
47-
for i in (virtualenv.workspace / "prof/combined.svg").lines()
47+
for i in (virtualenv.workspace / "prof/combined.svg").open().readlines()
4848
]
4949
)
5050

@@ -58,7 +58,7 @@ def test_profile_long_name(pytestconfig, virtualenv):
5858
pytestconfig,
5959
cd=virtualenv.workspace,
6060
)
61-
assert (virtualenv.workspace / "prof/fbf7dc37.prof").isfile()
61+
assert (virtualenv.workspace / "prof/fbf7dc37.prof").is_file()
6262

6363

6464
def test_profile_chdir(pytestconfig, virtualenv):

pytest-pyramid-server/pytest_pyramid_server.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import shutil
1212
import threading
1313

14-
try:
15-
from path import Path
16-
except ImportError:
17-
from path import path as Path
14+
from pathlib import Path
1815

1916
from wsgiref.simple_server import make_server
2017
from paste.deploy.loadwsgi import loadapp
@@ -30,28 +27,28 @@ class ConfigNotFoundError(Exception):
3027

3128
@yield_fixture(scope='session')
3229
def pyramid_server(request):
33-
""" Session-scoped Pyramid server run in a subprocess, out of a temp dir.
30+
""" Session-scoped Pyramid server run in a subprocess, out of a temp dir.
3431
This is a 'real' server that you can point a Selenium webdriver at.
35-
32+
3633
This fixture searches for its configuration in the current working directory
3734
called 'testing.ini'. All .ini files in the cwd will be copied to the tempdir
38-
so that config chaining still works.
39-
35+
so that config chaining still works.
36+
4037
The fixture implementation in `PyramidTestServer` has more flexible configuration
41-
options, use it directly to define more fine-grained fixtures.
42-
38+
options, use it directly to define more fine-grained fixtures.
39+
4340
Methods
4441
-------
4542
get_config() : Return current configuration as a dict.
4643
get() : Query url relative to the server root.
4744
.. Retry failures by default.
4845
post() : Post payload to url relative to the server root.
4946
.. Retry failures by default.
50-
47+
5148
Attributes
5249
----------
5350
working_config (`path.path`): Path to the config file used by the server at runtime
54-
.. also inherits all attributes from the `workspace` fixture
51+
.. also inherits all attributes from the `workspace` fixture
5552
"""
5653
with PyramidTestServer() as server:
5754
server.start()
@@ -97,7 +94,7 @@ def pre_setup(self):
9794
for filename in glob.glob(os.path.join(self.config_dir, '*.ini')):
9895
shutil.copy(filename, self.workspace)
9996

100-
Path.copy(self.original_config, self.working_config)
97+
shutil.copy(str(self.original_config), str(self.working_config))
10198

10299
parser = configparser.ConfigParser()
103100
parser.read(self.original_config)
@@ -142,7 +139,7 @@ def start_server(self, env=None):
142139
"""
143140
print('\n==================================================================================')
144141
print("Starting wsgiref pyramid test server on host %s port %s" % (self.hostname, self.port))
145-
wsgi_app = loadapp('config:' + self.working_config)
142+
wsgi_app = loadapp('config:' + str(self.working_config))
146143
self.server = make_server(self.hostname, self.port, wsgi_app)
147144
worker = threading.Thread(target=self.server.serve_forever)
148145
worker.daemon = True

pytest-server-fixtures/pytest_server_fixtures/httpd.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import os
22
import platform
3-
import socket
43
import string
54
import logging
65

76
import pytest
8-
try:
9-
from path import Path
10-
except ImportError:
11-
from path import path as Path
7+
from pathlib import Path
128

139
from pytest_fixture_config import yield_requires_config
1410
from pytest_server_fixtures import CONFIG

pytest-server-fixtures/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
}
3939

4040
tests_require = [
41-
'mock; python_version<"3.3"',
4241
'psutil',
4342
]
4443

pytest-server-fixtures/tests/integration/test_httpd_proxy_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_start_and_stop(httpd_server):
1111

1212

1313
def test_logs(httpd_server):
14-
files = [i.basename() for i in httpd_server.log_dir.files()]
14+
files = [i.name for i in httpd_server.log_dir.iterdir()]
1515
for log in ('access.log', 'error.log'):
1616
assert log in files
1717

pytest-shutil/pytest_shutil/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def run_in_subprocess(fn, python=sys.executable, cd=None, timeout=None):
190190
Raises execnet.RemoteError on exception.
191191
"""
192192
pkl_fn, preargs = (_evaluate_fn_source, (fn,)) if isinstance(fn, str) else _make_pickleable(fn)
193-
spec = '//'.join(filter(None, ['popen', 'python=' + python, 'chdir=' + cd if cd else None]))
193+
spec = '//'.join(filter(None, ['popen', 'python=' + python, 'chdir=' + str(cd) if cd else None]))
194194

195195
def inner(*args, **kwargs):
196196
# execnet sends stdout to /dev/null :(

pytest-shutil/pytest_shutil/workspace.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
import logging
88
import subprocess
99

10-
try:
11-
from path import Path
12-
except ImportError:
13-
from path import path as Path
14-
10+
from pathlib import Path
1511
import pytest
16-
from six import string_types
1712

1813
from . import cmdline
1914

@@ -23,15 +18,15 @@
2318
@pytest.yield_fixture()
2419
def workspace():
2520
""" Function-scoped temporary workspace that cleans up on exit.
26-
21+
2722
Attributes
2823
----------
2924
workspace (`path.path`): Path to the workspace directory.
3025
debug (bool): If set to True, will log more debug when running commands.
31-
delete (bool): If True, will always delete the workspace on teardown;
32-
.. If None, delete the workspace unless teardown occurs via an exception;
26+
delete (bool): If True, will always delete the workspace on teardown;
27+
.. If None, delete the workspace unless teardown occurs via an exception;
3328
.. If False, never delete the workspace on teardown.
34-
29+
3530
"""
3631
ws = Workspace()
3732
yield ws
@@ -99,7 +94,7 @@ def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs)
9994
cd : `str`
10095
Path to chdir to, defaults to workspace root
10196
"""
102-
if isinstance(cmd, string_types):
97+
if isinstance(cmd, str):
10398
shell = True
10499
else:
105100
# Some of the command components might be path objects or numbers
@@ -116,7 +111,7 @@ def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs)
116111
p = subprocess.Popen(cmd, shell=shell, **kwargs)
117112
(out, _) = p.communicate()
118113

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

122117
if self.debug and capture:
@@ -136,7 +131,7 @@ def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs)
136131
def teardown(self):
137132
if self.delete is not None and not self.delete:
138133
return
139-
if hasattr(self, 'workspace') and self.workspace.isdir():
134+
if hasattr(self, 'workspace') and self.workspace.is_dir():
140135
log.debug("")
141136
log.debug("=======================================================")
142137
log.debug("pytest_shutil deleting workspace %s" % self.workspace)

pytest-shutil/setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
install_requires = ['six',
2121
'execnet',
22-
'contextlib2;python_version<"3"',
2322
'pytest',
24-
'path; python_version >= "3.5"',
25-
'path.py; python_version < "3.5"',
26-
'mock; python_version<"3.3"',
2723
'termcolor'
2824
]
2925

pytest-shutil/tests/unit/test_cmdline.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import stat
21
import os
32

43
from pytest_shutil import cmdline
@@ -17,7 +16,7 @@ def test_pretty_formatter(monkeypatch):
1716
f.hr()
1817
f.p('A Paragraph', 'red')
1918
assert f.buffer == [
20-
'\x1b[1m\x1b[34m A Title\x1b[0m',
19+
'\x1b[1m\x1b[34m A Title\x1b[0m',
2120
'\x1b[1m\x1b[34m--------------------------------------------------------------------------------\x1b[0m',
2221
'\x1b[31mA Paragraph\x1b[0m'
2322
]
@@ -33,8 +32,8 @@ def test_tempdir():
3332
def test_copy_files(workspace):
3433
d1 = workspace.workspace / 'd1'
3534
d2 = workspace.workspace / 'd2'
36-
d1.makedirs()
37-
d2.makedirs()
35+
os.makedirs(d1)
36+
os.makedirs(d2)
3837
(d1 / 'foo').touch()
3938
(d1 / 'bar').touch()
4039
cmdline.copy_files(d1, d2)

0 commit comments

Comments
 (0)