# 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_add_exists(self):
        CharSetModel.objects.create(field={"nice"})
        CharSetModel.objects.update(field=SetF("field").add("nice"))
        model = CharSetModel.objects.get()
        assert model.field == {"nice"}

    def test_add_expression(self):
        CharSetModel.objects.create(field={"a"})
        CharSetModel.objects.update(field=SetF("field").add(Value("b")))
        model = CharSetModel.objects.get()
        assert model.field == {"a", "b"}

    @override_mysql_variables(SQL_MODE="ANSI")
    def test_add_works_in_ansi_mode(self):
        CharSetModel.objects.create()
        CharSetModel.objects.update(field=SetF("field").add("big"))
        CharSetModel.objects.update(field=SetF("field").add("bad"))
        model = CharSetModel.objects.get()
        assert model.field == {"big", "bad"}

    def test_add_assignment(self):
        model = CharSetModel.objects.create(field={"red"})
        model.field = SetF("field").add("blue")
        model.save()
        model = CharSetModel.objects.get()
        assert model.field == {"red", "blue"}

    def test_remove_one(self):
        CharSetModel.objects.create(field={"dopey", "knifey"})
        CharSetModel.objects.update(field=SetF("field").remove("knifey"))

# 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_add_exists(self):
        CharSetModel.objects.create(field={"nice"})
        CharSetModel.objects.update(field=SetF("field").add("nice"))
        model = CharSetModel.objects.get()
        assert model.field == {"nice"}

    def test_add_expression(self):
        CharSetModel.objects.create(field={"a"})
        CharSetModel.objects.update(field=SetF("field").add(Value("b")))
        model = CharSetModel.objects.get()
        assert model.field == {"a", "b"}

    @override_mysql_variables(SQL_MODE="ANSI")
    def test_add_works_in_ansi_mode(self):
        CharSetModel.objects.create()
        CharSetModel.objects.update(field=SetF("field").add("big"))
        CharSetModel.objects.update(field=SetF("field").add("bad"))
        model = CharSetModel.objects.get()
        assert model.field == {"big", "bad"}

    def test_add_assignment(self):
        model = CharSetModel.objects.create(field={"red"})
        model.field = SetF("field").add("blue")
        model.save()
        model = CharSetModel.objects.get()
        assert model.field == {"red", "blue"}

    def test_remove_one(self):
        CharSetModel.objects.create(field={"dopey", "knifey"})
        CharSetModel.objects.update(field=SetF("field").remove("knifey"))

        model = CharSetModel.objects.get()