<commit_before>import re
from unittest import TestCase

from web.blueprints.helpers.table import Column, BootstrapTable, SplittedTable

class ColumnTestCase(TestCase):
    def test_init_requires_args(self):
        with self.assertRaises(TypeError):
            Column()  # pylint: disable=no-value-for-parameter

    def test_instatiation_with_name_and_title_works(self):
        c = Column(title="Test Column", name="test_col")
        self.assertEqual(c.name, "test_col")
        self.assertEqual(c.title, "Test Column")
        self.assertEqual(c.width, 0)
        self.assertEqual(c.cell_style, False)
        self.assertEqual(repr(c), "<Column 'test_col' title='Test Column'>")

    def test_instantiation_without_name(self):
        c = Column("Test Title")
        self.assertIsNone(c.name)
        self.assertEqual(c.title, "Test Title")


class InstantiatedColumnTestCase(TestCase):
    def setUp(self):
        super().setUp()
        self.column = Column(title="Test Column", name="test_col")

    def test_col_args(self):
        arg_string = self.column.build_col_args()
        self.assertIn('data-field="test_col"', arg_string)
        self.assertIn('data-sortable="true"', arg_string)

    def test_col_render(self):
        rendered = str(self.column)
        self.assertEqual(self.column.render(), rendered)
        self.assertTrue(rendered.startswith("<th"))
        self.assertTrue(rendered.endswith("</th>"))
        self.assertIn(self.column.build_col_args(), rendered)
        self.assertIn(self.column.title, rendered)


class CustomizedColumnTestCase(TestCase):
    def test_custom_arguments_set(self):
        rendered = str(Column(title="Test Column", name="test_col", width=3,
                              cell_style="customCellStyle"))
        self.assertIn('data-cell-style="customCellStyle"', rendered)
        self.assertIn('class="col-sm-3"', rendered)


class BootstrapTableTestCase(TestCase):
    def test_init_requires_args(self):
        with self.assertRaises(TypeError):
            BootstrapTable()  # pylint: disable=no-value-for-parameter


    def test_minimal_instantiation(self):
        t = BootstrapTable(columns=["dummy"], data_url="http://foobar")
        self.assertEqual(t.columns, ["dummy"])
        self.assertEqual(t.data_url, "http://foobar")
        self.assertEqual(repr(t), "<BootstrapTable cols=1 data_url='http://foobar'>")


class InstantiatedBootstrapTableTestCase(TestCase):
    def setUp(self):
        super().setUp()
        self.table = BootstrapTable(
            columns=[Column(title="Column 1", name="col1"),
                     Column(title="Column 2", name="col2")],
            data_url="http://dummy",
            table_args={'foo': "bar", 'data-cache': "true"}
        )

    def test_table_header_generation(self):
        elements = list(self.table.generate_table_header())
        header = ''.join(elements)
        self.assertTrue(header.startswith("<thead><tr>"))
        self.assertTrue(header.endswith("</tr></thead>"))
        for col in self.table.columns:
            self.assertTrue(str(col))
            self.assertIn(str(col), elements)

    def test_table_args_passed(self):
        self.assertEqual(self.table.table_args.get('data-cache'), "true")
        self.assertEqual(self.table.table_args.get('foo'), "bar")

    def test_render_uses_the_generators_correctly(self):
        class MockedTable(BootstrapTable):
            def __init__(self):
                super().__init__(columns=[], data_url="http://dummy")
            generate_table_header = lambda self: ["HEADER"]
            generate_table_footer = lambda self: ["FOOTER"]
            generate_toolbar = lambda self: ["TOOLBAR"]

        markup = MockedTable().render(table_id="TABLE_ID")
        TOOLBAR_RE = r'<div .*role="toolbar".*>\s*TOOLBAR\s*</div>'
        HEADER_RE = r'<table .*id="TABLE_ID".*>\s*HEADER\s*FOOTER\s*</table>'

        self.assertEqual(len(re.findall(TOOLBAR_RE, markup)), 1)
        self.assertEqual(len(re.findall(HEADER_RE, markup)), 1)


class DeclarativeTableTestCase(TestCase):
    class Table(BootstrapTable):
        a = Column(title="Column 1", name=None)
        b = Column(title="Column 2", name='bar')

        def toolbar(self):<commit_msg>Add missing test for column appearance<commit_after>import re
from unittest import TestCase

from web.blueprints.helpers.table import Column, BootstrapTable, SplittedTable

