@@ -31,6 +31,16 @@ def assertValid(self, value, key="k"):
3131 def assertInvalid (self , value , key = "k" ):
3232 self .assertIsNone (_clean_attribute (key , value , None ))
3333
34+ def test_attribute_key_validation (self ):
35+ # only non-empty strings are valid keys
36+ self .assertInvalid (1 , "" )
37+ self .assertInvalid (1 , 1 )
38+ self .assertInvalid (1 , {})
39+ self .assertInvalid (1 , [])
40+ self .assertInvalid (1 , b"1" )
41+ self .assertValid (1 , "k" )
42+ self .assertValid (1 , "1" )
43+
3444 def test_clean_attribute (self ):
3545 self .assertInvalid ([1 , 2 , 3.4 , "ss" , 4 ])
3646 self .assertInvalid ([dict (), 1 , 2 , 3.4 , 4 ])
@@ -142,10 +152,10 @@ def test_bounded_dict(self):
142152 def test_no_limit_code (self ):
143153 bdict = BoundedAttributes (maxlen = None , immutable = False )
144154 for num in range (100 ):
145- bdict [num ] = num
155+ bdict [str ( num ) ] = num
146156
147157 for num in range (100 ):
148- self .assertEqual (bdict [num ], num )
158+ self .assertEqual (bdict [str ( num ) ], num )
149159
150160 def test_immutable (self ):
151161 bdict = BoundedAttributes ()
0 commit comments