# Path: tests/testapp/models.py
# class CharSetDefaultModel(Model):
#     field = SetCharField(
#         base_field=CharField(max_length=5),
#         size=5,
#         max_length=32,
#         default=lambda: {"a", "d"},
#     )
# 
# class CharSetModel(Model):
#     field = SetCharField(base_field=CharField(max_length=8), size=3, max_length=32)
#     field2 = SetCharField(base_field=CharField(max_length=8), max_length=255)
# 
# class IntSetModel(Model):
#     field = SetCharField(base_field=IntegerField(), size=5, max_length=32)


import json
import re
import pytest
from django import forms
from django.core import exceptions, serializers
from django.core.management import call_command
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.models import Q, Value
from django.test import SimpleTestCase, TestCase, TransactionTestCase, override_settings
from django.test.utils import isolate_apps
from django_mysql.forms import SimpleSetField
from django_mysql.models import SetCharField, SetF
from django_mysql.test.utils import override_mysql_variables
from tests.testapp.models import CharSetDefaultModel, CharSetModel, IntSetModel

    def test_int_easy(self):
        mymodel = IntSetModel.objects.create(field={1, 2})
        assert mymodel.field == {1, 2}
        mymodel = IntSetModel.objects.get(id=mymodel.id)
        assert mymodel.field == {1, 2}

    def test_int_contains_lookup(self):
        onetwo = IntSetModel.objects.create(field={1, 2})

        ones = IntSetModel.objects.filter(field__contains=1)
        assert ones.count() == 1
        assert ones[0] == onetwo

        twos = IntSetModel.objects.filter(field__contains=2)
        assert twos.count() == 1
        assert twos[0] == onetwo

        threes = IntSetModel.objects.filter(field__contains=3)
        assert threes.count() == 0

        with pytest.raises(ValueError):
            list(IntSetModel.objects.filter(field__contains={1, 2}))

        ones_and_twos = IntSetModel.objects.filter(
            Q(field__contains=1) & Q(field__contains=2)
        )
        assert ones_and_twos.count() == 1
        assert ones_and_twos[0] == onetwo


# Path: tests/testapp/models.py
# class CharSetDefaultModel(Model):
#     field = SetCharField(
#         base_field=CharField(max_length=5),
#         size=5,
#         max_length=32,
#         default=lambda: {"a", "d"},
#     )
# 
# class CharSetModel(Model):
#     field = SetCharField(base_field=CharField(max_length=8), size=3, max_length=32)
#     field2 = SetCharField(base_field=CharField(max_length=8), max_length=255)
# 
# class IntSetModel(Model):
#     field = SetCharField(base_field=IntegerField(), size=5, max_length=32)


# Path: tests/testapp/test_setcharfield.py
import json
import re
import pytest
from django import forms
from django.core import exceptions, serializers
from django.core.management import call_command
from django.db import connection, models
from django.db.migrations.writer import MigrationWriter
from django.db.models import Q, Value
from django.test import SimpleTestCase, TestCase, TransactionTestCase, override_settings
from django.test.utils import isolate_apps
from django_mysql.forms import SimpleSetField
from django_mysql.models import SetCharField, SetF
from django_mysql.test.utils import override_mysql_variables
from tests.testapp.models import CharSetDefaultModel, CharSetModel, IntSetModel


    def test_int_easy(self):
        mymodel = IntSetModel.objects.create(field={1, 2})
        assert mymodel.field == {1, 2}
        mymodel = IntSetModel.objects.get(id=mymodel.id)
        assert mymodel.field == {1, 2}

    def test_int_contains_lookup(self):
        onetwo = IntSetModel.objects.create(field={1, 2})

        ones = IntSetModel.objects.filter(field__contains=1)
        assert ones.count() == 1
        assert ones[0] == onetwo

        twos = IntSetModel.objects.filter(field__contains=2)
        assert twos.count() == 1
        assert twos[0] == onetwo

        threes = IntSetModel.objects.filter(field__contains=3)
        assert threes.count() == 0

        with pytest.raises(ValueError):
            list(IntSetModel.objects.filter(field__contains={1, 2}))

        ones_and_twos = IntSetModel.objects.filter(
            Q(field__contains=1) & Q(field__contains=2)
        )
        assert ones_and_twos.count() == 1
        assert ones_and_twos[0] == onetwo


        ones_and_threes = IntSetModel.objects.filter(