<commit_before>from django import forms

from selectable.forms import fields, widgets
from selectable.tests import ThingLookup
from selectable.tests.base import BaseSelectableTestCase


__all__ = (
    'AutoCompleteSelectFieldTestCase',
    'AutoComboboxSelectFieldTestCase',
    'AutoCompleteSelectMultipleFieldTestCase',
    'AutoComboboxSelectMultipleFieldTestCase',
)


class BaseFieldTestCase(BaseSelectableTestCase):
    field_cls = None
    lookup_cls = None

    def get_field_instance(self, allow_new=False, limit=None, widget=None):
        return self.field_cls(self.lookup_cls, allow_new=allow_new, limit=limit, widget=widget)

    def test_init(self):
        field = self.get_field_instance()
        self.assertEqual(field.lookup_class, self.lookup_cls)

    def test_init_with_limit(self):
        field = self.get_field_instance(limit=10)
        self.assertEqual(field.limit, 10)
        self.assertEqual(field.widget.limit, 10)

    def test_clean(self):
        self.fail('This test has not yet been written')


class AutoCompleteSelectFieldTestCase(BaseFieldTestCase):
    field_cls = fields.AutoCompleteSelectField
    lookup_cls = ThingLookup

    def test_clean(self):
        thing = self.create_thing()
        field = self.get_field_instance()
        value = field.clean([thing.name, thing.id])
        self.assertEqual(thing, value)

    def test_new_not_allowed(self):
        field = self.get_field_instance()
        value = self.get_random_string()
        self.assertRaises(forms.ValidationError, field.clean, [value, ''])

    def test_new_allowed(self):
        field = self.get_field_instance(allow_new=True)
        value = self.get_random_string()
        value = field.clean([value, ''])
        self.assertTrue(isinstance(value, ThingLookup.model))

    def test_default_widget(self):
        field = self.get_field_instance()
        self.assertTrue(isinstance(field.widget, widgets.AutoCompleteSelectWidget))

    def test_alternate_widget(self):
        widget_cls = widgets.AutoComboboxWidget
        field = self.get_field_instance(widget=widget_cls)
        self.assertTrue(isinstance(field.widget, widget_cls))

    def test_alternate_widget_instance(self):
        widget = widgets.AutoComboboxWidget(self.lookup_cls)
        field = self.get_field_instance(widget=widget)
        self.assertTrue(isinstance(field.widget, widgets.AutoComboboxWidget))


class AutoComboboxSelectFieldTestCase(BaseFieldTestCase):
    field_cls = fields.AutoComboboxSelectField
    lookup_cls = ThingLookup

    def test_clean(self):
        thing = self.create_thing()
        field = self.get_field_instance()
        value = field.clean([thing.name, thing.id])
        self.assertEqual(thing, value)

    def test_new_not_allowed(self):
        field = self.get_field_instance()
        value = self.get_random_string()
        self.assertRaises(forms.ValidationError, field.clean, [value, ''])

    def test_new_allowed(self):
        field = self.get_field_instance(allow_new=True)
        value = self.get_random_string()
        value = field.clean([value, ''])
        self.assertTrue(isinstance(value, ThingLookup.model))


class AutoCompleteSelectMultipleFieldTestCase(BaseFieldTestCase):
    field_cls = fields.AutoCompleteSelectMultipleField
    lookup_cls = ThingLookup

    def get_field_instance(self, limit=None, widget=None):
        return self.field_cls(self.lookup_cls, limit=limit, widget=widget)

    def test_clean(self):
        thing = self.create_thing()
        field = self.get_field_instance()
        value = field.clean([thing.id])
        self.assertEqual([thing], value)

    def test_clean_multiple(self):
        thing = self.create_thing()
        other_thing = self.create_thing()
        field = self.get_field_instance()
        ids = [thing.id, other_thing.id]
        value = field.clean(ids)
        self.assertEqual([thing, other_thing], value)

    def test_default_widget(self):
        field = self.get_field_instance()
        self.assertTrue(isinstance(field.widget, widgets.AutoCompleteSelectMultipleWidget))

    def test_alternate_widget(self):
        widget_cls = widgets.AutoComboboxSelectMultipleWidget
        field = self.get_field_instance(widget=widget_cls)
        self.assertTrue(isinstance(field.widget, widget_cls))

    def test_alternate_widget_instance(self):
        widget = widgets.AutoComboboxSelectMultipleWidget(self.lookup_cls)
        field = self.get_field_instance(widget=widget)
        self.assertTrue(isinstance(field.widget, widgets.AutoComboboxSelectMultipleWidget))


