(formatstr, args, output=None, limit=None, overflowok=False)
| 14 | # test on bytes object as well |
| 15 | |
| 16 | def 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 | |
| 51 | def testcommon(formatstr, args, output=None, limit=None, overflowok=False): |
| 52 | # if formatstr is a str, test str, bytes, and bytearray; |
no test coverage detected
searching dependent graphs…