# Path: tests/compat.py
# def wrap_testdata(func):
#     return func
# 
# Path: tests/testapp/models.py
# class DynamicModel(Model):
#     attrs = DynamicField(
#         spec={
#             "datetimey": dt.datetime,
#             "datey": dt.date,
#             "floaty": float,
#             "inty": int,
#             "stry": str,
#             "timey": dt.time,
#             "nesty": {"level2": str},
#         }
#     )
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())
# 
# class SpeclessDynamicModel(Model):
#     attrs = DynamicField()
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())


import datetime as dt
import json
import mariadb_dyncol
import pytest
from unittest import SkipTest, mock
from django.core import serializers
from django.core.exceptions import FieldError
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.models import CharField, Transform
from django.test import TestCase
from django.test.utils import isolate_apps
from django_mysql.models import DynamicField
from django_mysql.utils import connection_is_mariadb
from tests.compat import wrap_testdata
from tests.testapp.models import DynamicModel, SpeclessDynamicModel
        from django_mysql.models.fields import DynamicField as DField
        from django_mysql.models.fields.dynamic import DynamicField as DField
    def test_bulk_create(self):
        DynamicModel.objects.bulk_create(
            [DynamicModel(attrs={"a": "value"}), DynamicModel(attrs={"b": "value2"})]
        )
        dm1, dm2 = DynamicModel.objects.order_by("id")
        assert dm1.attrs == {"a": "value"}
        assert dm2.attrs == {"b": "value2"}


class SpecTests(DynColTestCase):
    def test_spec_empty(self):
        DynamicField.validate_spec({}, {})  # no errors

    def test_spec_dict_type(self):
        DynamicField.validate_spec({"a": dict}, {"a": {"this": "that"}})  # no errors

    def test_illegal_int(self):
        m = DynamicModel(attrs={"inty": 1.0})
        with pytest.raises(TypeError) as excinfo:
            m.save()
        assert "Key 'inty' should be of type int" in str(excinfo.value)

    def test_illegal_nested(self):
        m = DynamicModel(attrs={"nesty": {"level2": 1}})
        with pytest.raises(TypeError) as excinfo:
            m.save()
        assert "Key 'nesty.level2' should be of type " in str(excinfo.value)

    def test_illegal_nested_type(self):
        m = DynamicModel(attrs={"nesty": []})

# Path: tests/compat.py
# def wrap_testdata(func):
#     return func
# 
# Path: tests/testapp/models.py
# class DynamicModel(Model):
#     attrs = DynamicField(
#         spec={
#             "datetimey": dt.datetime,
#             "datey": dt.date,
#             "floaty": float,
#             "inty": int,
#             "stry": str,
#             "timey": dt.time,
#             "nesty": {"level2": str},
#         }
#     )
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())
# 
# class SpeclessDynamicModel(Model):
#     attrs = DynamicField()
# 
#     @classmethod
#     def check(cls, **kwargs):
#         # Disable the checks on MySQL so that checks tests don't fail
#         if not (connection_is_mariadb(connection)):
#             return []
#         return super().check(**kwargs)
# 
#     def __str__(self):  # pragma: no cover
#         return ",".join(f"{key}:{value}" for key, value in self.attrs.items())


# Path: tests/testapp/test_dynamicfield.py
import datetime as dt
import json
import mariadb_dyncol
import pytest
from unittest import SkipTest, mock
from django.core import serializers
from django.core.exceptions import FieldError
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.models import CharField, Transform
from django.test import TestCase
from django.test.utils import isolate_apps
from django_mysql.models import DynamicField
from django_mysql.utils import connection_is_mariadb
from tests.compat import wrap_testdata
from tests.testapp.models import DynamicModel, SpeclessDynamicModel
        from django_mysql.models.fields import DynamicField as DField
        from django_mysql.models.fields.dynamic import DynamicField as DField

    def test_bulk_create(self):
        DynamicModel.objects.bulk_create(
            [DynamicModel(attrs={"a": "value"}), DynamicModel(attrs={"b": "value2"})]
        )
        dm1, dm2 = DynamicModel.objects.order_by("id")
        assert dm1.attrs == {"a": "value"}
        assert dm2.attrs == {"b": "value2"}


class SpecTests(DynColTestCase):
    def test_spec_empty(self):
        DynamicField.validate_spec({}, {})  # no errors

    def test_spec_dict_type(self):
        DynamicField.validate_spec({"a": dict}, {"a": {"this": "that"}})  # no errors

    def test_illegal_int(self):
        m = DynamicModel(attrs={"inty": 1.0})
        with pytest.raises(TypeError) as excinfo:
            m.save()
        assert "Key 'inty' should be of type int" in str(excinfo.value)

    def test_illegal_nested(self):
        m = DynamicModel(attrs={"nesty": {"level2": 1}})
        with pytest.raises(TypeError) as excinfo:
            m.save()
        assert "Key 'nesty.level2' should be of type " in str(excinfo.value)

    def test_illegal_nested_type(self):
        m = DynamicModel(attrs={"nesty": []})

        with pytest.raises(TypeError) as excinfo: