(self)
| 5064 | self.assertEqual(s, t) |
| 5065 | |
| 5066 | def test_c_context_errors(self): |
| 5067 | Context = C.Context |
| 5068 | InvalidOperation = C.InvalidOperation |
| 5069 | Overflow = C.Overflow |
| 5070 | FloatOperation = C.FloatOperation |
| 5071 | localcontext = C.localcontext |
| 5072 | getcontext = C.getcontext |
| 5073 | setcontext = C.setcontext |
| 5074 | HAVE_CONFIG_64 = (C.MAX_PREC > 425000000) |
| 5075 | |
| 5076 | c = Context() |
| 5077 | |
| 5078 | # SignalDict: input validation |
| 5079 | self.assertRaises(KeyError, c.flags.__setitem__, 801, 0) |
| 5080 | self.assertRaises(KeyError, c.traps.__setitem__, 801, 0) |
| 5081 | self.assertRaises(ValueError, c.flags.__delitem__, Overflow) |
| 5082 | self.assertRaises(ValueError, c.traps.__delitem__, InvalidOperation) |
| 5083 | self.assertRaises(TypeError, setattr, c, 'flags', ['x']) |
| 5084 | self.assertRaises(TypeError, setattr, c,'traps', ['y']) |
| 5085 | self.assertRaises(KeyError, setattr, c, 'flags', {0:1}) |
| 5086 | self.assertRaises(KeyError, setattr, c, 'traps', {0:1}) |
| 5087 | |
| 5088 | # Test assignment from a signal dict with the correct length but |
| 5089 | # one invalid key. |
| 5090 | d = c.flags.copy() |
| 5091 | del d[FloatOperation] |
| 5092 | d["XYZ"] = 91283719 |
| 5093 | self.assertRaises(KeyError, setattr, c, 'flags', d) |
| 5094 | self.assertRaises(KeyError, setattr, c, 'traps', d) |
| 5095 | |
| 5096 | # Input corner cases |
| 5097 | int_max = 2**63-1 if HAVE_CONFIG_64 else 2**31-1 |
| 5098 | gt_max_emax = 10**18 if HAVE_CONFIG_64 else 10**9 |
| 5099 | |
| 5100 | # prec, Emax, Emin |
| 5101 | for attr in ['prec', 'Emax']: |
| 5102 | self.assertRaises(ValueError, setattr, c, attr, gt_max_emax) |
| 5103 | self.assertRaises(ValueError, setattr, c, 'Emin', -gt_max_emax) |
| 5104 | |
| 5105 | # prec, Emax, Emin in context constructor |
| 5106 | self.assertRaises(ValueError, Context, prec=gt_max_emax) |
| 5107 | self.assertRaises(ValueError, Context, Emax=gt_max_emax) |
| 5108 | self.assertRaises(ValueError, Context, Emin=-gt_max_emax) |
| 5109 | |
| 5110 | # Overflow in conversion |
| 5111 | self.assertRaises(OverflowError, Context, prec=int_max+1) |
| 5112 | self.assertRaises(OverflowError, Context, Emax=int_max+1) |
| 5113 | self.assertRaises(OverflowError, Context, Emin=-int_max-2) |
| 5114 | self.assertRaises(OverflowError, Context, clamp=int_max+1) |
| 5115 | self.assertRaises(OverflowError, Context, capitals=int_max+1) |
| 5116 | |
| 5117 | # OverflowError, general ValueError |
| 5118 | for attr in ('prec', 'Emin', 'Emax', 'capitals', 'clamp'): |
| 5119 | self.assertRaises(OverflowError, setattr, c, attr, int_max+1) |
| 5120 | self.assertRaises(OverflowError, setattr, c, attr, -int_max-2) |
| 5121 | if sys.platform != 'win32': |
| 5122 | self.assertRaises(ValueError, setattr, c, attr, int_max) |
| 5123 | self.assertRaises(ValueError, setattr, c, attr, -int_max-1) |
nothing calls this directly
no test coverage detected