<commit_before>from django.test import TestCase

from ..externals import External

try:
    from contextlib import GeneratorContextManager
except ImportError:
    from contextlib import _GeneratorContextManager as GeneratorContextManager

from types import FunctionType


class TestExternals(TestCase):

    def test_load(self):
        external = External('foo')

        with self.assertRaises(ImportError):
            external._load('')

    def test_load_class(self):
        external = External('foo')

        self.assertIsInstance(external.load_class(''), object)
        self.assertTrue(external.load_class('', fallback=True))

    def test_load_method(self):
        external = External('foo')
        self.assertIsNone(external.load_method('')())
        self.assertTrue(external.load_method('', fallback=True))

    def test_context_manager(self):
        external = External('foo')
        self.assertIs(type(external.context_manager('')), FunctionType)
        self.assertIsInstance(external.context_manager('')(), GeneratorContextManager)
        self.assertTrue(external.context_manager('', fallback=True))<commit_msg>Improve test coverage of externals.<commit_after>from django.test import TestCase

from ..externals import External

try:
    from contextlib import GeneratorContextManager
except ImportError:
    from contextlib import _GeneratorContextManager as GeneratorContextManager

from types import FunctionType


class TestExternals(TestCase):

    def test_load(self):
        external = External('foo')

        with self.assertRaises(ImportError):
            external._load('')

    def test_load_class(self):
        external = External('foo')

        self.assertIsInstance(external.load_class(''), object)
        self.assertTrue(external.load_class('', fallback=True))

    def test_load_method(self):
        external = External('foo')
        self.assertIsNone(external.load_method('')())
        self.assertTrue(external.load_method('', fallback=True))

    def test_context_manager(self):
        external = External('foo')
        self.assertIs(type(external.context_manager('')), FunctionType)
        self.assertIsInstance(external.context_manager('')(), GeneratorContextManager)
        self.assertTrue(external.context_manager('', fallback=True))

        with external.context_manager('')():
            self.assertTrue(True)
{'fraction_non_alphanumeric': 0.10886075949367088, 'fraction_numerical': 0.0, 'mean_word_length': 3.939583333333333, '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': '4524085', 'n_tokens_mistral': 644, 'n_tokens_neox': 618, 'n_words': 124}