def run_tvnamer(with_files, with_flags = None, with_input = "", with_config = None, run_on_directory = False, with_coverage = True):
    """Runs tvnamer on list of file-names in with_files.
    with_files is a list of strings.
    with_flags is a list of command line arguments to pass to tvnamer.
    with_input is the sent to tvnamer's stdin
    with_config is a string containing the tvnamer to run tvnamer with.

    Returns a dict with stdout, stderr and a list of files created
    """
    # Create dummy files (config and episodes)
    episodes_location = make_temp_dir()
    dummy_files = make_dummy_files(with_files, episodes_location)

    if with_config is not None:
        configfname = make_temp_config(with_config)
        conf_args = ['-c', configfname]
    else:
        conf_args = []

    if with_flags is None:
        with_flags = []

    if run_on_directory:
        files = [episodes_location]
    else:
        files = dummy_files

    # Copy sys.path to PYTHONPATH so same modules are available as in
    # test environmen
    env = os.environ.copy()
    env['PYTHONPATH'] = ":".join(sys.path)
    if with_coverage:
        # Get path to .coveragerc in parent dir
        covconf = os.path.abspath(
            os.path.join(
                os.path.dirname(os.path.abspath(__file__)),
                "..",
                ".coveragerc"))
        # Set env vars to flag to tvnamer/__init__.py to configure coverage.py
        env['COVERAGE_PROCESS_START'] = covconf
        env['TVNAMER_COVERAGE_SUBPROCESS'] = ''

    # Construct command
    cmd = [sys.executable, "-m", "tvnamer"] + conf_args + with_flags + files

    print("Running command:")
    print(" ".join(cmd))

    proc = subprocess.Popen(
        cmd,
        stdout = subprocess.PIPE,
        stderr = subprocess.STDOUT, # All stderr to stdout
        stdin = subprocess.PIPE,
        env=env)

    proc.stdin.write(with_input.encode("utf-8"))
    output, _ = proc.communicate()

    output = output.decode("utf-8")

    created_files = []

    for walkroot, walkdirs, walkfiles in os.walk(episodes_location):
        curlist = [
            os.path.join(
                walkroot,
                unicodedata.normalize('NFKD', name)) # Make unicode stuff consistent
            for name in walkfiles]

        # Remove episodes_location from start of path
        curlist = [relpath(x, episodes_location) for x in curlist]

        created_files.extend(curlist)

    # Clean up dummy files and config
    clear_temp_dir(episodes_location)
    if with_config is not None:
        os.unlink(configfname)

    return {
        'output': output,
        'files': created_files,
        'returncode': proc.returncode}
Runs tvnamer on list of file-names in with_files.
    with_files is a list of strings.
    with_flags is a list of command line arguments to pass to tvnamer.
    with_input is the sent to tvnamer's stdin
    with_config is a string containing the tvnamer to run tvnamer with.

    Returns a dict with stdout, stderr and a list of files created
    
tests/functional_runner.py