Skip to content

Commit

Permalink
Add test for PermissionError. Ref #181.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Sep 29, 2022
1 parent d2529ff commit faaf778
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
17 changes: 14 additions & 3 deletions conftest.py
@@ -1,6 +1,7 @@
import os
import sys
import platform
import pathlib

import pytest
import path
Expand Down Expand Up @@ -150,8 +151,18 @@ def suppress_path_mangle(monkeysession):
)


def _set_home(monkeypatch, path):
var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME'
monkeypatch.setenv(var, str(path))
return path


@pytest.fixture
def temp_home(tmp_path, monkeypatch):
var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME'
monkeypatch.setenv(var, str(tmp_path))
return tmp_path
return _set_home(monkeypatch, tmp_path)


@pytest.fixture
def fake_home(fs, monkeypatch):
home = fs.create_dir('/fakehome')
return _set_home(monkeypatch, pathlib.Path(home.path))
13 changes: 13 additions & 0 deletions distutils/tests/test_dist.py
Expand Up @@ -258,6 +258,19 @@ def test_find_config_files_disable(self, temp_home):
# make sure --no-user-cfg disables the user cfg file
assert len(all_files) - 1 == len(files)

@pytest.mark.xfail(reason="pypa/distutils#181", strict=True)
@pytest.mark.skipif(
'platform.system() == "Windows"',
reason='Windows does not honor chmod 000',
)
def test_find_config_files_permission_error(self, fake_home):
"""
Finding config files should not fail when directory is inaccessible.
"""
fake_home.joinpath(pydistutils_cfg).write_text('')
fake_home.chmod(0o000)
Distribution().find_config_files()


@pytest.mark.usefixtures('save_env')
@pytest.mark.usefixtures('save_argv')
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -20,6 +20,7 @@ deps =
jaraco.text
path
docutils
pyfakefs
commands =
pytest {posargs}
setenv =
Expand Down

0 comments on commit faaf778

Please sign in to comment.