summaryrefslogtreecommitdiff
path: root/tests/test_misc.py
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2014-06-10 12:40:22 -0700
committerThomas Kluyver <takowl@gmail.com>2014-06-10 12:40:22 -0700
commit7f14d7cd7390816d96d2e511189bec22f6824d91 (patch)
tree298d9e4cfcac41dd04e79a7f9df4c96c7b40c677 /tests/test_misc.py
parentf46de45cddbf6d0906000e3bf052051a85a15269 (diff)
parentc5b744c44bee1856b8a5f0f70560cc0eb02fd834 (diff)
downloadpexpect-7f14d7cd7390816d96d2e511189bec22f6824d91.tar.gz
Merge pull request #70 from pexpect/more-exacting-which
new function is_exe() makes existing which() more correct
Diffstat (limited to 'tests/test_misc.py')
-rwxr-xr-xtests/test_misc.py76
1 files changed, 0 insertions, 76 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 93ff930..a052fe5 100755
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -21,9 +21,7 @@ PEXPECT LICENSE
import pexpect
import unittest
from . import PexpectTestCase
-import os
import sys
-import tempfile
import re
import signal
import time
@@ -259,80 +257,6 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
assert default!=tmpdir, "'default' and 'tmpdir' should be different"
assert (b'tmp' in tmpdir), "'tmp' should be returned by 'pwd' command"
- def test_basic_which(self):
- # should find at least 'ls' program, and it should begin with '/'
- exercise = pexpect.which("ls")
- assert exercise is not None and exercise.startswith('/')
-
- def test_absolute_which(self):
- # make up a path and insert first a non-executable,
- # then, make it executable, and assert we may which() find it.
- fname = 'gcc'
- bin_dir = tempfile.mkdtemp()
- bin_path = os.path.join(bin_dir, fname)
- save_path = os.environ['PATH']
- try:
- # setup
- os.environ['PATH'] = bin_dir
- with open(bin_path, 'w') as fp:
- fp.write('#!/bin/sh\necho hello, world\n')
- os.chmod(bin_path, 0o400)
-
- # it should not be found because it is not executable
- assert pexpect.which(fname) is None, fname
-
- # but now it should -- because it is executable
- os.chmod(bin_path, 0o700)
- assert pexpect.which(fname) == bin_path, (fname, bin_path)
-
- finally:
- # restore,
- os.environ['PATH'] = save_path
- # destroy scratch files and folders,
- if os.path.exists(bin_path):
- os.unlink(bin_path)
- if os.path.exists(bin_dir):
- os.rmdir(bin_dir)
-
- def test_which_should_not_match_folders(self):
- # make up a path and insert a folder, which is 'executable', which
- # 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)
- # it should not be found because it is not executable *file*,
- # but rather, has the executable bit set, as a good folder
- # should -- it shouldn't be returned because it fails isdir()
- exercise = pexpect.which(fname)
- assert exercise is None, exercise
-
- 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)
-
- def test_which (self):
- p = os.defpath
- ep = os.environ['PATH']
- os.defpath = ":/tmp"
- os.environ['PATH'] = ":/tmp"
- wp = pexpect.which ("ticker.py")
- assert wp == 'ticker.py', "Should return a string. Returned %s" % wp
- os.defpath = "/tmp"
- os.environ['PATH'] = "/tmp"
- wp = pexpect.which ("ticker.py")
- assert wp == None, "Executable should not be found. Returned %s" % wp
- os.defpath = p
- os.environ['PATH'] = ep
-
def test_searcher_re (self):
# This should be done programatically, if we copied and pasted output,
# there wouldnt be a whole lot to test, really, other than our ability