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

Method _remove_unwanted_precision

src/_pytest/doctest.py:635–657  ·  src/_pytest/doctest.py::LiteralsOutputChecker._remove_unwanted_precision
(self, want: str, got: str)

Source from the content-addressed store, hash-verified

633 return super().check_output(want, got, optionflags)
634
635 def _remove_unwanted_precision(self, want: str, got: str) -> str:
636 wants = list(self._number_re.finditer(want))
637 gots = list(self._number_re.finditer(got))
638 if len(wants) != len(gots):
639 return got
640 offset = 0
641 for w, g in zip(wants, gots, strict=True):
642 fraction: str | None = w.group(class="st">"fraction")
643 exponent: str | None = w.group(class="st">"exponent1")
644 if exponent is None:
645 exponent = w.group(class="st">"exponent2")
646 precision = 0 if fraction is None else len(fraction)
647 if exponent is not None:
648 precision -= int(exponent)
649 if float(w.group()) == approx(float(g.group()), abs=10**-precision):
650 class="cm"># They're close enough. Replace the text we actually
651 class="cm"># got with the text we want, so that it will match when we
652 class="cm"># check the string literally.
653 got = (
654 got[: g.start() + offset] + w.group() + got[g.end() + offset :]
655 )
656 offset += w.end() - w.start() - (g.end() - g.start())
657 return got
658
659 return LiteralsOutputChecker
660

Callers 1

check_outputMethod · 0.95

Calls 5

approxFunction · 0.90
intClass · 0.85
groupMethod · 0.80
endMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected