def mk_test_name(name, value, index=0):
    """
    Generate a new name for a test case.

    It will take the original test name and append an ordinal index and a
    string representation of the value, and convert the result into a valid
    python identifier by replacing extraneous characters with ``_``.

    If hash randomization is enabled (a feature available since 2.7.3/3.2.3
    and enabled by default since 3.3) and a "non-trivial" value is passed
    this will omit the name argument by default. Set `PYTHONHASHSEED`
    to a fixed value before running tests in these cases to get the
    names back consistently or use the `__name__` attribute on data values.

    A "trivial" value is a plain scalar, or a tuple or list consisting
    only of trivial values.

    """

    # We avoid doing str(value) if all of the following hold:
    #
    # * Python version is 2.7.3 or newer (for 2 series) or 3.2.3 or
    #   newer (for 3 series). Also sys.flags.hash_randomization didn't
    #   exist before these.
    # * sys.flags.hash_randomization is set to True
    # * PYTHONHASHSEED is **not** defined in the environment
    # * Given `value` argument is not a trivial scalar (None, str,
    #   int, float).
    #
    # Trivial scalar values are passed as is in all cases.

    trivial_types = (type(None), bool, str, int, float)
    try:
        trivial_types += (unicode,)
    except __HOLE__:
        pass

    def is_trivial(value):
        if isinstance(value, trivial_types):
            return True

        if isinstance(value, (list, tuple)):
            return all(map(is_trivial, value))

        return False

    if is_hash_randomized() and not is_trivial(value):
        return "{0}_{1}".format(name, index + 1)

    try:
        value = str(value)
    except UnicodeEncodeError:
        # fallback for python2
        value = value.encode('ascii', 'backslashreplace')
    test_name = "{0}_{1}_{2}".format(name, index + 1, value)
    return re.sub('\W|^(?=\d)', '_', test_name)
dataset/ETHPy150Open numba/numba/numba/testing/ddt.py/mk_test_name