MCPcopy
hub / github.com/pytest-dev/pytest / ApproxDecimal

Class ApproxDecimal

src/_pytest/python_api.py:540–563  ·  view source on GitHub ↗

Perform approximate comparisons where the expected value is a Decimal.

Source from the content-addressed store, hash-verified

538
539
540class ApproxDecimal(ApproxScalar):
541 """Perform approximate comparisons where the expected value is a Decimal."""
542
543 DEFAULT_ABSOLUTE_TOLERANCE = Decimal("1e-12")
544 DEFAULT_RELATIVE_TOLERANCE = Decimal("1e-6")
545
546 def __repr__(self) -> str:
547 if isinstance(self.rel, float):
548 rel = Decimal.from_float(self.rel)
549 else:
550 rel = self.rel
551
552 if isinstance(self.abs, float):
553 abs_ = Decimal.from_float(self.abs)
554 else:
555 abs_ = self.abs
556
557 tol_str = "???"
558 if rel is not None and Decimal("1e-3") <= rel <= Decimal("1e3"):
559 tol_str = f"{rel:.1e}"
560 elif abs_ is not None:
561 tol_str = f"{abs_:.1e}"
562
563 return f"{self.expected} ± {tol_str}"
564
565
566class ApproxTimedelta(ApproxBase):

Callers 1

_approx_scalarMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected