from math import isnan
from uuid import UUID
from random import choice, random, randrange
+from decimal import Decimal
from collections import deque
import pytest
length = randrange(self.str_max_length)
return spec(bytes([randrange(256) for i in range(length)]))
+ def make_Decimal(self, spec):
+ if random() >= 0.99:
+ if self.conn.info.server_version >= 140000:
+ return Decimal(choice(["NaN", "Inf", "-Inf"]))
+ else:
+ return Decimal("NaN")
+
+ sign = choice("+-")
+ num = choice(["0.zd", "d", "d.d"])
+ while "z" in num:
+ ndigits = randrange(1, 20)
+ num = num.replace("z", "0" * ndigits, 1)
+ while "d" in num:
+ ndigits = randrange(1, 20)
+ num = num.replace(
+ "d", "".join([str(randrange(10)) for i in range(ndigits)]), 1
+ )
+ expsign = choice(["e+", "e-", ""])
+ exp = randrange(20) if expsign else ""
+ rv = Decimal(f"{sign}{num}{expsign}{exp}")
+ return rv
+
+ def match_Decimal(self, spec, got, want):
+ if got is not None and got.is_nan():
+ assert want.is_nan()
+ else:
+ assert got == want
+
def make_float(self, spec):
if random() <= 0.99:
# this exponent should generate no inf