(self)
| 289 | "%i format: a real number is required, not bytes") |
| 290 | |
| 291 | def test_str_format(self): |
| 292 | testformat("%r", "\u0378", "'\\u0378'") # non printable |
| 293 | testformat("%a", "\u0378", "'\\u0378'") # non printable |
| 294 | testformat("%r", "\u0374", "'\u0374'") # printable |
| 295 | testformat("%a", "\u0374", "'\\u0374'") # printable |
| 296 | |
| 297 | # Test exception for unknown format characters, etc. |
| 298 | if verbose: |
| 299 | print('Testing exceptions') |
| 300 | test_exc('abc %b', 1, ValueError, |
| 301 | "unsupported format character 'b' (0x62) at index 5") |
| 302 | #test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError, |
| 303 | # "unsupported format character '?' (0x3000) at index 5") |
| 304 | test_exc('%g', '1', TypeError, "must be real number, not str") |
| 305 | test_exc('no format', '1', TypeError, |
| 306 | "not all arguments converted during string formatting") |
| 307 | test_exc('%c', -1, OverflowError, "%c arg not in range(0x110000)") |
| 308 | test_exc('%c', sys.maxunicode+1, OverflowError, |
| 309 | "%c arg not in range(0x110000)") |
| 310 | #test_exc('%c', 2**128, OverflowError, "%c arg not in range(0x110000)") |
| 311 | test_exc('%c', 3.14, TypeError, "%c requires an int or a unicode character, not float") |
| 312 | test_exc('%c', 'ab', TypeError, "%c requires an int or a unicode character, not a string of length 2") |
| 313 | test_exc('%c', b'x', TypeError, "%c requires an int or a unicode character, not bytes") |
| 314 | |
| 315 | if maxsize == 2**31-1: |
| 316 | # crashes 2.2.1 and earlier: |
| 317 | try: |
| 318 | "%*d"%(maxsize, -127) |
| 319 | except MemoryError: |
| 320 | pass |
| 321 | else: |
| 322 | raise TestFailed('"%*d"%(maxsize, -127) should fail') |
| 323 | |
| 324 | def test_bytes_and_bytearray_format(self): |
| 325 | # %c will insert a single byte, either from an int in range(256), or |
nothing calls this directly
no test coverage detected