def test_which_should_not_match_folders(self):
" Which does not match folders, even though they are executable. "
# make up a path and insert a folder that is 'executable', a naive
# implementation might match (previously pexpect versions 3.2 and
# sh versions 1.0.8, reported by @lcm337.)
fname = 'g++'
bin_dir = tempfile.mkdtemp()
bin_dir2 = os.path.join(bin_dir, fname)
save_path = os.environ['PATH']
try:
os.environ['PATH'] = bin_dir
os.mkdir(bin_dir2, 0o755)
# should not be found because it is not executable *file*,
# but rather, has the executable bit set, as a good folder
# should -- it should not be returned because it fails isdir()
exercise = pexpect.which(fname)
assert exercise is None
finally:
# restore,
os.environ['PATH'] = save_path
# destroy scratch folders,
for _dir in (bin_dir2, bin_dir,):
if os.path.exists(_dir):
os.rmdir(_dir)
评论列表
文章目录