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

path.common: handle FileNotFoundError when trying to import pathlib #207

Merged
merged 3 commits into from Apr 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,3 +1,9 @@
Unreleased
==========

- handle ``FileNotFoundError`` when trying to import pathlib in ``path.common``
on Python 3.4 (#207).

1.8.0 (2019-02-21)
==================

Expand Down
8 changes: 7 additions & 1 deletion py/_path/common.py
Expand Up @@ -10,6 +10,12 @@
# Moved from local.py.
iswin32 = sys.platform == "win32" or (getattr(os, '_name', False) == 'nt')

try:
# FileNotFoundError might happen in py34, and is not available with py27.
import_errors = (ImportError, FileNotFoundError)
except NameError:
import_errors = (ImportError,)

try:
from os import fspath
except ImportError:
Expand All @@ -35,7 +41,7 @@ def fspath(path):
raise
try:
import pathlib
except ImportError:
except import_errors:
pass
else:
if isinstance(path, pathlib.PurePath):
Expand Down
26 changes: 25 additions & 1 deletion testing/path/test_local.py
Expand Up @@ -174,7 +174,31 @@ def test_eq_with_strings(self, path1):
assert path2 != path3

def test_eq_with_none(self, path1):
assert path1 != None # noqa
assert path1 != None # noqa: E711

@pytest.mark.skipif(
sys.platform.startswith("win32"), reason="cannot remove cwd on Windows"
)
@pytest.mark.skipif(
sys.version_info < (3, 0) or sys.version_info >= (3, 5),
reason="only with Python 3 before 3.5"
nicoddemus marked this conversation as resolved.
Show resolved Hide resolved
)
def test_eq_with_none_and_custom_fspath(self, monkeypatch, path1):
import os
import shutil
import tempfile

d = tempfile.mkdtemp()
monkeypatch.chdir(d)
shutil.rmtree(d)

monkeypatch.delitem(sys.modules, 'pathlib', raising=False)
monkeypatch.setattr(sys, 'path', [''] + sys.path)

with pytest.raises(FileNotFoundError):
import pathlib # noqa: F401

assert path1 != None # noqa: E711

def test_eq_non_ascii_unicode(self, path1):
path2 = path1.join(u'temp')
Expand Down