def check_example(dirname, fn_script, fns_data):
with tmpdir(__name__, dirname + fn_script) as dntmp:<EOL><INDENT>for fn in [fn_script] + fns_data:<EOL><INDENT>with pkg_resources.resource_stream("<STR_LIT>", "<STR_LIT>".format(dirname, fn)) as fin:<EOL><INDENT>if '<STR_LIT:/>' in fn:<EOL><INDENT>subdntmp = os.path.join(dntmp, os.path.dirname(fn))<EOL>if not os.path.isdir(subdntmp):<EOL><INDENT>os.makedirs(subdntmp)<EOL><DEDENT><DEDENT>with open(os.path.join(dntmp, fn), '<STR_LIT:wb>') as fout:<EOL><INDENT>fout.write(fin.read())<EOL><DEDENT><DEDENT><DEDENT>env = dict(os.environ)<EOL>root_dir = os.getcwd()<EOL>env['<STR_LIT>'] = root_dir + '<STR_LIT::>' + env.get('<STR_LIT>', '<STR_LIT>')<EOL>path_script = os.path.join(dntmp, fn_script)<EOL>os.chmod(path_script, os.stat(path_script).st_mode | stat.S_IXUSR)<EOL>command = ["<STR_LIT>", fn_script]<EOL>proc = subprocess.Popen(command, stdin=subprocess.PIPE,<EOL>stdout=subprocess.PIPE, stderr=subprocess.PIPE,<EOL>cwd=dntmp, env=env)<EOL>outdata, errdata = proc.communicate()<EOL>if proc.returncode != <NUM_LIT:0>:<EOL><INDENT>lines = [<EOL>'<STR_LIT>', str(command), '<STR_LIT>', '<STR_LIT:+>'*<NUM_LIT>, outdata.decode('<STR_LIT:utf-8>'),<EOL>'<STR_LIT:+>'*<NUM_LIT>, '<STR_LIT>', '<STR_LIT:+>'*<NUM_LIT>, errdata.decode('<STR_LIT:utf-8>'), '<STR_LIT:+>'*<NUM_LIT>]<EOL>raise AssertionError('<STR_LIT:\n>'.join(lines))<EOL><DEDENT><DEDENT>
Run an example in a temporary directory and check its exit code.

    Parameters
    ----------
    dirname : str
        The directory with the example, relative to the __file__ of where you call this
        function.
    fn_script : str
        The name of the script to be executed, assumed to be present in the given
        directory.
    fns_data : list of str:
        A list of data files needed by the example, which will be copied over to the
        temporary directory.