diff options
author | Thomas Kluyver <takowl@gmail.com> | 2019-08-07 07:57:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-07 07:57:54 +0100 |
commit | c0f8a4c56730e4a68fefb9b10db9fb5932a33bb4 (patch) | |
tree | c754928baf4afa4b89161724376f8f5096c7ff2b /tests | |
parent | 5440ed260f0f2fde56e1dba3a90835ad33f2d678 (diff) | |
parent | 2f9291a2b645781838722148c7c5e03fe4c38a7f (diff) | |
download | pexpect-git-c0f8a4c56730e4a68fefb9b10db9fb5932a33bb4.tar.gz |
Merge pull request #582 from dluyer/patch-5
Fix test_ansi.py when running in a non-writable directory
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_ansi.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/test_ansi.py b/tests/test_ansi.py index a9d445e..3d73fe8 100755 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -21,7 +21,10 @@ PEXPECT LICENSE from pexpect import ANSI import unittest from . import PexpectTestCase +import os +import shutil import sys +import tempfile PY3 = (sys.version_info[0] >= 3) @@ -120,8 +123,17 @@ class ansiTestCase (PexpectTestCase.PexpectTestCase): s = ANSI.ANSI (24,80) with open('torturet.vt') as f: sample_text = f.read() - for c in sample_text: - s.process (c) + # This causes ANSI.py's DoLog to write in the cwd. Make sure we're in a + # writeable directory. + d = tempfile.mkdtemp() + old_cwd = os.getcwd() + os.chdir(d) + try: + for c in sample_text: + s.process (c) + finally: + os.chdir(old_cwd) + shutil.rmtree(d) assert s.pretty() == torture_target, 'processed: \n' + s.pretty() + '\nexpected:\n' + torture_target def test_tetris (self): |