<commit_before>from sys import argv, exit


def entered_command(argv):
    if len(argv) >= 2:
        return argv[1]
    return None


def help():
    message = (
        'Usages:',
        '  python rosie.py run chamber_of_deputies [<path to output directory>]',
        '  python rosie.py test',
    )
    print('\n'.join(message))


def run():
    import rosie, rosie.chamber_of_deputies
    if len(argv) >= 3:
        target_module = argv[2]
    else:
        print('A module must be provided.')
        help()
        exit(1)
    target_directory = argv[3] if len(argv) >= 4 else '/tmp/serenata-data/'
    klass = getattr(rosie, target_module)
    klass.main(target_directory)


def test():
    import unittest
    loader = unittest.TestLoader()
    tests = loader.discover('rosie')
    testRunner = unittest.runner.TextTestRunner()
    testRunner.run(tests)


commands = {'run': run, 'test': test}
command = commands.get(entered_command(argv), help)
command()
<commit_msg>fix issue #43<commit_after>from sys import argv, exit


def entered_command(argv):
    if len(argv) >= 2:
        return argv[1]
    return None


def help():
    message = (
        'Usages:',
        '  python rosie.py run chamber_of_deputies [<path to output directory>]',
        '  python rosie.py test',
    )
    print('\n'.join(message))


def run():
    import rosie, rosie.chamber_of_deputies
    if len(argv) >= 3:
        target_module = argv[2]
    else:
        print('A module must be provided.')
        help()
        exit(1)
    target_directory = argv[3] if len(argv) >= 4 else '/tmp/serenata-data/'
    klass = getattr(rosie, target_module)
    klass.main(target_directory)


def test():
    import unittest
    loader = unittest.TestLoader()
    tests = loader.discover('rosie')
    testRunner = unittest.runner.TextTestRunner()
    result = testRunner.run(tests)
    if not result.wasSuccessful():
        exit(1)


commands = {'run': run, 'test': test}
command = commands.get(entered_command(argv), help)
command()

{'fraction_non_alphanumeric': 0.12996031746031747, 'fraction_numerical': 0.008432539682539682, 'mean_word_length': 2.834600760456274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3642348', 'n_tokens_mistral': 683, 'n_tokens_neox': 653, 'n_words': 165}