Skip to content

Commit 0f77b6e

Browse files
Merge pull request #186 from asottile/make_num_dir_case_insens
Don't make assumptions about fs case sensitivity in make_numbered_dir
2 parents 5f1f794 + 8acdb7e commit 0f77b6e

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(unreleased)
22
============
33

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

57
1.5.3
68
=====

py/_path/local.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from __future__ import with_statement
55

66
from contextlib import contextmanager
7-
import sys, os, re, atexit, io, uuid
7+
import sys, os, atexit, io, uuid
88
import py
99
from py._path import common
1010
from py._path.common import iswin32, fspath
1111
from stat import S_ISLNK, S_ISDIR, S_ISREG
1212

13-
from os.path import abspath, normcase, normpath, isabs, exists, isdir, isfile, islink, dirname
13+
from os.path import abspath, normpath, isabs, exists, isdir, isfile, islink, dirname
1414

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

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

813-
nprefix = normcase(prefix)
813+
nprefix = prefix.lower()
814814
def parse_num(path):
815815
""" parse the number out of a path (if it matches the prefix) """
816-
nbasename = normcase(path.basename)
816+
nbasename = path.basename.lower()
817817
if nbasename.startswith(nprefix):
818818
try:
819819
return int(nbasename[len(nprefix):])

testing/path/test_local.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,23 @@ def test_make_numbered_dir(self, tmpdir):
425425
if i >= 3:
426426
assert not numdir.new(ext=str(i-3)).check()
427427

428-
def test_make_numbered_dir_case_insensitive(self, tmpdir, monkeypatch):
429-
# https://github.com/pytest-dev/pytest/issues/708
430-
monkeypatch.setattr(py._path.local, 'normcase',
431-
lambda path: path.lower())
432-
monkeypatch.setattr(tmpdir, 'listdir',
433-
lambda: [tmpdir._fastjoin('case.0')])
434-
numdir = local.make_numbered_dir(prefix='CAse.', rootdir=tmpdir,
435-
keep=2, lock_timeout=0)
436-
assert numdir.basename.endswith('.1')
437-
438-
def test_make_numbered_dir_case_sensitive(self, tmpdir, monkeypatch):
439-
# https://github.com/pytest-dev/pytest/issues/708
440-
monkeypatch.setattr(py._path.local, 'normcase', lambda path: path)
441-
monkeypatch.setattr(tmpdir, 'listdir',
442-
lambda: [tmpdir._fastjoin('case.0')])
443-
numdir = local.make_numbered_dir(prefix='CAse.', rootdir=tmpdir,
444-
keep=2, lock_timeout=0)
445-
assert numdir.basename.endswith('.0')
428+
def test_make_numbered_dir_case(self, tmpdir):
429+
"""make_numbered_dir does not make assumptions on the underlying
430+
filesystem based on the platform and will assume it _could_ be case
431+
insensitive.
432+
433+
See issues:
434+
- https://github.com/pytest-dev/pytest/issues/708
435+
- https://github.com/pytest-dev/pytest/issues/3451
436+
"""
437+
d1 = local.make_numbered_dir(
438+
prefix='CAse.', rootdir=tmpdir, keep=2, lock_timeout=0,
439+
)
440+
d2 = local.make_numbered_dir(
441+
prefix='caSE.', rootdir=tmpdir, keep=2, lock_timeout=0,
442+
)
443+
assert str(d1).lower() != str(d2).lower()
444+
assert str(d2).endswith('.1')
446445

447446
def test_make_numbered_dir_NotImplemented_Error(self, tmpdir, monkeypatch):
448447
def notimpl(x, y):

0 commit comments

Comments
 (0)