MCPcopy Index your code
hub / github.com/python/cpython / testformat

Function testformat

Lib/test/test_format.py:16–49  ·  view source on GitHub ↗
(formatstr, args, output=None, limit=None, overflowok=False)

Source from the content-addressed store, hash-verified

14# test on bytes object as well
15
16def testformat(formatstr, args, output=None, limit=None, overflowok=False):
17 if verbose:
18 if output:
19 print("{!a} % {!a} =? {!a} ...".format(formatstr, args, output),
20 end=' ')
21 else:
22 print("{!a} % {!a} works? ...".format(formatstr, args), end=' ')
23 try:
24 result = formatstr % args
25 except OverflowError:
26 if not overflowok:
27 raise
28 if verbose:
29 print('overflow (this is fine)')
30 else:
31 if output and limit is None and result != output:
32 if verbose:
33 print('no')
34 raise AssertionError("%r %% %r == %r != %r" %
35 (formatstr, args, result, output))
36 # when 'limit' is specified, it determines how many characters
37 # must match exactly; lengths must always match.
38 # ex: limit=5, '12345678' matches '12345___'
39 # (mainly for floating-point format tests for which an exact match
40 # can't be guaranteed due to rounding and representation errors)
41 elif output and limit is not None and (
42 len(result)!=len(output) or result[:limit]!=output[:limit]):
43 if verbose:
44 print('no')
45 print("%s %% %s == %s != %s" % \
46 (repr(formatstr), repr(args), repr(result), repr(output)))
47 else:
48 if verbose:
49 print('yes')
50
51def testcommon(formatstr, args, output=None, limit=None, overflowok=False):
52 # if formatstr is a str, test str, bytes, and bytearray;

Callers 5

testcommonFunction · 0.85
test_excFunction · 0.85
test_str_formatMethod · 0.85
test_nulMethod · 0.85
test_non_asciiMethod · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…