class ColumnTestCase(TestCase):
    def test_init_requires_args(self):
        with self.assertRaises(TypeError):
            Column()  # pylint: disable=no-value-for-parameter

    def test_instatiation_with_name_and_title_works(self):
        c = Column(title="Test Column", name="test_col")
        self.assertEqual(c.name, "test_col")
        self.assertEqual(c.title, "Test Column")
        self.assertEqual(c.width, 0)
        self.assertEqual(c.cell_style, False)
        self.assertEqual(repr(c), "<Column 'test_col' title='Test Column'>")

    def test_instantiation_without_name(self):
        c = Column("Test Title")
        self.assertIsNone(c.name)
        self.assertEqual(c.title, "Test Title")


class InstantiatedColumnTestCase(TestCase):
    def setUp(self):
        super().setUp()
        self.column = Column(title="Test Column", name="test_col")

    def test_col_args(self):
        arg_string = self.column.build_col_args()
        self.assertIn('data-field="test_col"', arg_string)
        self.assertIn('data-sortable="true"', arg_string)

    def test_col_render(self):
        rendered = str(self.column)
        self.assertEqual(self.column.render(), rendered)
        self.assertTrue(rendered.startswith("<th"))
        self.assertTrue(rendered.endswith("</th>"))
        self.assertIn(self.column.build_col_args(), rendered)
        self.assertIn(self.column.title, rendered)


class CustomizedColumnTestCase(TestCase):
    def test_custom_arguments_set(self):
        rendered = str(Column(title="Test Column", name="test_col", width=3,
                              cell_style="customCellStyle"))
        self.assertIn('data-cell-style="customCellStyle"', rendered)
        self.assertIn('class="col-sm-3"', rendered)


class BootstrapTableTestCase(TestCase):
    def test_init_requires_args(self):
        with self.assertRaises(TypeError):
            BootstrapTable()  # pylint: disable=no-value-for-parameter


    def test_minimal_instantiation(self):
        t = BootstrapTable(columns=["dummy"], data_url="http://foobar")
        self.assertEqual(t.columns, ["dummy"])
        self.assertEqual(t.data_url, "http://foobar")
        self.assertEqual(repr(t), "<BootstrapTable cols=1 data_url='http://foobar'>")


class InstantiatedBootstrapTableTestCase(TestCase):
    def setUp(self):
        super().setUp()
        self.table = BootstrapTable(
            columns=[Column(title="Column 1", name="col1"),
                     Column(title="Column 2", name="col2")],
            data_url="http://dummy",
            table_args={'foo': "bar", 'data-cache': "true"}
        )

    def test_table_header_generation(self):
        elements = list(self.table.generate_table_header())
        header = ''.join(elements)
        self.assertTrue(header.startswith("<thead><tr>"))
        self.assertTrue(header.endswith("</tr></thead>"))
        for col in self.table.columns:
            self.assertTrue(str(col))
            self.assertIn(str(col), elements)

    def test_table_args_passed(self):
        self.assertEqual(self.table.table_args.get('data-cache'), "true")
        self.assertEqual(self.table.table_args.get('foo'), "bar")

    def test_render_uses_the_generators_correctly(self):
        class MockedTable(BootstrapTable):
            def __init__(self):
                super().__init__(columns=[], data_url="http://dummy")
            generate_table_header = lambda self: ["HEADER"]
            generate_table_footer = lambda self: ["FOOTER"]
            generate_toolbar = lambda self: ["TOOLBAR"]

        markup = MockedTable().render(table_id="TABLE_ID")
        TOOLBAR_RE = r'<div .*role="toolbar".*>\s*TOOLBAR\s*</div>'
        HEADER_RE = r'<table .*id="TABLE_ID".*>\s*HEADER\s*FOOTER\s*</table>'

        self.assertEqual(len(re.findall(TOOLBAR_RE, markup)), 1)
        self.assertEqual(len(re.findall(HEADER_RE, markup)), 1)

    def test_columns_appear_in_header(self):
        rendered = self.table.render("test_id")
        self.assertIn("Column 1", rendered)
        self.assertIn("Column 2", rendered)


class DeclarativeTableTestCase(TestCase):
    class Table(BootstrapTable):
        a = Column(title="Column 1", name=None)
        b = Column(title="Column 2", name='bar')

        def toolbar(self):
{'fraction_non_alphanumeric': 0.14033874870376772, 'fraction_numerical': 0.0029957368360410187, 'mean_word_length': 3.2465753424657535, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, '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': '2630729', 'n_tokens_mistral': 2687, 'n_tokens_neox': 2571, 'n_words': 418}