Skip to content

Commit 1980f9b

Browse files
committed
Provide the missing safe_rep function required in the back-ported assertIsNone() test case method.
- Legacy-Id: 6261
1 parent 08ea8c1 commit 1980f9b

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

django/test/testcases.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def restore_transaction_methods():
6363
transaction.leave_transaction_management = real_leave_transaction_management
6464
transaction.managed = real_managed
6565

66+
_MAX_LENGTH = 80
67+
def safe_repr(obj, short=False):
68+
try:
69+
result = repr(obj)
70+
except Exception:
71+
result = object.__repr__(obj)
72+
if not short or len(result) < _MAX_LENGTH:
73+
return result
74+
return result[:_MAX_LENGTH] + ' [truncated]...'
75+
6676
class OutputChecker(doctest.OutputChecker):
6777
def check_output(self, want, got, optionflags):
6878
"The entry method for doctest output checking. Defers to a sequence of child checkers"

0 commit comments

Comments
 (0)