# Path: tests/testapp/models.py
# class SizeFieldModel(Model):
#     binary1 = SizedBinaryField(size_class=1)
#     binary2 = SizedBinaryField(size_class=2)
#     binary3 = SizedBinaryField(size_class=3)
#     binary4 = SizedBinaryField(size_class=4)
#     text1 = SizedTextField(size_class=1)
#     text2 = SizedTextField(size_class=2)
#     text3 = SizedTextField(size_class=3)
#     text4 = SizedTextField(size_class=4)
# 
# Path: tests/testapp/utils.py
# def column_type(table_name, column_name):
#     with connection.cursor() as cursor:
#         cursor.execute(
#             """SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
#                WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s AND
#                      COLUMN_NAME = %s""",
#             (table_name, column_name),
#         )
#         return cursor.fetchone()[0]


import pytest
from django.core.management import call_command
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.transaction import atomic
from django.db.utils import DataError
from django.test import TestCase, TransactionTestCase
from django.test.utils import isolate_apps, override_settings
from django_mysql.models import SizedBinaryField, SizedTextField
from django_mysql.test.utils import override_mysql_variables
from tests.testapp.models import SizeFieldModel
from tests.testapp.utils import column_type
        statement, imports = MigrationWriter.serialize(field)

        assert statement == "django_mysql.models.SizedTextField(size_class=4)"


@forceDataError
class SizedTextFieldMigrationTests(TransactionTestCase):
    @override_settings(
        MIGRATION_MODULES={"testapp": "tests.testapp.sizedtextfield_migrations"}
    )
    def test_adding_field_with_default(self):
        table_name = "testapp_sizedtextaltermodel"
        table_names = connection.introspection.table_names

        with connection.cursor() as cursor:
            assert table_name not in table_names(cursor)

        migrate("0001_initial")
        with connection.cursor() as cursor:
            assert table_name in table_names(cursor)
            assert column_type(table_name, "field") == "mediumtext"

        migrate("0002_alter_field")
        with connection.cursor() as cursor:
            assert table_name in table_names(cursor)
            assert column_type(table_name, "field") == "tinytext"

        migrate("0001_initial")
        with connection.cursor() as cursor:
            assert table_name in table_names(cursor)

# Path: tests/testapp/models.py
# class SizeFieldModel(Model):
#     binary1 = SizedBinaryField(size_class=1)
#     binary2 = SizedBinaryField(size_class=2)
#     binary3 = SizedBinaryField(size_class=3)
#     binary4 = SizedBinaryField(size_class=4)
#     text1 = SizedTextField(size_class=1)
#     text2 = SizedTextField(size_class=2)
#     text3 = SizedTextField(size_class=3)
#     text4 = SizedTextField(size_class=4)
# 
# Path: tests/testapp/utils.py
# def column_type(table_name, column_name):
#     with connection.cursor() as cursor:
#         cursor.execute(
#             """SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
#                WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s AND
#                      COLUMN_NAME = %s""",
#             (table_name, column_name),
#         )
#         return cursor.fetchone()[0]


# Path: tests/testapp/test_size_fields.py
import pytest
from django.core.management import call_command
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.transaction import atomic
from django.db.utils import DataError
from django.test import TestCase, TransactionTestCase
from django.test.utils import isolate_apps, override_settings
from django_mysql.models import SizedBinaryField, SizedTextField
from django_mysql.test.utils import override_mysql_variables
from tests.testapp.models import SizeFieldModel
from tests.testapp.utils import column_type

        statement, imports = MigrationWriter.serialize(field)

        assert statement == "django_mysql.models.SizedTextField(size_class=4)"


@forceDataError
class SizedTextFieldMigrationTests(TransactionTestCase):
    @override_settings(
        MIGRATION_MODULES={"testapp": "tests.testapp.sizedtextfield_migrations"}
    )
    def test_adding_field_with_default(self):
        table_name = "testapp_sizedtextaltermodel"
        table_names = connection.introspection.table_names

        with connection.cursor() as cursor:
            assert table_name not in table_names(cursor)

        migrate("0001_initial")
        with connection.cursor() as cursor:
            assert table_name in table_names(cursor)
            assert column_type(table_name, "field") == "mediumtext"

        migrate("0002_alter_field")
        with connection.cursor() as cursor:
            assert table_name in table_names(cursor)
            assert column_type(table_name, "field") == "tinytext"

        migrate("0001_initial")
        with connection.cursor() as cursor:
            assert table_name in table_names(cursor)

            assert column_type(table_name, "field") == "mediumtext"