Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#224: Fix the use of Path, which renamed isdir() to is_dir(). #226

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions pytest-devpi-server/_pytest_devpi_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import logging
from six.moves import cStringIO

import pkg_resources
from pytest import yield_fixture, fixture
import devpi_server as _devpi_server
from devpi.main import main as devpi_client
Expand All @@ -20,16 +19,16 @@

@yield_fixture(scope='session')
def devpi_server(request):
""" Session-scoped Devpi server run in a subprocess, out of a temp dir.
""" Session-scoped Devpi server run in a subprocess, out of a temp dir.
Out-of-the-box it creates a single user an index for that user, then
uses that index.

Methods
-------
api(): Client API method, directly bound to the devpi-client command-line tool. Examples:
api(): Client API method, directly bound to the devpi-client command-line tool. Examples:
... api('index', '-c', 'myindex') to create an index called 'myindex'
... api('getjson', '/user/myindex') to return the json string describing this index

Attributes
----------
uri: Server URI
Expand All @@ -38,9 +37,9 @@ def devpi_server(request):
index: Initially created index name
server_dir: Path to server database
client_dir: Path to client directory
.. also inherits all attributes from the `workspace` fixture

.. also inherits all attributes from the `workspace` fixture

For more fine-grained control over these attributes, use the class directly and pass in
constructor arguments.
"""
Expand All @@ -51,7 +50,7 @@ def devpi_server(request):

@fixture
def devpi_function_index(request, devpi_server):
""" Creates and activates an index for your current test function.
""" Creates and activates an index for your current test function.
"""
index_name = '/'.join((devpi_server.user, request.function.__name__))
devpi_server.api('index', '-c', index_name)
Expand All @@ -70,7 +69,7 @@ def __init__(self, offline=True, debug=False, data=None, user="testuser", passwo
Run in offline mode. Defaults to True
data: `str`
Filesystem path to a zipfile archive of the initial server data directory.
If not set and in offline mode, it uses a pre-canned snapshot of a
If not set and in offline mode, it uses a pre-canned snapshot of a
newly-created empty server.
"""
self.debug = debug
Expand All @@ -89,7 +88,7 @@ def __init__(self, offline=True, debug=False, data=None, user="testuser", passwo
@property
def run_cmd(self):
res = [sys.executable, '-c', 'import sys; from devpi_server.main import main; sys.exit(main())',
'--serverdir', self.server_dir,
'--serverdir', str(self.server_dir),
'--host', self.hostname,
'--port', str(self.port)
]
Expand All @@ -104,7 +103,7 @@ def api(self, *args):
"""
client_args = ['devpi']
client_args.extend(args)
client_args.extend(['--clientdir', self.client_dir])
client_args.extend(['--clientdir', str(self.client_dir)])
log.info(' '.join(client_args))
captured = cStringIO()
stdout = sys.stdout
Expand All @@ -119,10 +118,10 @@ def api(self, *args):
def pre_setup(self):
if self.data:
log.info("Extracting initial server data from {}".format(self.data))
zipfile.ZipFile(self.data, 'r').extractall(self.server_dir)
zipfile.ZipFile(self.data, 'r').extractall(str(self.server_dir))
else:
self.run([os.path.join(sys.exec_prefix, "bin", "devpi-init"),
'--serverdir', self.server_dir,
'--serverdir', str(self.server_dir),
])


Expand Down
6 changes: 1 addition & 5 deletions pytest-devpi-server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
'devpi-server>=3.0.1',
'devpi-client',
'six',
'ruamel.yaml>=0.15;python_version == "2.7"',
'ruamel.yaml>=0.15;python_version > "3.4"',
'ruamel.yaml>=0.15',
]

tests_require = []

entry_points = {
'pytest11': [
'devpi_server = _pytest_devpi_server',
Expand All @@ -44,7 +41,6 @@
author_email='eeaston@gmail.com',
classifiers=classifiers,
install_requires=install_requires,
tests_require=tests_require,
packages=find_packages(exclude='tests'),
entry_points=entry_points,
))
Expand Down
22 changes: 14 additions & 8 deletions pytest-devpi-server/tests/integration/test_devpi_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import os
from pathlib import Path

