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+
16v4.16.0
27=======
38
Original file line number Diff line number Diff line change @@ -297,7 +297,9 @@ def __len__(self):
297297 return self .total_errors
298298
299299 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 } )>"
301303
302304 @property
303305 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):
396396 tree = exceptions .ErrorTree ([error ])
397397 self .assertIsInstance (tree ["foo" ], exceptions .ErrorTree )
398398
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 ):
400410 e1 , e2 = (
401411 exceptions .ValidationError (
402412 "1" ,
@@ -412,6 +422,10 @@ def test_repr(self):
412422 tree = exceptions .ErrorTree ([e1 , e2 ])
413423 self .assertEqual (repr (tree ), "<ErrorTree (2 total errors)>" )
414424
425+ def test_repr_empty (self ):
426+ tree = exceptions .ErrorTree ([])
427+ self .assertEqual (repr (tree ), "<ErrorTree (0 total errors)>" )
428+
415429
416430class TestErrorInitReprStr (TestCase ):
417431 def make_error (self , ** kwargs ):
You can’t perform that action at this time.
0 commit comments