@contextlib.contextmanager
def example_script(name, output='success'):
 tempdir = tempfile.mkdtemp(prefix='tmp-pexpect-test')
 try:
  script_path = os.path.join(tempdir, name)
  with open(script_path, 'w') as f:
   f.write(('#!/bin/sh\necho "%s"' % (output,)))
  try:
   os.chmod(script_path, 493)
   (yield tempdir)
  finally:
   os.remove(script_path)
 finally:
  os.rmdir(tempdir)

@ contextlib . contextmanager def example_script ( name , output = 'success' ) : tempdir = tempfile . mkdtemp ( prefix = 'tmp-pexpect-test' ) try : script_path = os . path . join ( tempdir , name ) with open ( script_path , 'w' ) as f : f . write ( ( '#!/bin/sh\necho "%s"' % ( output , ) ) ) try : os . chmod ( script_path , 493 ) ( yield tempdir ) finally : os . remove ( script_path ) finally : os . rmdir ( tempdir )
helper to create a temporary shell script that tests can run .