#!/usr/bin/env python
#     Copyright 2012, Kay Hayen, mailto:kayhayen@gmx.de
#
#     Part of "Nuitka", an optimizing Python compiler that is compatible and
#     integrates with CPython, but also works on its own.
#
#     If you submit patches or make the software available to licensors of
#     this software in either form, you automatically them grant them a
#     license for your part of the code under "Apache License 2.0" unless you
#     choose to remove this notice.
#
#     Kay Hayen uses the right to license his code under only GPL version 3,
#     to discourage a fork of Nuitka before it is "finished". He will later
#     make a new "Nuitka" release fully under "Apache License 2.0".
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, version 3 of the License.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Please leave the whole of this copyright notice intact.
#

from __future__ import print_function

import sys, re

ran_re = re.compile( r"^(Ran \d+ tests? in )\d+\.\d+s$" )
instance_re = re.compile( r"at 0x[0-9a-fA-F]+" )
compiled_function_re = re.compile( r"\<compiled function" )
compiled_genexpr_re = re.compile( r"\<compiled generator object \<(.*?)\>" )
compiled_generator_re = re.compile( r"\<compiled generator object (.*?) at" )
unbound_method_re = re.compile( r"bound compiled_method " )
compiled_type_re = re.compile( r"type 'compiled_" )
global_name_error_re = re.compile( r"global (name ')(.*?)(' is not defined)" )
module_repr_re = re.compile( r"(\<module '.*?' from ').*?('\>)" )

for line in sys.stdin:
    line = instance_re.sub( r"at 0xxxxxxxxx", line )
    line = compiled_function_re.sub( r"<function", line )
    line = compiled_genexpr_re.sub( r"<generator object <\1>", line )
    line = compiled_generator_re.sub( r"<generator object \1 at", line )
    line = unbound_method_re.sub( r"bound method ", line )
    line = compiled_type_re.sub( r"type '", line )
    line = global_name_error_re.sub( r"\1\2\3", line )
    line = module_repr_re.sub( r"\1xxxxx\2", line )

    # Windows has a different os.path, update according to it.
    line = line.replace( "ntpath", "posixpath" )

    line = line.replace(
        "must be a mapping, not compiled_function",
        "must be a mapping, not function"
    )
    line = line.replace(
        "must be a sequence, not compiled_function",
        "must be a sequence, not function"
    )

    if ran_re.match( line ):
        print(ran_re.match( line ).group(1) + " x.xxxs")
    else:
        print(line, end=' ')
