factor out win32 checks

This commit is contained in:
Benjamin Peterson 2011-08-18 18:15:30 -05:00
parent c426a67b0e
commit 9675b0f65c
1 changed files with 8 additions and 4 deletions

View File

@ -15,6 +15,12 @@ import py
from _pytest.assertion import util
# Windows gives ENOENT in places *nix gives ENOTDIR.
if sys.platform.startswith("win"):
PATH_COMPONENT_NOT_DIR = errno.ENOENT
else:
PATH_COMPONENT_NOT_DIR = errno.ENOTDIR
# py.test caches rewritten pycs in __pycache__.
if hasattr(imp, "get_tag"):
PYTEST_TAG = imp.get_tag() + "-PYTEST"
@ -106,8 +112,7 @@ class AssertionRewritingHook(object):
# common case) or it's blocked by a non-dir node. In the
# latter case, we'll ignore it in _write_pyc.
pass
elif (e == errno.ENOTDIR or
sys.platform == "win32" and e == errno.ENOENT):
elif e == PATH_COMPONENT_NOT_DIR:
# One of the path components was not a directory, likely
# because we're in a zip file.
write = False
@ -160,8 +165,7 @@ def _write_pyc(co, source_path, pyc):
fp = open(pyc, "wb")
except IOError:
err = sys.exc_info()[1].errno
if (err == errno.ENOTDIR or
sys.platform == "win32" and err == errno.ENOENT):
if err == PATH_COMPONENT_NOT_DIR:
# This happens when we get a EEXIST in find_module creating the
# __pycache__ directory and __pycache__ is by some non-dir node.
return False