Skip to content

Commit

Permalink
src/sage/libs/mpmath/ext_main.pyx: fix two repr tests with clone()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
orlitzky committed Oct 6, 2024
1 parent b918a1c commit 441ee05
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/sage/libs/mpmath/ext_main.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'<pi: 3.14159~>'
"""
if global_context.pretty:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 441ee05

Please sign in to comment.