Align interface of tests.lib.path.Path.mkdir with pathlib.Path.mkdir.

This commit is contained in:
Chris Hunt 2019-08-16 21:34:17 -04:00
parent a6b06059c9
commit f805f328d4
10 changed files with 35 additions and 20 deletions

View File

@ -551,7 +551,8 @@ def test_editable_install__local_dir_no_setup_py_with_pyproject(
Test installing in editable mode from a local directory with no setup.py
but that does have pyproject.toml.
"""
local_dir = script.scratch_path.joinpath('temp').mkdir()
local_dir = script.scratch_path.joinpath('temp')
local_dir.mkdir()
pyproject_path = local_dir.joinpath('pyproject.toml')
pyproject_path.write_text('')

View File

@ -7,7 +7,8 @@ from tests.lib import make_test_finder, path_to_url
def make_project(tmpdir, requires=[], backend=None):
project_dir = (tmpdir / 'project').mkdir()
project_dir = tmpdir / 'project'
project_dir.mkdir()
buildsys = {'requires': requires}
if backend:
buildsys['build-backend'] = backend
@ -125,7 +126,8 @@ def test_pep517_install_with_no_cache_dir(script, tmpdir, data):
def make_pyproject_with_setup(tmpdir, build_system=True, set_backend=True):
project_dir = (tmpdir / 'project').mkdir()
project_dir = tmpdir / 'project'
project_dir.mkdir()
setup_script = (
'from setuptools import setup\n'
)
@ -161,7 +163,8 @@ def make_pyproject_with_setup(tmpdir, build_system=True, set_backend=True):
project_dir.joinpath('pyproject.toml').write_text(project_data)
project_dir.joinpath('setup.py').write_text(setup_script)
package_dir = (project_dir / "pep517_test").mkdir()
package_dir = project_dir / "pep517_test"
package_dir.mkdir()
package_dir.joinpath('__init__.py').write_text('__version__ = "0.1"')
return project_dir, "pep517_test"

View File

@ -51,7 +51,7 @@ class Tests_UninstallUserSite:
"""
Test uninstall editable local user install
"""
script.user_site_path.mkdir(parents=True)
assert script.user_site_path.exists()
# install
to_install = data.packages.joinpath("FSPkg")

View File

@ -451,7 +451,8 @@ class PipTestEnvironment(TestFileEnvironment):
)
# Create a Directory to use as a scratch pad
self.scratch_path = base_path.joinpath("scratch").mkdir()
self.scratch_path = base_path.joinpath("scratch")
self.scratch_path.mkdir()
# Set our default working directory
kwargs.setdefault("cwd", self.scratch_path)
@ -988,7 +989,7 @@ def create_basic_wheel_for_package(script, name, version,
for fname in files:
path = script.temp_path / fname
path.parent.mkdir()
path.parent.mkdir(exist_ok=True)
path.write_text(files[fname])
retval = script.scratch_path / archive_name

View File

@ -154,18 +154,19 @@ class Path(_base):
"""
return os.path.exists(self)
def mkdir(self, mode=0x1FF, parents=False): # 0o777
def mkdir(self, mode=0x1FF, exist_ok=False, parents=False): # 0o777
"""
Creates a directory, if it doesn't exist already.
:param parents: Whether to create parent directories.
"""
if self.exists():
return self
maker_func = os.makedirs if parents else os.mkdir
maker_func(self, mode)
return self
try:
maker_func(self, mode)
except OSError:
if not exist_ok or not os.path.isdir(self):
raise
def unlink(self):
"""

View File

@ -75,7 +75,7 @@ class VirtualEnvironment(object):
context = builder.ensure_directories(self.location)
builder.create_configuration(context)
builder.setup_python(context)
self.site.mkdir(parents=True)
self.site.mkdir(parents=True, exist_ok=True)
self.sitecustomize = self._sitecustomize
self.user_site_packages = self._user_site_packages

View File

@ -358,7 +358,8 @@ def make_fake_html_response(url):
def test_get_html_page_directory_append_index(tmpdir):
"""`_get_html_page()` should append "index.html" to a directory URL.
"""
dirpath = tmpdir.mkdir("something")
dirpath = tmpdir / "something"
dirpath.mkdir()
dir_url = "file:///{}".format(
urllib_request.pathname2url(dirpath).lstrip("/"),
)

View File

@ -31,7 +31,8 @@ def test_get_path_uid_without_NOFOLLOW(monkeypatch):
@pytest.mark.skipif("sys.platform == 'win32'")
@pytest.mark.skipif("not hasattr(os, 'symlink')")
def test_get_path_uid_symlink(tmpdir):
f = tmpdir.mkdir("symlink").joinpath("somefile")
f = tmpdir / "symlink" / "somefile"
f.parent.mkdir()
f.write_text("content")
fs = f + '_link'
os.symlink(f, fs)
@ -43,7 +44,8 @@ def test_get_path_uid_symlink(tmpdir):
@pytest.mark.skipif("not hasattr(os, 'symlink')")
def test_get_path_uid_symlink_without_NOFOLLOW(tmpdir, monkeypatch):
monkeypatch.delattr("os.O_NOFOLLOW")
f = tmpdir.mkdir("symlink").joinpath("somefile")
f = tmpdir / "symlink" / "somefile"
f.parent.mkdir()
f.write_text("content")
fs = f + '_link'
os.symlink(f, fs)

View File

@ -96,7 +96,8 @@ class TestDistutilsScheme:
# This deals with nt/posix path differences
install_scripts = os.path.normcase(os.path.abspath(
os.path.join(os.path.sep, 'somewhere', 'else')))
f = tmpdir.mkdir("config").joinpath("setup.cfg")
f = tmpdir / "config" / "setup.cfg"
f.parent.mkdir()
f.write_text("[install]\ninstall-scripts=" + install_scripts)
from distutils.dist import Distribution
# patch the function that returns what config files are present
@ -116,7 +117,8 @@ class TestDistutilsScheme:
# This deals with nt/posix path differences
install_lib = os.path.normcase(os.path.abspath(
os.path.join(os.path.sep, 'somewhere', 'else')))
f = tmpdir.mkdir("config").joinpath("setup.cfg")
f = tmpdir / "config" / "setup.cfg"
f.parent.mkdir()
f.write_text("[install]\ninstall-lib=" + install_lib)
from distutils.dist import Distribution
# patch the function that returns what config files are present

View File

@ -303,7 +303,9 @@ def test_rmtree_errorhandler_readonly_directory(tmpdir):
Test rmtree_errorhandler makes the given read-only directory writable.
"""
# Create read only directory
path = str((tmpdir / 'subdir').mkdir())
subdir_path = tmpdir / 'subdir'
subdir_path.mkdir()
path = str(subdir_path)
os.chmod(path, stat.S_IREAD)
# Make sure mock_func is called with the given path
@ -321,7 +323,9 @@ def test_rmtree_errorhandler_reraises_error(tmpdir):
by the given unreadable directory.
"""
# Create directory without read permission
path = str((tmpdir / 'subdir').mkdir())
subdir_path = tmpdir / 'subdir'
subdir_path.mkdir()
path = str(subdir_path)
os.chmod(path, stat.S_IWRITE)
mock_func = Mock()