<s> import json <EOL> import re <EOL> from unittest import skipIf <EOL> import django <EOL> import pytest <EOL> from django import forms <EOL> from django . core import exceptions , serializers <EOL> from django . core . management import call_command <EOL> from django . db import connection , models <EOL> from django . db . migrations . writer import MigrationWriter <EOL> from django . db . models import Q <EOL> from django . test import ( <EOL> SimpleTestCase , TestCase , TransactionTestCase , override_settings <EOL> ) <EOL> from django_mysql . forms import SimpleSetField <EOL> from django_mysql . models import SetCharField , SetF <EOL> from django_mysql . test . utils import override_mysql_variables <EOL> from testapp . models import ( <EOL> CharSetDefaultModel , CharSetModel , IntSetModel , TemporaryModel <EOL> ) <EOL> class TestSaveLoad ( TestCase ) : <EOL> def test_char_easy ( self ) : <EOL> s = CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> assert s . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> s = CharSetModel . objects . get ( id = s . id ) <EOL> assert s . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> s . field . add ( "<STR_LIT>" ) <EOL> s . save ( ) <EOL> assert s . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> s = CharSetModel . objects . get ( id = s . id ) <EOL> assert s . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> def test_char_string_direct ( self ) : <EOL> s = CharSetModel . objects . create ( field = "<STR_LIT>" ) <EOL> s = CharSetModel . objects . get ( id = s . id ) <EOL> assert s . field == { '<STR_LIT>' , '<STR_LIT>' } <EOL> def test_is_a_set_immediately ( self ) : <EOL> s = CharSetModel ( ) <EOL> assert s . field == set ( ) <EOL> s . field . add ( "<STR_LIT>" ) <EOL> s . field . add ( "<STR_LIT>" ) <EOL> s . save ( ) <EOL> assert s . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> s = CharSetModel . objects . get ( id = s . id ) <EOL> assert s . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> def test_empty ( self ) : <EOL> s = CharSetModel . objects . create ( ) <EOL> assert s . field == set ( ) <EOL> s = CharSetModel . objects . get ( id = s . id ) <EOL> assert s . field == set ( ) <EOL> def test_char_cant_create_sets_with_empty_string ( self ) : <EOL> with pytest . raises ( ValueError ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> def test_char_cant_create_sets_with_commas ( self ) : <EOL> with pytest . raises ( ValueError ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> def test_char_basic_lookup ( self ) : <EOL> mymodel = CharSetModel . objects . create ( ) <EOL> empty = CharSetModel . objects . filter ( field = "<STR_LIT>" ) <EOL> assert empty . count ( ) == <NUM_LIT:1> <EOL> assert empty [ <NUM_LIT:0> ] == mymodel <EOL> mymodel . delete ( ) <EOL> assert empty . count ( ) == <NUM_LIT:0> <EOL> def test_char_lookup_contains ( self ) : <EOL> self . check_char_lookup ( '<STR_LIT>' ) <EOL> def test_char_lookup_icontains ( self ) : <EOL> self . check_char_lookup ( '<STR_LIT>' ) <EOL> def check_char_lookup ( self , lookup ) : <EOL> lname = '<STR_LIT>' + lookup <EOL> mymodel = CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> mouldy = CharSetModel . objects . filter ( ** { lname : "<STR_LIT>" } ) <EOL> assert mouldy . count ( ) == <NUM_LIT:1> <EOL> assert mouldy [ <NUM_LIT:0> ] == mymodel <EOL> rotten = CharSetModel . objects . filter ( ** { lname : "<STR_LIT>" } ) <EOL> assert rotten . count ( ) == <NUM_LIT:1> <EOL> assert rotten [ <NUM_LIT:0> ] == mymodel <EOL> clean = CharSetModel . objects . filter ( ** { lname : "<STR_LIT>" } ) <EOL> assert clean . count ( ) == <NUM_LIT:0> <EOL> with pytest . raises ( ValueError ) : <EOL> list ( CharSetModel . objects . filter ( ** { lname : { "<STR_LIT:a>" , "<STR_LIT:b>" } } ) ) <EOL> both = CharSetModel . objects . filter ( <EOL> Q ( ** { lname : "<STR_LIT>" } ) & Q ( ** { lname : "<STR_LIT>" } ) <EOL> ) <EOL> assert both . count ( ) == <NUM_LIT:1> <EOL> assert both [ <NUM_LIT:0> ] == mymodel <EOL> either = CharSetModel . objects . filter ( <EOL> Q ( ** { lname : "<STR_LIT>" } ) | Q ( ** { lname : "<STR_LIT>" } ) <EOL> ) <EOL> assert either . count ( ) == <NUM_LIT:1> <EOL> not_clean = CharSetModel . objects . exclude ( ** { lname : "<STR_LIT>" } ) <EOL> assert not_clean . count ( ) == <NUM_LIT:1> <EOL> not_mouldy = CharSetModel . objects . exclude ( ** { lname : "<STR_LIT>" } ) <EOL> assert not_mouldy . count ( ) == <NUM_LIT:0> <EOL> def test_char_len_lookup_empty ( self ) : <EOL> mymodel = CharSetModel . objects . create ( field = set ( ) ) <EOL> empty = CharSetModel . objects . filter ( field__len = <NUM_LIT:0> ) <EOL> assert empty . count ( ) == <NUM_LIT:1> <EOL> assert empty [ <NUM_LIT:0> ] == mymodel <EOL> one = CharSetModel . objects . filter ( field__len = <NUM_LIT:1> ) <EOL> assert one . count ( ) == <NUM_LIT:0> <EOL> one_or_more = CharSetModel . objects . filter ( field__len__gte = <NUM_LIT:0> ) <EOL> assert one_or_more . count ( ) == <NUM_LIT:1> <EOL> def test_char_len_lookup ( self ) : <EOL> mymodel = CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> empty = CharSetModel . objects . filter ( field__len = <NUM_LIT:0> ) <EOL> assert empty . count ( ) == <NUM_LIT:0> <EOL> one_or_more = CharSetModel . objects . filter ( field__len__gte = <NUM_LIT:1> ) <EOL> assert one_or_more . count ( ) == <NUM_LIT:1> <EOL> assert one_or_more [ <NUM_LIT:0> ] == mymodel <EOL> two = CharSetModel . objects . filter ( field__len = <NUM_LIT:2> ) <EOL> assert two . count ( ) == <NUM_LIT:1> <EOL> assert two [ <NUM_LIT:0> ] == mymodel <EOL> three = CharSetModel . objects . filter ( field__len = <NUM_LIT:3> ) <EOL> assert three . count ( ) == <NUM_LIT:0> <EOL> def test_char_default ( self ) : <EOL> mymodel = CharSetDefaultModel . objects . create ( ) <EOL> assert mymodel . field == { "<STR_LIT:a>" , "<STR_LIT:d>" } <EOL> mymodel = CharSetDefaultModel . objects . get ( id = mymodel . id ) <EOL> assert mymodel . field == { "<STR_LIT:a>" , "<STR_LIT:d>" } <EOL> def test_int_easy ( self ) : <EOL> mymodel = IntSetModel . objects . create ( field = { <NUM_LIT:1> , <NUM_LIT:2> } ) <EOL> assert mymodel . field == { <NUM_LIT:1> , <NUM_LIT:2> } <EOL> mymodel = IntSetModel . objects . get ( id = mymodel . id ) <EOL> assert mymodel . field == { <NUM_LIT:1> , <NUM_LIT:2> } <EOL> def test_int_contains_lookup ( self ) : <EOL> onetwo = IntSetModel . objects . create ( field = { <NUM_LIT:1> , <NUM_LIT:2> } ) <EOL> ones = IntSetModel . objects . filter ( field__contains = <NUM_LIT:1> ) <EOL> assert ones . count ( ) == <NUM_LIT:1> <EOL> assert ones [ <NUM_LIT:0> ] == onetwo <EOL> twos = IntSetModel . objects . filter ( field__contains = <NUM_LIT:2> ) <EOL> assert twos . count ( ) == <NUM_LIT:1> <EOL> assert twos [ <NUM_LIT:0> ] == onetwo <EOL> threes = IntSetModel . objects . filter ( field__contains = <NUM_LIT:3> ) <EOL> assert threes . count ( ) == <NUM_LIT:0> <EOL> with pytest . raises ( ValueError ) : <EOL> list ( IntSetModel . objects . filter ( field__contains = { <NUM_LIT:1> , <NUM_LIT:2> } ) ) <EOL> ones_and_twos = IntSetModel . objects . filter ( <EOL> Q ( field__contains = <NUM_LIT:1> ) & Q ( field__contains = <NUM_LIT:2> ) <EOL> ) <EOL> assert ones_and_twos . count ( ) == <NUM_LIT:1> <EOL> assert ones_and_twos [ <NUM_LIT:0> ] == onetwo <EOL> ones_and_threes = IntSetModel . objects . filter ( <EOL> Q ( field__contains = <NUM_LIT:1> ) & Q ( field__contains = <NUM_LIT:3> ) <EOL> ) <EOL> assert ones_and_threes . count ( ) == <NUM_LIT:0> <EOL> ones_or_threes = IntSetModel . objects . filter ( <EOL> Q ( field__contains = <NUM_LIT:1> ) | Q ( field__contains = <NUM_LIT:3> ) <EOL> ) <EOL> assert ones_or_threes . count ( ) == <NUM_LIT:1> <EOL> no_three = IntSetModel . objects . exclude ( field__contains = <NUM_LIT:3> ) <EOL> assert no_three . count ( ) == <NUM_LIT:1> <EOL> no_one = IntSetModel . objects . exclude ( field__contains = <NUM_LIT:1> ) <EOL> assert no_one . count ( ) == <NUM_LIT:0> <EOL> @ skipIf ( django . VERSION [ : <NUM_LIT:2> ] < ( <NUM_LIT:1> , <NUM_LIT:8> ) , <EOL> "<STR_LIT>" ) <EOL> class TestSetF ( TestCase ) : <EOL> def test_add_to_none ( self ) : <EOL> CharSetModel . objects . create ( field = set ( ) ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" } <EOL> def test_add_to_one ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> def test_add_to_some ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> def test_add_to_multiple_objects ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( "<STR_LIT>" ) ) <EOL> first , second = tuple ( CharSetModel . objects . all ( ) ) <EOL> assert first . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> assert second . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> def test_add_exists ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( "<STR_LIT>" ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" } <EOL> @ override_mysql_variables ( SQL_MODE = "<STR_LIT>" ) <EOL> def test_add_works_in_ansi_mode ( self ) : <EOL> CharSetModel . objects . create ( ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( '<STR_LIT>' ) ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" , "<STR_LIT>" } <EOL> def test_add_assignment ( self ) : <EOL> model = CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> model . field = SetF ( '<STR_LIT>' ) . add ( '<STR_LIT>' ) <EOL> model . save ( ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { '<STR_LIT>' , '<STR_LIT>' } <EOL> def test_remove_one ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" } <EOL> def test_remove_only_one ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == set ( ) <EOL> def test_remove_from_none ( self ) : <EOL> CharSetModel . objects . create ( field = set ( ) ) <EOL> CharSetModel . objects . update ( field = SetF ( "<STR_LIT>" ) . remove ( "<STR_LIT>" ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == set ( ) <EOL> def test_remove_first ( self ) : <EOL> CharSetModel . objects . create ( ) <EOL> CharSetModel . objects . update ( field = "<STR_LIT>" ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT:a>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT:b>" , "<STR_LIT:c>" } <EOL> def test_remove_middle ( self ) : <EOL> CharSetModel . objects . create ( ) <EOL> CharSetModel . objects . update ( field = "<STR_LIT>" ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT:b>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT:a>" , "<STR_LIT:c>" } <EOL> def test_remove_last ( self ) : <EOL> CharSetModel . objects . create ( ) <EOL> CharSetModel . objects . update ( field = "<STR_LIT>" ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT:c>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT:a>" , "<STR_LIT:b>" } <EOL> def test_remove_not_exists ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( "<STR_LIT>" ) . remove ( "<STR_LIT>" ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" } <EOL> def test_remove_from_multiple_objects ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( "<STR_LIT>" ) ) <EOL> first , second = tuple ( CharSetModel . objects . all ( ) ) <EOL> assert first . field == { "<STR_LIT>" } <EOL> assert second . field == { "<STR_LIT>" } <EOL> @ override_mysql_variables ( SQL_MODE = "<STR_LIT>" ) <EOL> def test_remove_works_in_ansi_mode ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT>' ) ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT>' ) ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( '<STR_LIT>' ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == set ( ) <EOL> def test_remove_assignment ( self ) : <EOL> model = IntSetModel . objects . create ( field = { <NUM_LIT> , <NUM_LIT> } ) <EOL> model . field = SetF ( '<STR_LIT>' ) . remove ( <NUM_LIT> ) <EOL> model . save ( ) <EOL> model = IntSetModel . objects . get ( ) <EOL> assert model . field == { <NUM_LIT> } <EOL> def test_works_with_two_fields ( self ) : <EOL> CharSetModel . objects . create ( field = { "<STR_LIT>" , "<STR_LIT>" } , <EOL> field2 = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( "<STR_LIT>" ) , <EOL> field2 = SetF ( '<STR_LIT>' ) . add ( "<STR_LIT>" ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> assert model . field2 == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . add ( "<STR_LIT>" ) , <EOL> field2 = SetF ( '<STR_LIT>' ) . remove ( "<STR_LIT>" ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> assert model . field2 == { "<STR_LIT>" , "<STR_LIT>" } <EOL> CharSetModel . objects . update ( field = SetF ( '<STR_LIT>' ) . remove ( "<STR_LIT>" ) , <EOL> field2 = SetF ( '<STR_LIT>' ) . remove ( "<STR_LIT>" ) ) <EOL> model = CharSetModel . objects . get ( ) <EOL> assert model . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> assert model . field2 == { "<STR_LIT>" } <EOL> @ skipIf ( django . VERSION [ : <NUM_LIT:2> ] >= ( <NUM_LIT:1> , <NUM_LIT:8> ) , <EOL> "<STR_LIT>" ) <EOL> class TestSetFFails ( TestCase ) : <EOL> def test_cannot_instantiate ( self ) : <EOL> with pytest . raises ( ValueError ) : <EOL> SetF ( '<STR_LIT>' ) . add ( "<STR_LIT>" ) <EOL> class TestValidation ( SimpleTestCase ) : <EOL> def test_max_length ( self ) : <EOL> field = SetCharField ( <EOL> models . CharField ( max_length = <NUM_LIT:32> ) , <EOL> size = <NUM_LIT:3> , <EOL> max_length = <NUM_LIT:32> <EOL> ) <EOL> field . clean ( { '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' } , None ) <EOL> with pytest . raises ( exceptions . ValidationError ) as excinfo : <EOL> field . clean ( { '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' } , None ) <EOL> assert ( <EOL> excinfo . value . messages [ <NUM_LIT:0> ] == <EOL> '<STR_LIT>' <EOL> ) <EOL> class TestCheck ( SimpleTestCase ) : <EOL> def test_model_set ( self ) : <EOL> field = IntSetModel . _meta . get_field ( '<STR_LIT>' ) <EOL> assert field . model == IntSetModel <EOL> assert field . base_field . model . __name__ == '<STR_LIT>' <EOL> def test_base_field_checks ( self ) : <EOL> class InvalidSetCharFieldModel ( TemporaryModel ) : <EOL> field = SetCharField ( models . CharField ( ) , max_length = <NUM_LIT:32> ) <EOL> errors = InvalidSetCharFieldModel . check ( actually_check = True ) <EOL> assert len ( errors ) == <NUM_LIT:1> <EOL> assert errors [ <NUM_LIT:0> ] . id == '<STR_LIT>' <EOL> assert '<STR_LIT>' in errors [ <NUM_LIT:0> ] . msg <EOL> assert '<STR_LIT:max_length>' in errors [ <NUM_LIT:0> ] . msg <EOL> def test_invalid_base_fields ( self ) : <EOL> class InvalidSetCharFieldModel ( TemporaryModel ) : <EOL> field = SetCharField ( <EOL> models . ForeignKey ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:32> <EOL> ) <EOL> errors = InvalidSetCharFieldModel . check ( actually_check = True ) <EOL> assert len ( errors ) == <NUM_LIT:1> <EOL> assert errors [ <NUM_LIT:0> ] . id == '<STR_LIT>' <EOL> assert '<STR_LIT>' in errors [ <NUM_LIT:0> ] . msg <EOL> def test_max_length_including_base ( self ) : <EOL> class InvalidSetCharFieldModel ( TemporaryModel ) : <EOL> field = SetCharField ( <EOL> models . CharField ( max_length = <NUM_LIT:32> ) , <EOL> size = <NUM_LIT:2> , max_length = <NUM_LIT:32> ) <EOL> errors = InvalidSetCharFieldModel . check ( actually_check = True ) <EOL> assert len ( errors ) == <NUM_LIT:1> <EOL> assert errors [ <NUM_LIT:0> ] . id == '<STR_LIT>' <EOL> assert '<STR_LIT>' in errors [ <NUM_LIT:0> ] . msg <EOL> class TestDeconstruct ( TestCase ) : <EOL> def test_deconstruct ( self ) : <EOL> field = SetCharField ( models . IntegerField ( ) , max_length = <NUM_LIT:32> ) <EOL> name , path , args , kwargs = field . deconstruct ( ) <EOL> new = SetCharField ( * args , ** kwargs ) <EOL> assert new . base_field . __class__ == field . base_field . __class__ <EOL> def test_deconstruct_with_size ( self ) : <EOL> field = SetCharField ( models . IntegerField ( ) , size = <NUM_LIT:3> , max_length = <NUM_LIT:32> ) <EOL> name , path , args , kwargs = field . deconstruct ( ) <EOL> new = SetCharField ( * args , ** kwargs ) <EOL> assert new . size == field . size <EOL> def test_deconstruct_args ( self ) : <EOL> field = SetCharField ( models . CharField ( max_length = <NUM_LIT:5> ) , max_length = <NUM_LIT:32> ) <EOL> name , path , args , kwargs = field . deconstruct ( ) <EOL> new = SetCharField ( * args , ** kwargs ) <EOL> assert new . base_field . max_length == field . base_field . max_length <EOL> def test_makemigrations ( self ) : <EOL> field = SetCharField ( models . CharField ( max_length = <NUM_LIT:5> ) , max_length = <NUM_LIT:32> ) <EOL> statement , imports = MigrationWriter . serialize ( field ) <EOL> assert re . compile ( <EOL> r"""<STR_LIT>""" , <EOL> re . VERBOSE <EOL> ) . match ( statement ) <EOL> class TestMigrationWriter ( TestCase ) : <EOL> def test_makemigrations_with_size ( self ) : <EOL> field = SetCharField ( <EOL> models . CharField ( max_length = <NUM_LIT:5> ) , <EOL> max_length = <NUM_LIT:32> , <EOL> size = <NUM_LIT:5> <EOL> ) <EOL> statement , imports = MigrationWriter . serialize ( field ) <EOL> assert re . compile ( <EOL> r"""<STR_LIT>""" , <EOL> re . VERBOSE <EOL> ) . match ( statement ) <EOL> class TestMigrations ( TransactionTestCase ) : <EOL> @ override_settings ( MIGRATION_MODULES = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> def test_adding_field_with_default ( self ) : <EOL> table_name = '<STR_LIT>' <EOL> table_names = connection . introspection . table_names <EOL> with connection . cursor ( ) as cursor : <EOL> assert table_name not in table_names ( cursor ) <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , skip_checks = True ) <EOL> with connection . cursor ( ) as cursor : <EOL> assert table_name in table_names ( cursor ) <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , skip_checks = True ) <EOL> with connection . cursor ( ) as cursor : <EOL> assert table_name not in table_names ( cursor ) <EOL> class TestSerialization ( SimpleTestCase ) : <EOL> def test_dumping ( self ) : <EOL> instance = CharSetModel ( field = { "<STR_LIT>" , "<STR_LIT>" } ) <EOL> data = json . loads ( serializers . serialize ( '<STR_LIT>' , [ instance ] ) ) [ <NUM_LIT:0> ] <EOL> field = data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert sorted ( field . split ( '<STR_LIT:U+002C>' ) ) == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_loading ( self ) : <EOL> test_data = '''<STR_LIT>''' <EOL> objs = list ( serializers . deserialize ( '<STR_LIT>' , test_data ) ) <EOL> instance = objs [ <NUM_LIT:0> ] . object <EOL> assert instance . field == { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } <EOL> class TestDescription ( SimpleTestCase ) : <EOL> def test_char ( self ) : <EOL> field = SetCharField ( models . CharField ( max_length = <NUM_LIT:5> ) , max_length = <NUM_LIT:32> ) <EOL> assert field . description == "<STR_LIT>" <EOL> def test_int ( self ) : <EOL> field = SetCharField ( models . IntegerField ( ) , max_length = <NUM_LIT:32> ) <EOL> assert field . description == "<STR_LIT>" <EOL> class TestFormField ( SimpleTestCase ) : <EOL> def test_model_field_formfield ( self ) : <EOL> model_field = SetCharField ( models . CharField ( max_length = <NUM_LIT> ) ) <EOL> form_field = model_field . formfield ( ) <EOL> assert isinstance ( form_field , SimpleSetField ) <EOL> assert isinstance ( form_field . base_field , forms . CharField ) <EOL> assert form_field . base_field . max_length == <NUM_LIT> <EOL> def test_model_field_formfield_size ( self ) : <EOL> model_field = SetCharField ( models . IntegerField ( ) , size = <NUM_LIT:4> ) <EOL> form_field = model_field . formfield ( ) <EOL> assert isinstance ( form_field , SimpleSetField ) <EOL> assert form_field . max_length == <NUM_LIT:4> </s>
