| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import py |
| 5 |
import sys |
| 6 |
from tempfile import NamedTemporaryFile |
| 7 |
|
| 8 |
class ExpectTest(object): |
| 9 |
def _spawn(self, *args, **kwds): |
| 10 |
import pexpect |
| 11 |
kwds.setdefault('timeout', 600) |
| 12 |
child = pexpect.spawn(*args, **kwds) |
| 13 |
child.logfile = sys.stdout |
| 14 |
return child |
| 15 |
|
| 16 |
def spawn(self, argv): |
| 17 |
return self._spawn(sys.executable, argv) |
| 18 |
|
| 19 |
def run_test(self, func): |
| 20 |
try: |
| 21 |
import pexpect |
| 22 |
except ImportError: |
| 23 |
py.test.skip("pexpect not found") |
| 24 |
source = py.code.Source(func)[1:].deindent() |
| 25 |
tmpfile = NamedTemporaryFile(suffix='.py') |
| 26 |
fname = tmpfile.name |
| 27 |
dir_to_insert = py.path.local(__file__).join('..', '..', '..', '..') |
| 28 |
source.lines = ['import sys', |
| 29 |
'sys.path.insert(0, %s)' % repr(str(dir_to_insert)) |
| 30 |
] + source.lines |
| 31 |
source.lines.append('print "%s ok!"' % fname) |
| 32 |
f = py.path.local(fname) |
| 33 |
f.write(source) |
| 34 |
|
| 35 |
child = self.spawn([str(f)]) |
| 36 |
import re |
| 37 |
child.expect(re.escape(fname + " ok!")) |