From 441ee05163a9071ad119d7b4eed9c8a35d371668 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 6 Oct 2024 08:48:12 -0400 Subject: [PATCH] src/sage/libs/mpmath/ext_main.pyx: fix two repr tests with clone() There are two tests in this file that are attempting to test the repr() of an mpmath number with mp.pretty=True set globally. The shared state is causing test failures, but we can't simply leave it off, because that's the point of the test. Instead we can clone() the "mp" object to obtain a new one (whose state is not so global) and then work with that instead. --- src/sage/libs/mpmath/ext_main.pyx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/sage/libs/mpmath/ext_main.pyx b/src/sage/libs/mpmath/ext_main.pyx index 0ac92485aba..96111f7b942 100644 --- a/src/sage/libs/mpmath/ext_main.pyx +++ b/src/sage/libs/mpmath/ext_main.pyx @@ -2201,12 +2201,13 @@ cdef class constant(mpf_base): Represent ``self`` as a string. With mp.pretty=False, the representation differs from that of an ordinary mpf:: - sage: from mpmath import mp, pi - sage: mp.pretty = True - sage: repr(pi) + sage: from mpmath import mp + sage: mp2 = mp.clone() + sage: mp2.pretty = True + sage: repr(mp2.pi) '3.14159265358979' - sage: mp.pretty = False - sage: repr(pi) + sage: mp2.pretty = False + sage: repr(mp2.pi) '' """ if global_context.pretty: @@ -2372,11 +2373,12 @@ cdef class mpc(mpnumber): TESTS:: sage: from mpmath import mp - sage: mp.pretty = True - sage: repr(mp.mpc(2,3)) + sage: mp2 = mp.clone() + sage: mp2.pretty = True + sage: repr(mp2.mpc(2,3)) '(2.0 + 3.0j)' - sage: mp.pretty = False - sage: repr(mp.mpc(2,3)) + sage: mp2.pretty = False + sage: repr(mp2.mpc(2,3)) "mpc(real='2.0', imag='3.0')" """ if global_context.pretty: