(self)
| 3879 | class ContextFlags: |
| 3880 | |
| 3881 | def test_flags_irrelevant(self): |
| 3882 | # check that the result (numeric result + flags raised) of an |
| 3883 | # arithmetic operation doesn't depend on the current flags |
| 3884 | Decimal = self.decimal.Decimal |
| 3885 | Context = self.decimal.Context |
| 3886 | Inexact = self.decimal.Inexact |
| 3887 | Rounded = self.decimal.Rounded |
| 3888 | Underflow = self.decimal.Underflow |
| 3889 | Clamped = self.decimal.Clamped |
| 3890 | Subnormal = self.decimal.Subnormal |
| 3891 | |
| 3892 | def raise_error(context, flag): |
| 3893 | if self.decimal == C: |
| 3894 | context.flags[flag] = True |
| 3895 | if context.traps[flag]: |
| 3896 | raise flag |
| 3897 | else: |
| 3898 | context._raise_error(flag) |
| 3899 | |
| 3900 | context = Context(prec=9, Emin = -425000000, Emax = 425000000, |
| 3901 | rounding=ROUND_HALF_EVEN, traps=[], flags=[]) |
| 3902 | |
| 3903 | # operations that raise various flags, in the form (function, arglist) |
| 3904 | operations = [ |
| 3905 | (context._apply, [Decimal("100E-425000010")]), |
| 3906 | (context.sqrt, [Decimal(2)]), |
| 3907 | (context.add, [Decimal("1.23456789"), Decimal("9.87654321")]), |
| 3908 | (context.multiply, [Decimal("1.23456789"), Decimal("9.87654321")]), |
| 3909 | (context.subtract, [Decimal("1.23456789"), Decimal("9.87654321")]), |
| 3910 | ] |
| 3911 | |
| 3912 | # try various flags individually, then a whole lot at once |
| 3913 | flagsets = [[Inexact], [Rounded], [Underflow], [Clamped], [Subnormal], |
| 3914 | [Inexact, Rounded, Underflow, Clamped, Subnormal]] |
| 3915 | |
| 3916 | for fn, args in operations: |
| 3917 | # find answer and flags raised using a clean context |
| 3918 | context.clear_flags() |
| 3919 | ans = fn(*args) |
| 3920 | flags = [k for k, v in context.flags.items() if v] |
| 3921 | |
| 3922 | for extra_flags in flagsets: |
| 3923 | # set flags, before calling operation |
| 3924 | context.clear_flags() |
| 3925 | for flag in extra_flags: |
| 3926 | raise_error(context, flag) |
| 3927 | new_ans = fn(*args) |
| 3928 | |
| 3929 | # flags that we expect to be set after the operation |
| 3930 | expected_flags = list(flags) |
| 3931 | for flag in extra_flags: |
| 3932 | if flag not in expected_flags: |
| 3933 | expected_flags.append(flag) |
| 3934 | expected_flags.sort(key=id) |
| 3935 | |
| 3936 | # flags we actually got |
| 3937 | new_flags = [k for k,v in context.flags.items() if v] |
| 3938 | new_flags.sort(key=id) |
nothing calls this directly
no test coverage detected