(self)
| 96 | class FormatTest(unittest.TestCase): |
| 97 | |
| 98 | def test_common_format(self): |
| 99 | # test the format identifiers that work the same across |
| 100 | # str, bytes, and bytearrays (integer, float, oct, hex) |
| 101 | testcommon("%%", (), "%") |
| 102 | testcommon("%.1d", (1,), "1") |
| 103 | testcommon("%.*d", (sys.maxsize,1), overflowok=True) # expect overflow |
| 104 | testcommon("%.100d", (1,), '00000000000000000000000000000000000000' |
| 105 | '000000000000000000000000000000000000000000000000000000' |
| 106 | '00000001', overflowok=True) |
| 107 | testcommon("%#.117x", (1,), '0x00000000000000000000000000000000000' |
| 108 | '000000000000000000000000000000000000000000000000000000' |
| 109 | '0000000000000000000000000001', |
| 110 | overflowok=True) |
| 111 | testcommon("%#.118x", (1,), '0x00000000000000000000000000000000000' |
| 112 | '000000000000000000000000000000000000000000000000000000' |
| 113 | '00000000000000000000000000001', |
| 114 | overflowok=True) |
| 115 | |
| 116 | testcommon("%f", (1.0,), "1.000000") |
| 117 | # these are trying to test the limits of the internal magic-number-length |
| 118 | # formatting buffer, if that number changes then these tests are less |
| 119 | # effective |
| 120 | testcommon("%#.*g", (109, -1.e+49/3.)) |
| 121 | testcommon("%#.*g", (110, -1.e+49/3.)) |
| 122 | testcommon("%#.*g", (110, -1.e+100/3.)) |
| 123 | # test some ridiculously large precision, expect overflow |
| 124 | testcommon('%12.*f', (123456, 1.0)) |
| 125 | |
| 126 | # check for internal overflow validation on length of precision |
| 127 | # these tests should no longer cause overflow in Python |
| 128 | # 2.7/3.1 and later. |
| 129 | testcommon("%#.*g", (110, -1.e+100/3.)) |
| 130 | testcommon("%#.*G", (110, -1.e+100/3.)) |
| 131 | testcommon("%#.*f", (110, -1.e+100/3.)) |
| 132 | testcommon("%#.*F", (110, -1.e+100/3.)) |
| 133 | # Formatting of integers. Overflow is not ok |
| 134 | testcommon("%x", 10, "a") |
| 135 | testcommon("%x", 100000000000, "174876e800") |
| 136 | testcommon("%o", 10, "12") |
| 137 | testcommon("%o", 100000000000, "1351035564000") |
| 138 | testcommon("%d", 10, "10") |
| 139 | testcommon("%d", 100000000000, "100000000000") |
| 140 | |
| 141 | big = 123456789012345678901234567890 |
| 142 | testcommon("%d", big, "123456789012345678901234567890") |
| 143 | testcommon("%d", -big, "-123456789012345678901234567890") |
| 144 | testcommon("%5d", -big, "-123456789012345678901234567890") |
| 145 | testcommon("%31d", -big, "-123456789012345678901234567890") |
| 146 | testcommon("%32d", -big, " -123456789012345678901234567890") |
| 147 | testcommon("%-32d", -big, "-123456789012345678901234567890 ") |
| 148 | testcommon("%032d", -big, "-0123456789012345678901234567890") |
| 149 | testcommon("%-032d", -big, "-123456789012345678901234567890 ") |
| 150 | testcommon("%034d", -big, "-000123456789012345678901234567890") |
| 151 | testcommon("%034d", big, "0000123456789012345678901234567890") |
| 152 | testcommon("%0+34d", big, "+000123456789012345678901234567890") |
| 153 | testcommon("%+34d", big, " +123456789012345678901234567890") |
| 154 | testcommon("%34d", big, " 123456789012345678901234567890") |
| 155 | testcommon("%.2d", big, "123456789012345678901234567890") |
nothing calls this directly
no test coverage detected