<commit_before>#!/usr/bin/env python
import os
import sys
import unittest

from huey import tests


def _requirements_installed():
    try:
        import django
        return True
    except Exception:
        return False


def run_tests(*test_args):
    suite = unittest.TestLoader().loadTestsFromModule(tests)
    result = unittest.TextTestRunner(verbosity=1).run(suite)
    if os.path.exists('huey.db'):
        os.unlink('huey.db')
    if result.failures:
        sys.exit(1)
    elif result.errors:
        sys.exit(2)


def run_django_tests(*test_args):
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "huey.contrib.djhuey.tests.settings")
    from django.core.management import execute_from_command_line
    args = sys.argv
    args.insert(1, "test")
    args.append('huey.contrib.djhuey.tests')
    execute_from_command_line(args)


if __name__ == '__main__':
    if not _requirements_installed():
        print('Requirements are not installed. Run "pip install -r test_requirements.txt" to install all dependencies.')
        sys.exit(2)
    run_tests(*sys.argv[1:])
    run_django_tests(*sys.argv[1:])
    sys.exit(0)

<commit_msg>Allow running tests without Django.<commit_after>#!/usr/bin/env python
import os
import sys
import unittest

from huey import tests


def _requirements_installed():
    try:
        import django
        return True
    except Exception:
        return False


def run_tests(*test_args):
    suite = unittest.TestLoader().loadTestsFromModule(tests)
    result = unittest.TextTestRunner(verbosity=1).run(suite)
    if os.path.exists('huey.db'):
        os.unlink('huey.db')
    if result.failures:
        sys.exit(1)
    elif result.errors:
        sys.exit(2)


def run_django_tests(*test_args):
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "huey.contrib.djhuey.tests.settings")
    from django.core.management import execute_from_command_line
    args = sys.argv
    args.insert(1, "test")
    args.append('huey.contrib.djhuey.tests')
    execute_from_command_line(args)


if __name__ == '__main__':
    run_tests(*sys.argv[1:])
    if _requirements_installed():
        run_django_tests(*sys.argv[1:])
    else:
        print('Django not installed, skipping Django tests.')
    sys.exit(0)


{'fraction_non_alphanumeric': 0.11427301022676745, 'fraction_numerical': 0.006669630947087594, 'mean_word_length': 3.39453125, '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': '5642373', 'n_tokens_mistral': 769, 'n_tokens_neox': 745, 'n_words': 146}