summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Silvester <steven.silvester@ieee.org>2014-12-01 21:27:33 -0600
committerThomas Kluyver <takowl@gmail.com>2015-09-12 11:49:09 +0100
commitcd9296c1b93bcdd1006cd044110c3e806c322a66 (patch)
tree31d31deae221bcdcd44dde250f21e885ced32050
parent6407d849d4719c9aeda1eca011808044fb126764 (diff)
downloadpexpect-git-cd9296c1b93bcdd1006cd044110c3e806c322a66.tar.gz
Fix popen spawn and tests on windows
Cleanup Always close stdin
-rw-r--r--pexpect/popen_spawn.py8
-rw-r--r--tests/test_popen_spawn.py14
2 files changed, 9 insertions, 13 deletions
diff --git a/pexpect/popen_spawn.py b/pexpect/popen_spawn.py
index 389c505..887d0a4 100644
--- a/pexpect/popen_spawn.py
+++ b/pexpect/popen_spawn.py
@@ -128,8 +128,7 @@ class PopenSpawn(SpawnBase):
automatically appended. Returns number of bytes written. '''
n = self.send(s)
- n = n + self.send(self.linesep)
- return n
+ return n + self.send(self.linesep)
def wait(self):
status = self.proc.wait()
@@ -154,10 +153,7 @@ class PopenSpawn(SpawnBase):
os.kill(self.proc.pid, sig)
def sendeof(self):
- if sys.platform == 'win32':
- self.kill(signal.CTRL_BREAK_EVENT)
- else:
- self.kill(signal.SIGTERM)
+ self.proc.stdin.close()
class PopenSpawnUnicode(SpawnBaseUnicode, PopenSpawn):
diff --git a/tests/test_popen_spawn.py b/tests/test_popen_spawn.py
index 3431e49..740b510 100644
--- a/tests/test_popen_spawn.py
+++ b/tests/test_popen_spawn.py
@@ -52,9 +52,9 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
p.expect_exact(pexpect.EOF)
def test_expect(self):
- the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ the_old_way = subprocess.Popen(args=['ls', '-l', '~'],
stdout=subprocess.PIPE).communicate()[0].rstrip()
- p = PopenSpawn('ls -l /bin')
+ p = PopenSpawn('ls -l ~')
the_new_way = b''
while 1:
i = p.expect([b'\n', pexpect.EOF])
@@ -66,9 +66,9 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
assert the_old_way == the_new_way, len(the_old_way) - len(the_new_way)
def test_expect_exact(self):
- the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ the_old_way = subprocess.Popen(args=['ls', '-l', '~'],
stdout=subprocess.PIPE).communicate()[0].rstrip()
- p = PopenSpawn('ls -l /bin')
+ p = PopenSpawn('ls -l ~')
the_new_way = b''
while 1:
i = p.expect_exact([b'\n', pexpect.EOF])
@@ -85,9 +85,9 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
self.assertEqual(p.after, b'.?')
def test_expect_eof(self):
- the_old_way = subprocess.Popen(args=['/bin/ls', '-l', '/bin'],
+ the_old_way = subprocess.Popen(args=['ls', '-l', '~'],
stdout=subprocess.PIPE).communicate()[0].rstrip()
- p = PopenSpawn('/bin/ls -l /bin')
+ p = PopenSpawn('ls -l ~')
# This basically tells it to read everything. Same as pexpect.run()
# function.
p.expect(pexpect.EOF)
@@ -100,7 +100,7 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
self.assertEqual(p.after, pexpect.TIMEOUT)
def test_unexpected_eof(self):
- p = PopenSpawn('ls -l /bin')
+ p = PopenSpawn('ls -l ~')
try:
p.expect('_Z_XY_XZ') # Probably never see this in ls output.
except pexpect.EOF: