mirror of
https://github.com/ocrmypdf/OCRmyPDF.git
synced 2026-05-04 20:54:18 -04:00
Fix Python 3.5 test suite failure on symlinks
Did not account for API difference in pathlib
This commit is contained in:
@@ -64,9 +64,20 @@ def is_file_writable(test_file):
|
||||
the location is writable.
|
||||
"""
|
||||
p = Path(test_file)
|
||||
|
||||
if p.is_symlink():
|
||||
p = p.resolve()
|
||||
if p.is_file():
|
||||
# Python 3.5 does not accept parameters for Path.resolve() and behaves
|
||||
# as if strict=True (throws an exception on failure). Python 3.6
|
||||
# defaults to strict=False. This implements strict=False like behavior
|
||||
# for Python 3.5.
|
||||
if sys.version_info[0:2] <= (3, 5):
|
||||
resolve = lambda: Path(os.path.realpath(str(p)))
|
||||
else:
|
||||
resolve = lambda: p.resolve(strict=False)
|
||||
p = resolve()
|
||||
|
||||
# p.is_file() throws an exception in some cases
|
||||
if p.exists() and p.is_file():
|
||||
return os.access(
|
||||
str(p), os.W_OK,
|
||||
effective_ids=(os.access in os.supports_effective_ids))
|
||||
|
||||
@@ -1134,6 +1134,6 @@ def test_output_is_symlink(spoof_tesseract_noop, resources, outdir):
|
||||
'--force-ocr',
|
||||
env=spoof_tesseract_noop
|
||||
)
|
||||
assert p.returncode == ExitCode.ok
|
||||
assert p.returncode == ExitCode.ok, err
|
||||
assert (outdir / 'out.pdf').stat().st_size > 0, 'target file not created'
|
||||
|
||||
Reference in New Issue
Block a user