From ed7a2d2da34ddeffd70735875803c0d966b4fdce Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 27 Apr 2010 16:10:25 +0200 Subject: [PATCH] refine/fix isimportable-logic and ensure that 'tmpdir' has a python-importable name --HG-- branch : trunk --- py/_path/local.py | 6 +++++- py/_test/config.py | 2 +- testing/path/test_local.py | 11 +++++++++++ testing/plugin/test_pytest_tmpdir.py | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/py/_path/local.py b/py/_path/local.py index 37e62037c..6616601e1 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -802,4 +802,8 @@ def autopath(globs=None): def isimportable(name): - return name[0].isalpha() and name.isalnum() + if name: + if not (name[0].isalpha() or name[0] == '_'): + return False + name= name.replace("_", '') + return not name or name.isalnum() diff --git a/py/_test/config.py b/py/_test/config.py index 46945a207..03e27ece5 100644 --- a/py/_test/config.py +++ b/py/_test/config.py @@ -151,7 +151,7 @@ class Config(object): if not numbered: return basetemp.mkdir(basename) else: - return py.path.local.make_numbered_dir(prefix=basename + "-", + return py.path.local.make_numbered_dir(prefix=basename, keep=0, rootdir=basetemp, lock_timeout=None) def getinitialnodes(self): diff --git a/testing/path/test_local.py b/testing/path/test_local.py index 8de95ab92..5a58b3548 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -363,6 +363,17 @@ def test_pypkgdir_unimportable(tmpdir): assert subdir.ensure("xyz.py").pypkgpath() == subdir assert not pkg.pypkgpath() +def test_isimportable(): + from py._path.local import isimportable + assert not isimportable("") + assert isimportable("x") + assert isimportable("x1") + assert isimportable("x_1") + assert isimportable("_") + assert isimportable("_1") + assert not isimportable("x-1") + assert not isimportable("x:1") + def test_homedir(): homedir = py.path.local._gethomedir() assert homedir.check(dir=1) diff --git a/testing/plugin/test_pytest_tmpdir.py b/testing/plugin/test_pytest_tmpdir.py index a89405cd7..692956f45 100644 --- a/testing/plugin/test_pytest_tmpdir.py +++ b/testing/plugin/test_pytest_tmpdir.py @@ -5,5 +5,5 @@ def test_funcarg(testdir): item = testdir.getitem("def test_func(tmpdir): pass") p = pytest_funcarg__tmpdir(FuncargRequest(item)) assert p.check() - bn = p.basename.strip("0123456789-") + bn = p.basename.strip("0123456789") assert bn.endswith("test_func")