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

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

Merged
merged 1 commit into from
Oct 7, 2019
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
3 changes: 2 additions & 1 deletion tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('')

Expand Down
9 changes: 6 additions & 3 deletions tests/functional/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@


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
Expand Down Expand Up @@ -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'
)
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_uninstall_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_uninstall_editable_from_usersite(self, script, data):
"""
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")
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ def __init__(self, base_path, *args, **kwargs):
)

# 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)
Expand Down Expand Up @@ -988,7 +989,7 @@ def hello():

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
Expand Down
11 changes: 6 additions & 5 deletions tests/lib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,19 @@ def exists(self):
"""
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):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _create(self, clear=False):
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

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/"),
)
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def test_distutils_config_file_read(self, tmpdir, monkeypatch):
# 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
Expand All @@ -116,7 +117,8 @@ def test_install_lib_takes_precedence(self, tmpdir, monkeypatch):
# 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
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down