diff options
author | dluyer <53582923+dluyer@users.noreply.github.com> | 2019-08-06 09:58:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-06 09:58:19 -0700 |
commit | 1dd76ca951670f87b78b75c78697647001f68386 (patch) | |
tree | c0649e03966e14ddd0d5fc96ef4e2b50e39c71a4 | |
parent | af9d9d91bb80d3c7783a0e6fe8d1bb67790e615a (diff) | |
download | pexpect-git-1dd76ca951670f87b78b75c78697647001f68386.tar.gz |
Fix test_ansi.py when running in a non-writable directory
-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..2140013 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) @@ -118,8 +121,17 @@ class ansiTestCase (PexpectTestCase.PexpectTestCase): def test_torturet (self): s = ANSI.ANSI (24,80) - with open('torturet.vt') as f: - sample_text = f.read() + # 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: + with open('torturet.vt') as f: + sample_text = f.read() + finally: + os.chdir(old_cwd) + shutil.rmtree(d) for c in sample_text: s.process (c) assert s.pretty() == torture_target, 'processed: \n' + s.pretty() + '\nexpected:\n' + torture_target |