(self)
| 4307 | class ContextSubclassing: |
| 4308 | |
| 4309 | def test_context_subclassing(self): |
| 4310 | decimal = self.decimal |
| 4311 | Decimal = decimal.Decimal |
| 4312 | Context = decimal.Context |
| 4313 | Clamped = decimal.Clamped |
| 4314 | DivisionByZero = decimal.DivisionByZero |
| 4315 | Inexact = decimal.Inexact |
| 4316 | Overflow = decimal.Overflow |
| 4317 | Rounded = decimal.Rounded |
| 4318 | Subnormal = decimal.Subnormal |
| 4319 | Underflow = decimal.Underflow |
| 4320 | InvalidOperation = decimal.InvalidOperation |
| 4321 | |
| 4322 | class MyContext(Context): |
| 4323 | def __init__(self, prec=None, rounding=None, Emin=None, Emax=None, |
| 4324 | capitals=None, clamp=None, flags=None, |
| 4325 | traps=None): |
| 4326 | Context.__init__(self) |
| 4327 | if prec is not None: |
| 4328 | self.prec = prec |
| 4329 | if rounding is not None: |
| 4330 | self.rounding = rounding |
| 4331 | if Emin is not None: |
| 4332 | self.Emin = Emin |
| 4333 | if Emax is not None: |
| 4334 | self.Emax = Emax |
| 4335 | if capitals is not None: |
| 4336 | self.capitals = capitals |
| 4337 | if clamp is not None: |
| 4338 | self.clamp = clamp |
| 4339 | if flags is not None: |
| 4340 | if isinstance(flags, list): |
| 4341 | flags = {v:(v in flags) for v in OrderedSignals[decimal] + flags} |
| 4342 | self.flags = flags |
| 4343 | if traps is not None: |
| 4344 | if isinstance(traps, list): |
| 4345 | traps = {v:(v in traps) for v in OrderedSignals[decimal] + traps} |
| 4346 | self.traps = traps |
| 4347 | |
| 4348 | c = Context() |
| 4349 | d = MyContext() |
| 4350 | for attr in ('prec', 'rounding', 'Emin', 'Emax', 'capitals', 'clamp', |
| 4351 | 'flags', 'traps'): |
| 4352 | self.assertEqual(getattr(c, attr), getattr(d, attr)) |
| 4353 | |
| 4354 | # prec |
| 4355 | self.assertRaises(ValueError, MyContext, **{'prec':-1}) |
| 4356 | c = MyContext(prec=1) |
| 4357 | self.assertEqual(c.prec, 1) |
| 4358 | self.assertRaises(InvalidOperation, c.quantize, Decimal('9e2'), 0) |
| 4359 | |
| 4360 | # rounding |
| 4361 | self.assertRaises(TypeError, MyContext, **{'rounding':'XYZ'}) |
| 4362 | c = MyContext(rounding=ROUND_DOWN, prec=1) |
| 4363 | self.assertEqual(c.rounding, ROUND_DOWN) |
| 4364 | self.assertEqual(c.plus(Decimal('9.9')), 9) |
| 4365 | |
| 4366 | # Emin |
nothing calls this directly
no test coverage detected