Fix uncaught exception on unreadable files (#2196)

* Avoid bailing out with uncaught `PermissionError`

* Update codespell_lib/tests/test_basic.py

* FIX: Coverage

* FIX: Already short-circuited

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
This commit is contained in:
Dimitri Papadopoulos Orfanos
2022-10-19 17:44:09 +02:00
committed by GitHub
parent 1c081fa945
commit a050986bf8
5 changed files with 29 additions and 5 deletions

View File

@ -122,6 +122,20 @@ def test_basic(tmpdir, capsys):
assert cs.main(d) == 0
@pytest.mark.skipif(
not sys.platform == 'linux', reason='Only supported on Linux')
def test_permission_error(tmp_path, capsys):
"""Test permission error handling."""
d = tmp_path
with open(d / 'unreadable.txt', 'w') as f:
f.write('abandonned\n')
code, _, stderr = cs.main(f.name, std=True)
assert 'WARNING:' not in stderr
os.chmod(f.name, 0o000)
code, _, stderr = cs.main(f.name, std=True)
assert 'WARNING:' in stderr
def test_interactivity(tmpdir, capsys):
"""Test interaction"""
# Windows can't read a currently-opened file, so here we use