<commit_before>#ckwg +4
# Copyright 2012 by Kitware, Inc. All Rights Reserved. Please refer to
# KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
# Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.


def test_error(msg):
    import sys

    sys.stderr.write("Error: %s\n" % msg)


def expect_exception(action, kind, func, *args):
    got_exception = False

    try:
        func(*args)
    except kind:
        got_exception = True
    except BaseException as e:
        test_error("Got unexpected exception: %s" % str(e))

        got_exception = True
    except:
        test_error("Got non-standard exception")

        got_exception = True

    if not got_exception:
        test_error("Did not get exception when %s" % action)<commit_msg>Add test runner function for Python tests<commit_after>#ckwg +4
# Copyright 2012-2013 by Kitware, Inc. All Rights Reserved. Please refer to
# KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
# Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.


def test_error(msg):
    import sys

    sys.stderr.write("Error: %s\n" % msg)


def expect_exception(action, kind, func, *args):
    got_exception = False

    try:
        func(*args)
    except kind:
        got_exception = True
    except BaseException as e:
        test_error("Got unexpected exception: %s" % str(e))

        got_exception = True
    except:
        test_error("Got non-standard exception")

        got_exception = True

    if not got_exception:
        test_error("Did not get exception when %s" % action)


def run_test(testname, tests, *args, **kwargs):
    if testname not in tests:
        import sys

        test_error("No such test '%s'" % testname)

        sys.exit(1)

    try:
        tests[testname](*args, **kwargs)
    except BaseException as e:
        test_error("Unexpected exception: %s" % str(e))
{'fraction_non_alphanumeric': 0.09741969457609267, 'fraction_numerical': 0.015271195365982097, 'mean_word_length': 2.95010395010395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5980051', 'n_tokens_mistral': 611, 'n_tokens_neox': 556, 'n_words': 188}