class AutoComboboxSelectMultipleFieldTestCase(BaseFieldTestCase):
    field_cls = fields.AutoComboboxSelectMultipleField
    lookup_cls = ThingLookup

    def get_field_instance(self, limit=None):
        return self.__class__.field_cls(self.__class__.lookup_cls, limit=limit)

    def test_clean(self):
        thing = self.create_thing()
        field = self.get_field_instance()
        value = field.clean([thing.id])
        self.assertEqual([thing], value)

    def test_clean_multiple(self):
        thing = self.create_thing()
        other_thing = self.create_thing()
        field = self.get_field_instance()
        ids = [thing.id, other_thing.id]
        value = field.clean(ids)
        self.assertEqual([thing, other_thing], value)
<commit_msg>Remove tests related to removed fields.<commit_after>from django import forms

from selectable.forms import fields, widgets
from selectable.tests import ThingLookup
from selectable.tests.base import BaseSelectableTestCase


__all__ = (
    'AutoCompleteSelectFieldTestCase',
    'AutoCompleteSelectMultipleFieldTestCase',
)


class BaseFieldTestCase(BaseSelectableTestCase):
    field_cls = None
    lookup_cls = None

    def get_field_instance(self, allow_new=False, limit=None, widget=None):
        return self.field_cls(self.lookup_cls, allow_new=allow_new, limit=limit, widget=widget)

    def test_init(self):
        field = self.get_field_instance()
        self.assertEqual(field.lookup_class, self.lookup_cls)

    def test_init_with_limit(self):
        field = self.get_field_instance(limit=10)
        self.assertEqual(field.limit, 10)
        self.assertEqual(field.widget.limit, 10)

    def test_clean(self):
        self.fail('This test has not yet been written')


class AutoCompleteSelectFieldTestCase(BaseFieldTestCase):
    field_cls = fields.AutoCompleteSelectField
    lookup_cls = ThingLookup

    def test_clean(self):
        thing = self.create_thing()
        field = self.get_field_instance()
        value = field.clean([thing.name, thing.id])
        self.assertEqual(thing, value)

    def test_new_not_allowed(self):
        field = self.get_field_instance()
        value = self.get_random_string()
        self.assertRaises(forms.ValidationError, field.clean, [value, ''])

    def test_new_allowed(self):
        field = self.get_field_instance(allow_new=True)
        value = self.get_random_string()
        value = field.clean([value, ''])
        self.assertTrue(isinstance(value, ThingLookup.model))

    def test_default_widget(self):
        field = self.get_field_instance()
        self.assertTrue(isinstance(field.widget, widgets.AutoCompleteSelectWidget))

    def test_alternate_widget(self):
        widget_cls = widgets.AutoComboboxWidget
        field = self.get_field_instance(widget=widget_cls)
        self.assertTrue(isinstance(field.widget, widget_cls))

    def test_alternate_widget_instance(self):
        widget = widgets.AutoComboboxWidget(self.lookup_cls)
        field = self.get_field_instance(widget=widget)
        self.assertTrue(isinstance(field.widget, widgets.AutoComboboxWidget))


class AutoCompleteSelectMultipleFieldTestCase(BaseFieldTestCase):
    field_cls = fields.AutoCompleteSelectMultipleField
    lookup_cls = ThingLookup

    def get_field_instance(self, limit=None, widget=None):
        return self.field_cls(self.lookup_cls, limit=limit, widget=widget)

    def test_clean(self):
        thing = self.create_thing()
        field = self.get_field_instance()
        value = field.clean([thing.id])
        self.assertEqual([thing], value)

    def test_clean_multiple(self):
        thing = self.create_thing()
        other_thing = self.create_thing()
        field = self.get_field_instance()
        ids = [thing.id, other_thing.id]
        value = field.clean(ids)
        self.assertEqual([thing, other_thing], value)

    def test_default_widget(self):
        field = self.get_field_instance()
        self.assertTrue(isinstance(field.widget, widgets.AutoCompleteSelectMultipleWidget))

    def test_alternate_widget(self):
        widget_cls = widgets.AutoComboboxSelectMultipleWidget
        field = self.get_field_instance(widget=widget_cls)
        self.assertTrue(isinstance(field.widget, widget_cls))

    def test_alternate_widget_instance(self):
        widget = widgets.AutoComboboxSelectMultipleWidget(self.lookup_cls)
        field = self.get_field_instance(widget=widget)
        self.assertTrue(isinstance(field.widget, widgets.AutoComboboxSelectMultipleWidget))
{'fraction_non_alphanumeric': 0.09367450032945311, 'fraction_numerical': 0.001317812431363936, 'mean_word_length': 3.7333679833679834, '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': '1330642', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2590, 'n_words': 439}