'Call explicitly dump_traceback(all_threads=True) and check the output.
Raise an error if the output doesn\'t match the expected format.'

@unittest.skipIf((not HAVE_THREADS), 'need    threads')
def check_dump_traceback_threads(self, filename):

    code = '\n                                                import    faulthandler\n                                                from    threading    import    Thread,    Event\n                                                import    time\n\n                                                def    dump():\n                                                                if    {filename}:\n                                                                                with    open({filename},    "wb")    as    fp:\n                                                                                                faulthandler.dump_traceback(fp,    all_threads=True)\n                                                                else:\n                                                                                faulthandler.dump_traceback(all_threads=True)\n\n                                                class    Waiter(Thread):\n                                                                #    avoid    blocking    if    the    main    thread    raises    an    exception.\n                                                                daemon    =    True\n\n                                                                def    __init__(self):\n                                                                                Thread.__init__(self)\n                                                                                self.running    =    Event()\n                                                                                self.stop    =    Event()\n\n                                                                def    run(self):\n                                                                                self.running.set()\n                                                                                self.stop.wait()\n\n                                                waiter    =    Waiter()\n                                                waiter.start()\n                                                waiter.running.wait()\n                                                dump()\n                                                waiter.stop.set()\n                                                waiter.join()\n                                                '
    code = code.format(filename=repr(filename))
    (output, exitcode) = self.get_output(code, filename)
    output = '\n'.join(output)
    if filename:
        lineno = 8
    else:
        lineno = 10
    regex = '\n                                                ^Thread    0x[0-9a-f]+    \\(most    recent    call    first\\):\n                                                (?:        File    ".*threading.py",    line    [0-9]+    in    [_a-z]+\n                                                ){{1,3}}        File    "<string>",    line    23    in    run\n                                                        File    ".*threading.py",    line    [0-9]+    in    _bootstrap_inner\n                                                        File    ".*threading.py",    line    [0-9]+    in    _bootstrap\n\n                                                Current    thread    XXX    \\(most    recent    call    first\\):\n                                                        File    "<string>",    line    {lineno}    in    dump\n                                                        File    "<string>",    line    28    in    <module>$\n                                                '
    regex = dedent(regex.format(lineno=lineno)).strip()
    self.assertRegex(output, regex)
    self.assertEqual(exitcode, 0)
