-from test.test_support import verbose, have_unicode
+from test.test_support import verbose, have_unicode, TestFailed
import sys
# test string formatting operator (I am not sure if this is being tested
if verbose: print 'no'
print 'Unexpected exception'
raise
+ else:
+ raise TestFailed, 'did not get expected exception: %s' % excmsg
test_exc('abc %a', 1, ValueError,
"unsupported format character 'a' (0x61) at index 5")
if have_unicode:
test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError,
"unsupported format character '?' (0x3000) at index 5")
+
+test_exc('%d', '1', TypeError, "int argument required")
+test_exc('%g', '1', TypeError, "float argument required")
+
worst case length = 3 + 10 (len of INT_MAX) + 1 = 14 (use 20)*/
char fmt[20];
double x;
- v = PyNumber_Float(v);
- if (!v)
+ x = PyFloat_AsDouble(v);
+ if (x == -1.0 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "float argument required");
return -1;
- x = PyFloat_AS_DOUBLE(v);
- Py_DECREF(v);
+ }
if (prec < 0)
prec = 6;
if (type == 'f' && fabs(x)/1e25 >= 1e25)
char fmt[64]; /* plenty big enough! */
long x;
- v = PyNumber_Int(v);
- if (!v)
+ x = PyInt_AsLong(v);
+ if (x == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "int argument required");
return -1;
- x = PyInt_AS_LONG(v);
- Py_DECREF(v);
+ }
if (prec < 0)
prec = 1;