diff options
author | jquast <contact@jeffquast.com> | 2013-09-22 09:17:39 -0400 |
---|---|---|
committer | jquast <contact@jeffquast.com> | 2013-09-22 09:17:39 -0400 |
commit | 09c2dd7900b34712cea1607bcda5d8f98e67923c (patch) | |
tree | c42fe0d49dc0fb6259fa338f93d09b3c9f3185da /tests/test_unicode.py | |
parent | e1eeefafd206b7d13b25f64bfb00f5d944690723 (diff) | |
download | pexpect-git-09c2dd7900b34712cea1607bcda5d8f98e67923c.tar.gz |
cat(1) may display ^D\x08\x08 when ^D is used.
This causes various tests, that depend on cat(1) to fail on Mac OSX 10.8.5. These changes ensure that if ^D\x08\x08 ('^D', followed by '\b\b') is found, it is removed.
Diffstat (limited to 'tests/test_unicode.py')
-rw-r--r-- | tests/test_unicode.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/test_unicode.py b/tests/test_unicode.py index a17f21e..eefdfbf 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -7,6 +7,9 @@ import pexpect import unittest import PexpectTestCase +# the program cat(1) may display ^D\x08\x08 when \x04 (EOF, Ctrl-D) is sent +_CAT_EOF = b'^D\x08\x08' + class UnicodeTests(PexpectTestCase.PexpectTestCase): def test_expect_basic (self): p = pexpect.spawnu('cat') @@ -82,7 +85,14 @@ class UnicodeTests(PexpectTestCase.PexpectTestCase): self.assertEqual(f.read(), msg+'\n\x04') with io.open(filename_read, encoding='utf-8', newline='') as f: - self.assertEqual(f.read(), (msg+'\r\n')*2 ) + output = f.read() + # ^D\x08\x08 may be found twice, at the end of each ``msg``, + # strip if found. + idx = output.find(_CAT_EOF.decode('utf-8')) + while idx != -1: + output = output[:idx] + output[idx + len(_CAT_EOF):] + idx = output.find(_CAT_EOF.decode('utf-8')) + self.assertEqual(output, (msg+'\r\n')*2 ) def test_spawn_expect_ascii_unicode(self): @@ -108,4 +118,4 @@ class UnicodeTests(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(UnicodeTests, 'test')
\ No newline at end of file +suite = unittest.makeSuite(UnicodeTests, 'test') |