<commit_before># -*- encoding: utf-8 -*-
from inspect import isgenerator

from .testcase import DatatableViewTestCase
from .test_app import models
from ..exceptions import ColumnError
from ..datatables import Datatable, ValuesDatatable
from ..views import DatatableJSONResponseMixin
from .. import columns
from .. import utils

class DatatableTests(DatatableViewTestCase):
    def test_normalize_config(self):
        dt = Datatable([], '/')
        self.assertEqual(dt.config['hidden_columns'], [])
        self.assertEqual(dt.config['search_fields'], [])
        self.assertEqual(dt.config['unsortable_columns'], [])
        self.assertEqual(dt.config['search'], '')
        self.assertEqual(dt.config['start_offset'], 0)
        self.assertEqual(dt.config['page_length'], 25)
        self.assertEqual(dt.config['ordering'], None)

    def test_column_names_list_raises_unknown_columns(self):
        with self.assertRaises(ColumnError) as cm:
            dt = Datatable([], '/', model=models.ExampleModel, columns=['fake'])
        self.assertEqual(str(cm.exception), "Unknown column name(s): ('fake',)")

    def test_column_names_list_finds_local_fields(self):
        class DT(Datatable):
            class Meta:
                model = models.ExampleModel
                columns = ['name']

        class NoError(BaseException):
            pass

        with self.assertRaises(NoError):
            dt = DT([], '/')
            raise NoError()

    def test_column_names_list_raises_related_columns(self):
        # This was the old way of including related data, but this is no longer supported
        class DT(Datatable):
            class Meta:
                model = models.ExampleModel<commit_msg>Fix test referencing removed kwarg feature<commit_after># -*- encoding: utf-8 -*-
from inspect import isgenerator

from .testcase import DatatableViewTestCase
from .test_app import models
from ..exceptions import ColumnError
from ..datatables import Datatable, ValuesDatatable
from ..views import DatatableJSONResponseMixin
from .. import columns
from .. import utils

class DatatableTests(DatatableViewTestCase):
    def test_normalize_config(self):
        dt = Datatable([], '/')
        self.assertEqual(dt.config['hidden_columns'], [])
        self.assertEqual(dt.config['search_fields'], [])
        self.assertEqual(dt.config['unsortable_columns'], [])
        self.assertEqual(dt.config['search'], '')
        self.assertEqual(dt.config['start_offset'], 0)
        self.assertEqual(dt.config['page_length'], 25)
        self.assertEqual(dt.config['ordering'], None)

    def test_column_names_list_raises_unknown_columns(self):
        class DT(Datatable):
            class Meta:
                model = models.ExampleModel
                columns = ['fake']

        with self.assertRaises(ColumnError) as cm:
            dt = DT([], '/')
        self.assertEqual(str(cm.exception), "Unknown column name(s): ('fake',)")

    def test_column_names_list_finds_local_fields(self):
        class DT(Datatable):
            class Meta:
                model = models.ExampleModel
                columns = ['name']

        class NoError(BaseException):
            pass

        with self.assertRaises(NoError):
            dt = DT([], '/')
            raise NoError()

    def test_column_names_list_raises_related_columns(self):
        # This was the old way of including related data, but this is no longer supported
        class DT(Datatable):
            class Meta:
                model = models.ExampleModel
{'fraction_non_alphanumeric': 0.11142533936651584, 'fraction_numerical': 0.0022624434389140274, 'mean_word_length': 2.8320693391115928, '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': '7305181', 'n_tokens_mistral': 960, 'n_tokens_neox': 931, 'n_words': 224}