<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 SimpleListField <EOL> from django_mysql . models import ListCharField , ListF <EOL> from django_mysql . test . utils import override_mysql_variables <EOL> from testapp . models import ( <EOL> CharListDefaultModel , CharListModel , IntListModel , TemporaryModel <EOL> ) <EOL> class TestSaveLoad ( TestCase ) : <EOL> def test_char_easy ( self ) : <EOL> s = CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> assert s . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> s = CharListModel . objects . get ( id = s . id ) <EOL> assert s . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> s . field . append ( "<STR_LIT>" ) <EOL> s . save ( ) <EOL> assert s . field == [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> s = CharListModel . objects . get ( id = s . id ) <EOL> assert s . field == [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_char_string_direct ( self ) : <EOL> s = CharListModel . objects . create ( field = "<STR_LIT>" ) <EOL> s = CharListModel . objects . get ( id = s . id ) <EOL> assert s . field == [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_is_a_list_immediately ( self ) : <EOL> s = CharListModel ( ) <EOL> assert s . field == [ ] <EOL> s . field . append ( "<STR_LIT>" ) <EOL> s . field . append ( "<STR_LIT>" ) <EOL> s . save ( ) <EOL> assert s . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> s = CharListModel . objects . get ( id = s . id ) <EOL> assert s . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_empty ( self ) : <EOL> s = CharListModel . objects . create ( ) <EOL> assert s . field == [ ] <EOL> s = CharListModel . objects . get ( id = s . id ) <EOL> assert s . field == [ ] <EOL> def test_char_cant_create_lists_with_empty_string ( self ) : <EOL> with pytest . raises ( ValueError ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> def test_char_cant_create_sets_with_commas ( self ) : <EOL> with pytest . raises ( ValueError ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_char_basic_lookup ( self ) : <EOL> mymodel = CharListModel . objects . create ( ) <EOL> empty = CharListModel . 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 = CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> mouldy = CharListModel . objects . filter ( ** { lname : "<STR_LIT>" } ) <EOL> assert mouldy . count ( ) == <NUM_LIT:1> <EOL> assert mouldy [ <NUM_LIT:0> ] == mymodel <EOL> rotten = CharListModel . objects . filter ( ** { lname : "<STR_LIT>" } ) <EOL> assert rotten . count ( ) == <NUM_LIT:1> <EOL> assert rotten [ <NUM_LIT:0> ] == mymodel <EOL> clean = CharListModel . objects . filter ( ** { lname : "<STR_LIT>" } ) <EOL> assert clean . count ( ) == <NUM_LIT:0> <EOL> with pytest . raises ( ValueError ) : <EOL> list ( CharListModel . objects . filter ( ** { lname : [ "<STR_LIT:a>" , "<STR_LIT:b>" ] } ) ) <EOL> both = CharListModel . 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 = CharListModel . objects . filter ( <EOL> Q ( ** { lname : "<STR_LIT>" } ) | Q ( ** { lname : "<STR_LIT>" } ) <EOL> ) <EOL> assert either . count ( ) == <NUM_LIT:1> <EOL> not_clean = CharListModel . objects . exclude ( ** { lname : "<STR_LIT>" } ) <EOL> assert not_clean . count ( ) == <NUM_LIT:1> <EOL> not_mouldy = CharListModel . objects . exclude ( ** { lname : "<STR_LIT>" } ) <EOL> assert not_mouldy . count ( ) == <NUM_LIT:0> <EOL> def test_char_len_lookup_empty ( self ) : <EOL> mymodel = CharListModel . objects . create ( field = [ ] ) <EOL> empty = CharListModel . objects . filter ( field__len = <NUM_LIT:0> ) <EOL> assert empty . count ( ) == <NUM_LIT:1> <EOL> assert empty [ <NUM_LIT:0> ] == mymodel <EOL> one = CharListModel . objects . filter ( field__len = <NUM_LIT:1> ) <EOL> assert one . count ( ) == <NUM_LIT:0> <EOL> one_or_more = CharListModel . 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 = CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> empty = CharListModel . objects . filter ( field__len = <NUM_LIT:0> ) <EOL> assert empty . count ( ) == <NUM_LIT:0> <EOL> one_or_more = CharListModel . 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 = CharListModel . objects . filter ( field__len = <NUM_LIT:2> ) <EOL> assert two . count ( ) == <NUM_LIT:1> <EOL> assert two [ <NUM_LIT:0> ] == mymodel <EOL> three = CharListModel . objects . filter ( field__len = <NUM_LIT:3> ) <EOL> assert three . count ( ) == <NUM_LIT:0> <EOL> def test_char_default ( self ) : <EOL> mymodel = CharListDefaultModel . objects . create ( ) <EOL> assert mymodel . field == [ "<STR_LIT:a>" , "<STR_LIT:d>" ] <EOL> mymodel = CharListDefaultModel . objects . get ( id = mymodel . id ) <EOL> assert mymodel . field == [ "<STR_LIT:a>" , "<STR_LIT:d>" ] <EOL> def test_char_position_lookup ( self ) : <EOL> mymodel = CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> blue0 = CharListModel . objects . filter ( field__0 = "<STR_LIT>" ) <EOL> assert blue0 . count ( ) == <NUM_LIT:0> <EOL> red0 = CharListModel . objects . filter ( field__0 = "<STR_LIT>" ) <EOL> assert list ( red0 ) == [ mymodel ] <EOL> red0_red1 = CharListModel . objects . filter ( field__0 = "<STR_LIT>" , <EOL> field__1 = "<STR_LIT>" ) <EOL> assert red0_red1 . count ( ) == <NUM_LIT:0> <EOL> red0_blue1 = CharListModel . objects . filter ( field__0 = "<STR_LIT>" , <EOL> field__1 = "<STR_LIT>" ) <EOL> assert list ( red0_blue1 ) == [ mymodel ] <EOL> red0_or_blue0 = CharListModel . objects . filter ( <EOL> Q ( field__0 = "<STR_LIT>" ) | Q ( field__0 = "<STR_LIT>" ) <EOL> ) <EOL> assert list ( red0_or_blue0 ) == [ mymodel ] <EOL> def test_char_position_lookup_repeat_fails ( self ) : <EOL> """<STR_LIT>""" <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> red1 = CharListModel . objects . filter ( field__1 = "<STR_LIT>" ) <EOL> assert list ( red1 ) == [ ] <EOL> def test_char_position_lookup_too_long ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> red1 = CharListModel . objects . filter ( field__2 = "<STR_LIT>" ) <EOL> assert list ( red1 ) == [ ] <EOL> def test_int_easy ( self ) : <EOL> mymodel = IntListModel . objects . create ( field = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert mymodel . field == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> mymodel = IntListModel . objects . get ( id = mymodel . id ) <EOL> assert mymodel . field == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> def test_int_contains_lookup ( self ) : <EOL> onetwo = IntListModel . objects . create ( field = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> ones = IntListModel . objects . filter ( field__contains = <NUM_LIT:1> ) <EOL> assert ones . count ( ) == <NUM_LIT:1> <EOL> assert ones [ <NUM_LIT:0> ] == onetwo <EOL> twos = IntListModel . objects . filter ( field__contains = <NUM_LIT:2> ) <EOL> assert twos . count ( ) == <NUM_LIT:1> <EOL> assert twos [ <NUM_LIT:0> ] == onetwo <EOL> threes = IntListModel . objects . filter ( field__contains = <NUM_LIT:3> ) <EOL> assert threes . count ( ) == <NUM_LIT:0> <EOL> with pytest . raises ( ValueError ) : <EOL> list ( IntListModel . objects . filter ( field__contains = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> ones_and_twos = IntListModel . 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 = IntListModel . 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 = IntListModel . 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 = IntListModel . objects . exclude ( field__contains = <NUM_LIT:3> ) <EOL> assert no_three . count ( ) == <NUM_LIT:1> <EOL> no_one = IntListModel . objects . exclude ( field__contains = <NUM_LIT:1> ) <EOL> assert no_one . count ( ) == <NUM_LIT:0> <EOL> def test_int_position_lookup ( self ) : <EOL> onetwo = IntListModel . objects . create ( field = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> one0 = IntListModel . objects . filter ( field__0 = <NUM_LIT:1> ) <EOL> assert list ( one0 ) == [ onetwo ] <EOL> two0 = IntListModel . objects . filter ( field__0 = <NUM_LIT:2> ) <EOL> assert two0 . count ( ) == <NUM_LIT:0> <EOL> one0two1 = IntListModel . objects . filter ( field__0 = <NUM_LIT:1> , field__1 = <NUM_LIT:2> ) <EOL> assert list ( one0two1 ) == [ onetwo ] <EOL> @ skipIf ( django . VERSION [ : <NUM_LIT:2> ] < ( <NUM_LIT:1> , <NUM_LIT:8> ) , <EOL> "<STR_LIT>" ) <EOL> class TestListF ( TestCase ) : <EOL> def test_append_to_none ( self ) : <EOL> CharListModel . objects . create ( field = [ ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" ] <EOL> def test_append_to_one ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_append_to_some ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_append_to_multiple_objects ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( "<STR_LIT>" ) ) <EOL> first , second = tuple ( CharListModel . objects . all ( ) ) <EOL> assert first . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> assert second . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_append_exists ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( "<STR_LIT>" ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> @ override_mysql_variables ( SQL_MODE = "<STR_LIT>" ) <EOL> def test_append_works_in_ansi_mode ( self ) : <EOL> CharListModel . objects . create ( ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( '<STR_LIT>' ) ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . append ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_append_assignment ( self ) : <EOL> model = CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> model . field = ListF ( '<STR_LIT>' ) . append ( '<STR_LIT>' ) <EOL> model . save ( ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_appendleft_to_none ( self ) : <EOL> CharListModel . objects . create ( field = [ ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" ] <EOL> def test_appendleft_to_one ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_appendleft_to_some ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_appendleft_to_multiple_objects ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( "<STR_LIT>" ) ) <EOL> first , second = tuple ( CharListModel . objects . all ( ) ) <EOL> assert first . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> assert second . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_appendleft_exists ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( "<STR_LIT>" ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> @ override_mysql_variables ( SQL_MODE = "<STR_LIT>" ) <EOL> def test_appendleft_works_in_ansi_mode ( self ) : <EOL> CharListModel . objects . create ( ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( '<STR_LIT>' ) ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . appendleft ( '<STR_LIT>' ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_appendleft_assignment ( self ) : <EOL> model = CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> model . field = ListF ( '<STR_LIT>' ) . appendleft ( '<STR_LIT>' ) <EOL> model . save ( ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def test_pop_none ( self ) : <EOL> CharListModel . objects . create ( field = [ ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . pop ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ ] <EOL> def test_pop_one ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . pop ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ ] <EOL> def test_pop_two ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . pop ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" ] <EOL> def test_pop_three ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:p>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . pop ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_popleft_none ( self ) : <EOL> CharListModel . objects . create ( field = [ ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . popleft ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ ] <EOL> def test_popleft_one ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . popleft ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ ] <EOL> def test_popleft_two ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . popleft ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" ] <EOL> def test_popleft_three ( self ) : <EOL> CharListModel . objects . create ( field = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:p>" ] ) <EOL> CharListModel . objects . update ( field = ListF ( '<STR_LIT>' ) . popleft ( ) ) <EOL> model = CharListModel . objects . get ( ) <EOL> assert model . field == [ "<STR_LIT>" , "<STR_LIT:p>" ] <EOL> class TestValidation ( SimpleTestCase ) : <EOL> def test_max_length ( self ) : <EOL> field = ListCharField ( <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_field_checks ( self ) : <EOL> class InvalidListCharModel ( TemporaryModel ) : <EOL> field = ListCharField ( models . CharField ( ) , max_length = <NUM_LIT:32> ) <EOL> errors = InvalidListCharModel . 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 InvalidListCharModel ( TemporaryModel ) : <EOL> field = ListCharField ( <EOL> models . ForeignKey ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:32> <EOL> ) <EOL> errors = InvalidListCharModel . 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 InvalidListCharModel ( TemporaryModel ) : <EOL> field = ListCharField ( <EOL> models . CharField ( max_length = <NUM_LIT:32> ) , <EOL> size = <NUM_LIT:2> , max_length = <NUM_LIT:32> ) <EOL> errors = InvalidListCharModel . 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 = ListCharField ( models . IntegerField ( ) , max_length = <NUM_LIT:32> ) <EOL> name , path , args , kwargs = field . deconstruct ( ) <EOL> new = ListCharField ( * args , ** kwargs ) <EOL> assert new . base_field . __class__ == field . base_field . __class__ <EOL> def test_deconstruct_with_size ( self ) : <EOL> field = ListCharField ( models . IntegerField ( ) , size = <NUM_LIT:3> , max_length = <NUM_LIT:32> ) <EOL> name , path , args , kwargs = field . deconstruct ( ) <EOL> new = ListCharField ( * args , ** kwargs ) <EOL> assert new . size == field . size <EOL> def test_deconstruct_args ( self ) : <EOL> field = ListCharField ( models . CharField ( max_length = <NUM_LIT:5> ) , max_length = <NUM_LIT:32> ) <EOL> name , path , args , kwargs = field . deconstruct ( ) <EOL> new = ListCharField ( * args , ** kwargs ) <EOL> assert new . base_field . max_length == field . base_field . max_length <EOL> class TestMigrationWriter ( TestCase ) : <EOL> def test_makemigrations ( self ) : <EOL> field = ListCharField ( 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> def test_makemigrations_with_size ( self ) : <EOL> field = ListCharField ( <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 = CharListModel ( 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 = ListCharField ( 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 = ListCharField ( 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 = ListCharField ( models . CharField ( max_length = <NUM_LIT> ) ) <EOL> form_field = model_field . formfield ( ) <EOL> assert isinstance ( form_field , SimpleListField ) <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 = ListCharField ( models . IntegerField ( ) , size = <NUM_LIT:4> ) <EOL> form_field = model_field . formfield ( ) <EOL> assert isinstance ( form_field , SimpleListField ) <EOL> assert form_field . max_length == <NUM_LIT:4> </s>
