<commit_before># -*- coding: utf-8 -*-
import unittest

from django import forms
from django_genericfilters import forms as gf


class FormTestCase(unittest.TestCase):

    def test_query_form_mixin(self):
        class Form(gf.QueryFormMixin):
            pass

        form = Form()
        
        self.assertTrue('query' in form.fields)

    def test_order_form_mixin(self):
        def get_order_by_choices():
            return (('last_name', 'Last Name'),
                    ('first_name', 'First Name'))
        
        class Form(gf.OrderFormMixin):
            def get_order_by_choices(self):
                return get_order_by_choices()
        
        form = Form()
        
        self.assertTrue('order_by' in form.fields)
        self.assertTrue('order_reverse' in form.fields)
        
        self.assertEqual(form.fields['order_by'].choices,
                         list(get_order_by_choices()))

    def test_pagination_form_mixin(self):
        class Form(gf.PaginationFormMixin):
            pass
        
        form = Form()
        
        self.assertTrue('page' in form.fields)
        self.assertTrue('paginate_by' in form.fields)

    def test_get_order_by_choices_not_implemented(self):
        class Form(gf.OrderFormMixin):
            pass

        with self.assertRaises(NotImplementedError):
            Form()


class FilteredFormTestCase(unittest.TestCase):
    # Define a form class for this test case
    class Form(gf.OrderFormMixin, gf.PaginationFormMixin,
               gf.QueryFormMixin, gf.FilteredForm):
        def get_order_by_choices(self):
            return (('last_name', 'Last Name'),
                    ('first_name', 'First Name'))
        

    def test_empty_form_bound(self):
        form = self.Form(data={}, initial={"order_by": 'last_name'})
        self.assertTrue(form.is_bound)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data['order_by'], 'last_name')

    def test_form_order_by_bound(self):<commit_msg>Fix AssertRaises to work with 2.6<commit_after># -*- coding: utf-8 -*-
import unittest

from django import forms
from django_genericfilters import forms as gf


class FormTestCase(unittest.TestCase):

    def test_query_form_mixin(self):
        class Form(gf.QueryFormMixin):
            pass

        form = Form()
        
        self.assertTrue('query' in form.fields)

    def test_order_form_mixin(self):
        def get_order_by_choices():
            return (('last_name', 'Last Name'),
                    ('first_name', 'First Name'))
        
        class Form(gf.OrderFormMixin):
            def get_order_by_choices(self):
                return get_order_by_choices()
        
        form = Form()
        
        self.assertTrue('order_by' in form.fields)
        self.assertTrue('order_reverse' in form.fields)
        
        self.assertEqual(form.fields['order_by'].choices,
                         list(get_order_by_choices()))

    def test_pagination_form_mixin(self):
        class Form(gf.PaginationFormMixin):
            pass
        
        form = Form()
        
        self.assertTrue('page' in form.fields)
        self.assertTrue('paginate_by' in form.fields)

    def test_get_order_by_choices_not_implemented(self):
        class Form(gf.OrderFormMixin):
            pass

        self.assertRaises(NotImplementedError, Form)


class FilteredFormTestCase(unittest.TestCase):
    # Define a form class for this test case
    class Form(gf.OrderFormMixin, gf.PaginationFormMixin,
               gf.QueryFormMixin, gf.FilteredForm):
        def get_order_by_choices(self):
            return (('last_name', 'Last Name'),
                    ('first_name', 'First Name'))
        

    def test_empty_form_bound(self):
        form = self.Form(data={}, initial={"order_by": 'last_name'})
        self.assertTrue(form.is_bound)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data['order_by'], 'last_name')

    def test_form_order_by_bound(self):
{'fraction_non_alphanumeric': 0.10211180124223602, 'fraction_numerical': 0.0009937888198757764, 'mean_word_length': 2.316309719934102, 'pattern_counts': {'":': 2, '<': 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': '5984067', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1190, 'n_words': 225}