NEW_INDEX = {
u"result": {
Expand All @@ -23,8 +25,8 @@ def test_server(devpi_server):


def test_upload(devpi_server):
pkg_dir = devpi_server.workspace / "pkg"
pkg_dir.mkdir_p()
pkg_dir: Path = devpi_server.workspace / "pkg"
pkg_dir.mkdir(parents=True, exist_ok=True)
setup_py = pkg_dir / "setup.py"
setup_py.write_text(
"""
Expand All @@ -33,12 +35,16 @@ def test_upload(devpi_server):
version='1.2.3')
"""
)
pkg_dir.chdir()
devpi_server.api("upload")
res = devpi_server.api(
"getjson", "/{}/{}".format(devpi_server.user, devpi_server.index)
)
assert json.loads(res)["result"]["projects"] == ["test-foo"]
orig_dir = os.getcwd()
try:
os.chdir(pkg_dir)
devpi_server.api("upload")
res = devpi_server.api(
"getjson", "/{}/{}".format(devpi_server.user, devpi_server.index)
)
assert json.loads(res)["result"]["projects"] == ["test-foo"]
finally:
os.chdir(orig_dir)


def test_function_index(devpi_server, devpi_function_index):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def virtualenv():

venv.install_package("pytest-cov")
venv.install_package("pytest-profiling")
copy_tree(test_dir, venv.workspace)
copy_tree(str(test_dir), str(venv.workspace))
shutil.rmtree(
venv.workspace / "tests" / "unit" / "__pycache__", ignore_errors=True
)
Expand All @@ -44,7 +44,7 @@ def test_profile_generates_svg(pytestconfig, virtualenv):
assert any(
[
"test_example:1:test_foo" in i
for i in (virtualenv.workspace / "prof/combined.svg").lines()
for i in (virtualenv.workspace / "prof/combined.svg").open().readlines()
]
)

Expand All @@ -58,7 +58,7 @@ def test_profile_long_name(pytestconfig, virtualenv):
pytestconfig,
cd=virtualenv.workspace,
)
assert (virtualenv.workspace / "prof/fbf7dc37.prof").isfile()
assert (virtualenv.workspace / "prof/fbf7dc37.prof").is_file()


def test_profile_chdir(pytestconfig, virtualenv):
Expand Down
25 changes: 11 additions & 14 deletions pytest-pyramid-server/pytest_pyramid_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import shutil
import threading

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

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

@yield_fixture(scope='session')
def pyramid_server(request):
""" Session-scoped Pyramid server run in a subprocess, out of a temp dir.
""" Session-scoped Pyramid server run in a subprocess, out of a temp dir.
This is a 'real' server that you can point a Selenium webdriver at.

This fixture searches for its configuration in the current working directory
called 'testing.ini'. All .ini files in the cwd will be copied to the tempdir
so that config chaining still works.
so that config chaining still works.

The fixture implementation in `PyramidTestServer` has more flexible configuration
options, use it directly to define more fine-grained fixtures.
options, use it directly to define more fine-grained fixtures.

Methods
-------
get_config() : Return current configuration as a dict.
get() : Query url relative to the server root.
.. Retry failures by default.
post() : Post payload to url relative to the server root.
.. Retry failures by default.

Attributes
----------
working_config (`path.path`): Path to the config file used by the server at runtime
.. also inherits all attributes from the `workspace` fixture
.. also inherits all attributes from the `workspace` fixture
"""
with PyramidTestServer() as server:
server.start()
Expand Down Expand Up @@ -97,7 +94,7 @@ def pre_setup(self):
for filename in glob.glob(os.path.join(self.config_dir, '*.ini')):
shutil.copy(filename, self.workspace)

Path.copy(self.original_config, self.working_config)
shutil.copy(str(self.original_config), str(self.working_config))

parser = configparser.ConfigParser()
parser.read(self.original_config)
Expand Down Expand Up @@ -142,7 +139,7 @@ def start_server(self, env=None):
"""
print('\n==================================================================================')
print("Starting wsgiref pyramid test server on host %s port %s" % (self.hostname, self.port))
wsgi_app = loadapp('config:' + self.working_config)
wsgi_app = loadapp('config:' + str(self.working_config))
self.server = make_server(self.hostname, self.port, wsgi_app)
worker = threading.Thread(target=self.server.serve_forever)
worker.daemon = True
Expand Down
6 changes: 1 addition & 5 deletions pytest-server-fixtures/pytest_server_fixtures/httpd.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import os
import platform
import socket
import string
import logging

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

from pytest_fixture_config import yield_requires_config
from pytest_server_fixtures import CONFIG
Expand Down
1 change: 0 additions & 1 deletion pytest-server-fixtures/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
}

tests_require = [
'mock; python_version<"3.3"',
'psutil',
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_start_and_stop(httpd_server):


def test_logs(httpd_server):
files = [i.basename() for i in httpd_server.log_dir.files()]
files = [i.name for i in httpd_server.log_dir.iterdir()]
for log in ('access.log', 'error.log'):
assert log in files

Expand Down
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
21 changes: 8 additions & 13 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 All @@ -136,7 +131,7 @@ def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs)
def teardown(self):
if self.delete is not None and not self.delete:
return
if hasattr(self, 'workspace') and self.workspace.isdir():
if hasattr(self, 'workspace') and self.workspace.is_dir():
log.debug("")
log.debug("=======================================================")
log.debug("pytest_shutil deleting workspace %s" % self.workspace)
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; 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
Loading