Skip to content

Commit

Permalink
Merge pull request #121 from dnozay/master
Browse files Browse the repository at this point in the history
Fix make_numbered_dir on case-insensitive filesystems.
  • Loading branch information
RonnyPfannschmidt committed May 4, 2017
2 parents 03282a4 + cf77241 commit a6392dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.4.34
====================================================================

- fix issue119 / pytest issue708 where tmpdir may fail to make numbered directories
when the filesystem is case-insensitive.

1.4.33
====================================================================

Expand Down
2 changes: 1 addition & 1 deletion py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(c) Holger Krekel and others, 2004-2014
"""
__version__ = '1.4.33'
__version__ = '1.4.34'

from py import _apipkg

Expand Down
10 changes: 6 additions & 4 deletions py/_path/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from py._path.common import iswin32, fspath
from stat import S_ISLNK, S_ISDIR, S_ISREG

from os.path import abspath, normpath, isabs, exists, isdir, isfile, islink, dirname
from os.path import abspath, normcase, normpath, isabs, exists, isdir, isfile, islink, dirname

if sys.version_info > (3,0):
def map_as_list(func, iter):
Expand Down Expand Up @@ -801,12 +801,13 @@ def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,
if rootdir is None:
rootdir = cls.get_temproot()

nprefix = normcase(prefix)
def parse_num(path):
""" parse the number out of a path (if it matches the prefix) """
bn = path.basename
if bn.startswith(prefix):
nbasename = normcase(path.basename)
if nbasename.startswith(nprefix):
try:
return int(bn[len(prefix):])
return int(nbasename[len(nprefix):])
except ValueError:
pass

Expand Down Expand Up @@ -898,6 +899,7 @@ def try_remove_lockfile():
return udir
make_numbered_dir = classmethod(make_numbered_dir)


def copymode(src, dest):
""" copy permission from src to dst. """
py.std.shutil.copymode(src, dest)
Expand Down
16 changes: 16 additions & 0 deletions testing/path/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ def test_make_numbered_dir(self, tmpdir):
if i>=3:
assert not numdir.new(ext=str(i-3)).check()

def test_make_numbered_dir_case_insensitive(self, tmpdir, monkeypatch):
# https://github.com/pytest-dev/pytest/issues/708
monkeypatch.setattr(py._path.local, 'normcase', lambda path: path.lower())
monkeypatch.setattr(tmpdir, 'listdir', lambda: [tmpdir._fastjoin('case.0')])
numdir = local.make_numbered_dir(prefix='CAse.', rootdir=tmpdir,
keep=2, lock_timeout=0)
assert numdir.basename.endswith('.1')

def test_make_numbered_dir_case_sensitive(self, tmpdir, monkeypatch):
# https://github.com/pytest-dev/pytest/issues/708
monkeypatch.setattr(py._path.local, 'normcase', lambda path: path)
monkeypatch.setattr(tmpdir, 'listdir', lambda: [tmpdir._fastjoin('case.0')])
numdir = local.make_numbered_dir(prefix='CAse.', rootdir=tmpdir,
keep=2, lock_timeout=0)
assert numdir.basename.endswith('.0')

def test_make_numbered_dir_NotImplemented_Error(self, tmpdir, monkeypatch):
def notimpl(x, y):
raise NotImplementedError(42)
Expand Down

0 comments on commit a6392dd

Please sign in to comment.