From: W. Trevor King Date: Tue, 5 Feb 2013 19:09:05 +0000 (-0500) Subject: question: Normalize tempdir paths in stdout/stderr X-Git-Tag: v0.1~54 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=669d03b3a43d6c978b6dbe92a6e3e4ea769b8eb2;p=quizzer.git question: Normalize tempdir paths in stdout/stderr Otherwise it's hard to test `pwd`, since tempdir will change between the expected and user-supplied answer runs. --- diff --git a/quizzer/question.py b/quizzer/question.py index 34fe8c1..a9d00c0 100644 --- a/quizzer/question.py +++ b/quizzer/question.py @@ -1,4 +1,5 @@ import logging as _logging +import os.path as _os_path import tempfile as _tempfile from . import error as _error @@ -109,16 +110,20 @@ class ScriptQuestion (Question): return True def _invoke(self, answer): - with _tempfile.TemporaryDirectory( - prefix='{}-'.format(type(self).__name__), - ) as tempdir: + prefix = '{}-'.format(type(self).__name__) + with _tempfile.TemporaryDirectory(prefix=prefix) as tempdir: script = '\n'.join(self.setup + [answer] + self.teardown) - return _util.invoke( + status,stdout,stderr = _util.invoke( args=[self.interpreter], stdin=script, cwd=tempdir, universal_newlines=True, - timeout=self.timeout,) + timeout=self.timeout, + ) + dirname = _os_path.basename(tempdir) + stdout = stdout.replace(dirname, '{}XXXXXX'.format(prefix)) + stderr = stderr.replace(dirname, '{}XXXXXX'.format(prefix)) + return status,stdout,stderr for name,obj in list(locals().items()): if name.startswith('_'):