@@ -127,10 +127,12 @@ def test_iban_validator(self):
127
127
128
128
iban_validator = IBANValidator ()
129
129
for iban in valid :
130
- iban_validator (iban )
130
+ with self .subTest (iban = iban ):
131
+ iban_validator (iban )
131
132
132
133
for iban in invalid :
133
- self .assertRaisesMessage (ValidationError , invalid [iban ], IBANValidator (), iban )
134
+ with self .subTest (iban = iban ):
135
+ self .assertRaisesMessage (ValidationError , invalid [iban ], IBANValidator (), iban )
134
136
135
137
def test_iban_validator_deconstruct (self ):
136
138
# Call to the required deconstruct method to see if it exists and
@@ -145,9 +147,10 @@ def test_iban_validator_deconstruct(self):
145
147
]
146
148
147
149
for test_case in test_cases :
148
- iban1 = IBANValidator (** test_case )
149
- iban2 = IBANValidator (** test_case )
150
- self .assertEqual (iban1 , iban2 , msg = "IBAN validators with equal parameters are not equal." )
150
+ with self .subTest (test_case = test_case ):
151
+ iban1 = IBANValidator (** test_case )
152
+ iban2 = IBANValidator (** test_case )
153
+ self .assertEqual (iban1 , iban2 , msg = "IBAN validators with equal parameters are not equal." )
151
154
152
155
def test_iban_fields (self ):
153
156
"""Test the IBAN model and form field."""
@@ -194,17 +197,19 @@ def test_iban_fields(self):
194
197
# Test valid inputs for model field.
195
198
iban_model_field = IBANField ()
196
199
for input , output in valid .items ():
197
- self .assertEqual (iban_model_field .clean (input , None ), output )
200
+ with self .subTest (input = input , output = output ):
201
+ self .assertEqual (iban_model_field .clean (input , None ), output )
198
202
199
203
self .assertIsNone (iban_model_field .to_python (None ))
200
204
201
205
# Invalid inputs for model field.
202
206
for input , errors in invalid .items ():
203
- with self .assertRaises (ValidationError ) as context_manager :
204
- iban_model_field .clean (input , None )
205
- # The error messages for models are in a different order.
206
- errors .reverse ()
207
- self .assertEqual (context_manager .exception .messages , errors )
207
+ with self .subTest (input = input , errors = errors ):
208
+ with self .assertRaises (ValidationError ) as context_manager :
209
+ iban_model_field .clean (input , None )
210
+ # The error messages for models are in a different order.
211
+ errors .reverse ()
212
+ self .assertEqual (context_manager .exception .messages , errors )
208
213
209
214
def test_nordea_extensions (self ):
210
215
"""Test a valid IBAN in the Nordea extensions."""
@@ -249,15 +254,17 @@ def test_include_countries(self):
249
254
# Test valid inputs for model field.
250
255
iban_model_field = IBANField (include_countries = include_countries )
251
256
for input , output in valid .items ():
252
- self .assertEqual (iban_model_field .clean (input , None ), output )
257
+ with self .subTest (input = input , output = output ):
258
+ self .assertEqual (iban_model_field .clean (input , None ), output )
253
259
254
260
# Invalid inputs for model field.
255
261
for input , errors in invalid .items ():
256
- with self .assertRaises (ValidationError ) as context_manager :
257
- iban_model_field .clean (input , None )
258
- # The error messages for models are in a different order.
259
- errors .reverse ()
260
- self .assertEqual (context_manager .exception .messages , errors )
262
+ with self .subTest (input = input , errors = errors ):
263
+ with self .assertRaises (ValidationError ) as context_manager :
264
+ iban_model_field .clean (input , None )
265
+ # The error messages for models are in a different order.
266
+ errors .reverse ()
267
+ self .assertEqual (context_manager .exception .messages , errors )
261
268
262
269
def test_misconfigured_include_countries (self ):
263
270
"""Test that an IBAN field or model raises an error when asked to validate a country not part of IBAN."""
@@ -297,7 +304,8 @@ def test_model_field_deconstruct(self):
297
304
name , path , args , kwargs = test_instance .deconstruct ()
298
305
new_instance = IBANField (* args , ** kwargs )
299
306
for attr in ('include_countries' , 'use_nordea_extensions' ):
300
- self .assertEqual (getattr (test_instance , attr ), getattr (new_instance , attr ))
307
+ with self .subTest (attr = attr ):
308
+ self .assertEqual (getattr (test_instance , attr ), getattr (new_instance , attr ))
301
309
302
310
303
311
class BICTests (TestCase ):
@@ -370,15 +378,17 @@ def test_bic_model_field(self):
370
378
371
379
# Test valid inputs for model field.
372
380
for input , output in valid .items ():
373
- self .assertEqual (bic_model_field .clean (input , None ), output )
381
+ with self .subTest (input = input , output = output ):
382
+ self .assertEqual (bic_model_field .clean (input , None ), output )
374
383
375
384
self .assertIsNone (bic_model_field .to_python (None ))
376
385
377
386
# Invalid inputs for model field.
378
387
for input , errors in invalid .items ():
379
- with self .assertRaises (ValidationError ) as context_manager :
380
- bic_model_field .clean (input , None )
381
- self .assertEqual (errors , context_manager .exception .messages )
388
+ with self .subTest (input = input , errors = errors ):
389
+ with self .assertRaises (ValidationError ) as context_manager :
390
+ bic_model_field .clean (input , None )
391
+ self .assertEqual (errors , context_manager .exception .messages )
382
392
383
393
def test_default_form (self ):
384
394
bic_model_field = BICField ()
@@ -408,10 +418,12 @@ def test_ean_validator(self):
408
418
409
419
validator = EANValidator ()
410
420
for value in valid :
411
- validator (value )
421
+ with self .subTest (value = value ):
422
+ validator (value )
412
423
413
424
for value in invalid :
414
- self .assertRaisesMessage (ValidationError , error_message , validator , value )
425
+ with self .subTest (value = value ):
426
+ self .assertRaisesMessage (ValidationError , error_message , validator , value )
415
427
416
428
def test_ean_validator_deconstruct (self ):
417
429
# Call to the required deconstruct method to see if it exists and
@@ -426,9 +438,10 @@ def test_ean_validator_deconstruct(self):
426
438
]
427
439
428
440
for test_case in test_cases :
429
- ean1 = EANValidator (** test_case )
430
- ean2 = EANValidator (** test_case )
431
- self .assertEqual (ean1 , ean2 , msg = "EAN validators with equal parameters are not equal." )
441
+ with self .subTest (test_case = test_case ):
442
+ ean1 = EANValidator (** test_case )
443
+ ean2 = EANValidator (** test_case )
444
+ self .assertEqual (ean1 , ean2 , msg = "EAN validators with equal parameters are not equal." )
432
445
433
446
def test_ean_validator_strip_nondigits (self ):
434
447
valid = [
@@ -456,7 +469,9 @@ def test_ean_validator_strip_nondigits(self):
456
469
457
470
validator = EANValidator (strip_nondigits = True )
458
471
for value in valid :
459
- validator (value )
472
+ with self .subTest (value = value ):
473
+ validator (value )
460
474
461
475
for value in invalid :
462
- self .assertRaisesMessage (ValidationError , error_message , validator , value )
476
+ with self .subTest (value = value ):
477
+ self .assertRaisesMessage (ValidationError , error_message , validator , value )
0 commit comments