MCPcopy Index your code
hub / github.com/python/cpython / test_nested_with_statements

Method test_nested_with_statements

Lib/test/test_decimal.py:3776–3809  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3774 self.assertEqual(ctx.prec, orig_prec)
3775
3776 def test_nested_with_statements(self):
3777 # Use a copy of the supplied context in the block
3778 Decimal = self.decimal.Decimal
3779 Context = self.decimal.Context
3780 getcontext = self.decimal.getcontext
3781 localcontext = self.decimal.localcontext
3782 Clamped = self.decimal.Clamped
3783 Overflow = self.decimal.Overflow
3784
3785 orig_ctx = getcontext()
3786 orig_ctx.clear_flags()
3787 new_ctx = Context(Emax=384)
3788 with localcontext() as c1:
3789 self.assertEqual(c1.flags, orig_ctx.flags)
3790 self.assertEqual(c1.traps, orig_ctx.traps)
3791 c1.traps[Clamped] = True
3792 c1.Emin = -383
3793 self.assertNotEqual(orig_ctx.Emin, -383)
3794 self.assertRaises(Clamped, c1.create_decimal, '0e-999')
3795 self.assertTrue(c1.flags[Clamped])
3796 with localcontext(new_ctx) as c2:
3797 self.assertEqual(c2.flags, new_ctx.flags)
3798 self.assertEqual(c2.traps, new_ctx.traps)
3799 self.assertRaises(Overflow, c2.power, Decimal('3.4e200'), 2)
3800 self.assertFalse(c2.flags[Clamped])
3801 self.assertTrue(c2.flags[Overflow])
3802 del c2
3803 self.assertFalse(c1.flags[Overflow])
3804 del c1
3805 self.assertNotEqual(orig_ctx.Emin, -383)
3806 self.assertFalse(orig_ctx.flags[Clamped])
3807 self.assertFalse(orig_ctx.flags[Overflow])
3808 self.assertFalse(new_ctx.flags[Clamped])
3809 self.assertFalse(new_ctx.flags[Overflow])
3810
3811 def test_with_statements_gc1(self):
3812 localcontext = self.decimal.localcontext

Callers

nothing calls this directly

Calls 10

getcontextFunction · 0.85
localcontextFunction · 0.85
DecimalClass · 0.85
clear_flagsMethod · 0.80
assertNotEqualMethod · 0.80
assertTrueMethod · 0.80
assertFalseMethod · 0.80
ContextClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected