Merge 3.3.
This commit is contained in:
commit
82c6029832
@ -4971,22 +4971,16 @@ class CWhitebox(unittest.TestCase):
|
|||||||
def test_c_format(self):
|
def test_c_format(self):
|
||||||
# Restricted input
|
# Restricted input
|
||||||
Decimal = C.Decimal
|
Decimal = C.Decimal
|
||||||
InvalidOperation = C.InvalidOperation
|
|
||||||
Rounded = C.Rounded
|
|
||||||
localcontext = C.localcontext
|
|
||||||
HAVE_CONFIG_64 = (C.MAX_PREC > 425000000)
|
HAVE_CONFIG_64 = (C.MAX_PREC > 425000000)
|
||||||
|
|
||||||
self.assertRaises(TypeError, Decimal(1).__format__, "=10.10", [], 9)
|
self.assertRaises(TypeError, Decimal(1).__format__, "=10.10", [], 9)
|
||||||
self.assertRaises(TypeError, Decimal(1).__format__, "=10.10", 9)
|
self.assertRaises(TypeError, Decimal(1).__format__, "=10.10", 9)
|
||||||
self.assertRaises(TypeError, Decimal(1).__format__, [])
|
self.assertRaises(TypeError, Decimal(1).__format__, [])
|
||||||
|
|
||||||
with localcontext() as c:
|
self.assertRaises(ValueError, Decimal(1).__format__, "<>=10.10")
|
||||||
c.traps[InvalidOperation] = True
|
maxsize = 2**63-1 if HAVE_CONFIG_64 else 2**31-1
|
||||||
c.traps[Rounded] = True
|
self.assertRaises(ValueError, Decimal("1.23456789").__format__,
|
||||||
self.assertRaises(ValueError, Decimal(1).__format__, "<>=10.10")
|
"=%d.1" % maxsize)
|
||||||
maxsize = 2**63-1 if HAVE_CONFIG_64 else 2**31-1
|
|
||||||
self.assertRaises(InvalidOperation, Decimal("1.23456789").__format__,
|
|
||||||
"=%d.1" % maxsize)
|
|
||||||
|
|
||||||
def test_c_integral(self):
|
def test_c_integral(self):
|
||||||
Decimal = C.Decimal
|
Decimal = C.Decimal
|
||||||
|
@ -3222,7 +3222,13 @@ dec_format(PyObject *dec, PyObject *args)
|
|||||||
|
|
||||||
decstring = mpd_qformat_spec(MPD(dec), &spec, CTX(context), &status);
|
decstring = mpd_qformat_spec(MPD(dec), &spec, CTX(context), &status);
|
||||||
if (decstring == NULL) {
|
if (decstring == NULL) {
|
||||||
dec_addstatus(context, status);
|
if (status & MPD_Malloc_error) {
|
||||||
|
PyErr_NoMemory();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"format specification exceeds internal limits of _decimal");
|
||||||
|
}
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
result = PyUnicode_DecodeUTF8(decstring, strlen(decstring), NULL);
|
result = PyUnicode_DecodeUTF8(decstring, strlen(decstring), NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user