Skip to content

Commit

Permalink
Merge pull request #186 from asottile/make_num_dir_case_insens
Browse files Browse the repository at this point in the history
Don't make assumptions about fs case sensitivity in make_numbered_dir
  • Loading branch information
RonnyPfannschmidt committed Jun 21, 2018
2 parents 5f1f794 + 8acdb7e commit 0f77b6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(unreleased)
============

- fix pytest-dev/pytest#3451: don't make assumptions about fs case sensitivity
in ``make_numbered_dir``.

1.5.3
=====
Expand Down
10 changes: 5 additions & 5 deletions py/_path/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from __future__ import with_statement

from contextlib import contextmanager
import sys, os, re, atexit, io, uuid
import sys, os, atexit, io, uuid
import py
from py._path import common
from py._path.common import iswin32, fspath
from stat import S_ISLNK, S_ISDIR, S_ISREG

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

if sys.version_info > (3,0):
def map_as_list(func, iter):
Expand Down Expand Up @@ -800,7 +800,7 @@ def mkdtemp(cls, rootdir=None):
return cls(py.error.checked_call(tempfile.mkdtemp, dir=str(rootdir)))

def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,
lock_timeout = 172800): # two days
lock_timeout=172800): # two days
""" return unique directory with a number greater than the current
maximum one. The number is assumed to start directly after prefix.
if keep is true directories with a number less than (maxnum-keep)
Expand All @@ -810,10 +810,10 @@ def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,
if rootdir is None:
rootdir = cls.get_temproot()

nprefix = normcase(prefix)
nprefix = prefix.lower()
def parse_num(path):
""" parse the number out of a path (if it matches the prefix) """
nbasename = normcase(path.basename)
nbasename = path.basename.lower()
if nbasename.startswith(nprefix):
try:
return int(nbasename[len(nprefix):])
Expand Down
35 changes: 17 additions & 18 deletions testing/path/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,24 +425,23 @@ 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_case(self, tmpdir):
"""make_numbered_dir does not make assumptions on the underlying
filesystem based on the platform and will assume it _could_ be case
insensitive.
See issues:
- https://github.com/pytest-dev/pytest/issues/708
- https://github.com/pytest-dev/pytest/issues/3451
"""
d1 = local.make_numbered_dir(
prefix='CAse.', rootdir=tmpdir, keep=2, lock_timeout=0,
)
d2 = local.make_numbered_dir(
prefix='caSE.', rootdir=tmpdir, keep=2, lock_timeout=0,
)
assert str(d1).lower() != str(d2).lower()
assert str(d2).endswith('.1')

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

0 comments on commit 0f77b6e

Please sign in to comment.