[FIX] EOF handling moved upper to handle exception of last characters' patterns

This commit is contained in:
Benedek Racz 2020-04-02 19:50:45 +02:00
parent 96987d4030
commit 3ba138a6fc
2 changed files with 7 additions and 6 deletions

View File

@ -8,7 +8,6 @@ import os
import wexpect import wexpect
from tests import PexpectTestCase from tests import PexpectTestCase
from .utils import no_coverage_env
# Many of these test cases blindly assume that sequential directory # Many of these test cases blindly assume that sequential directory
# listings of the /bin directory will yield the same results. # listings of the /bin directory will yield the same results.
@ -279,14 +278,14 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
def test_before_after(self): def test_before_after(self):
'''This tests expect() for some simple before/after things. '''This tests expect() for some simple before/after things.
''' '''
p = wexpect.spawn('%s -Wi list100.py' % PYTHONBINQUOTE, env=no_coverage_env()) p = wexpect.spawn('%s -Wi list100.py' % PYTHONBINQUOTE)
self._before_after(p) self._before_after(p)
def test_before_after_exact(self): def test_before_after_exact(self):
'''This tests some simple before/after things, for '''This tests some simple before/after things, for
expect_exact(). (Grahn broke it at one point.) expect_exact(). (Grahn broke it at one point.)
''' '''
p = wexpect.spawn('%s -Wi list100.py' % PYTHONBINQUOTE, env=no_coverage_env()) p = wexpect.spawn('%s -Wi list100.py' % PYTHONBINQUOTE)
# mangle the spawn so we test expect_exact() instead # mangle the spawn so we test expect_exact() instead
p.expect = p.expect_exact p.expect = p.expect_exact
self._before_after(p) self._before_after(p)

View File

@ -814,6 +814,8 @@ class SpawnBase:
self.match_index = index self.match_index = index
return self.match_index return self.match_index
# No match at this point # No match at this point
if self.flag_eof:
raise EOF('EOF flag has been raised.')
if timeout is not None and end_time < time.time(): if timeout is not None and end_time < time.time():
logger.info('Timeout exceeded in expect_any().') logger.info('Timeout exceeded in expect_any().')
raise TIMEOUT('Timeout exceeded in expect_any().') raise TIMEOUT('Timeout exceeded in expect_any().')
@ -932,10 +934,10 @@ class SpawnPipe(SpawnBase):
else: else:
logger.spam(f'Readed: {s}') logger.spam(f'Readed: {s}')
if b'\x04' in s: if EOF_CHAR in s:
self.flag_eof = True self.flag_eof = True
logger.info("EOF: EOF character has been arrived") logger.info("EOF: EOF character has been arrived")
raise EOF('EOF character has been arrived') s = s.split(EOF_CHAR)[0]
return s.decode() return s.decode()
except pywintypes.error as e: except pywintypes.error as e:
@ -1052,7 +1054,7 @@ class SpawnSocket(SpawnBase):
if EOF_CHAR in s: if EOF_CHAR in s:
self.flag_eof = True self.flag_eof = True
logger.info("EOF: EOF character has been arrived") logger.info("EOF: EOF character has been arrived")
raise EOF('EOF character has been arrived') s = s.split(EOF_CHAR)[0]
except ConnectionResetError: except ConnectionResetError:
self.flag_eof = True self.flag_eof = True