File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change
1
+ v4.16.1
2
+ =======
3
+
4
+ * Make ``ErrorTree `` have a more grammatically correct ``repr ``.
5
+
1
6
v4.16.0
2
7
=======
3
8
Original file line number Diff line number Diff line change @@ -297,7 +297,9 @@ def __len__(self):
297
297
return self .total_errors
298
298
299
299
def __repr__ (self ):
300
- return f"<{ self .__class__ .__name__ } ({ len (self )} total errors)>"
300
+ total = len (self )
301
+ errors = "error" if total == 1 else "errors"
302
+ return f"<{ self .__class__ .__name__ } ({ total } total { errors } )>"
301
303
302
304
@property
303
305
def total_errors (self ):
Original file line number Diff line number Diff line change @@ -396,7 +396,17 @@ def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
396
396
tree = exceptions .ErrorTree ([error ])
397
397
self .assertIsInstance (tree ["foo" ], exceptions .ErrorTree )
398
398
399
- def test_repr (self ):
399
+ def test_repr_single (self ):
400
+ error = exceptions .ValidationError (
401
+ "1" ,
402
+ validator = "foo" ,
403
+ path = ["bar" , "bar2" ],
404
+ instance = "i1" ,
405
+ )
406
+ tree = exceptions .ErrorTree ([error ])
407
+ self .assertEqual (repr (tree ), "<ErrorTree (1 total error)>" )
408
+
409
+ def test_repr_multiple (self ):
400
410
e1 , e2 = (
401
411
exceptions .ValidationError (
402
412
"1" ,
@@ -412,6 +422,10 @@ def test_repr(self):
412
422
tree = exceptions .ErrorTree ([e1 , e2 ])
413
423
self .assertEqual (repr (tree ), "<ErrorTree (2 total errors)>" )
414
424
425
+ def test_repr_empty (self ):
426
+ tree = exceptions .ErrorTree ([])
427
+ self .assertEqual (repr (tree ), "<ErrorTree (0 total errors)>" )
428
+
415
429
416
430
class TestErrorInitReprStr (TestCase ):
417
431
def make_error (self , ** kwargs ):
You can’t perform that action at this time.
0 commit comments