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