Skip to content

Commit 441ee05

Browse files
committed
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.
1 parent b918a1c commit 441ee05

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/sage/libs/mpmath/ext_main.pyx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,12 +2201,13 @@ cdef class constant(mpf_base):
22012201
Represent ``self`` as a string. With mp.pretty=False, the
22022202
representation differs from that of an ordinary mpf::
22032203
2204-
sage: from mpmath import mp, pi
2205-
sage: mp.pretty = True
2206-
sage: repr(pi)
2204+
sage: from mpmath import mp
2205+
sage: mp2 = mp.clone()
2206+
sage: mp2.pretty = True
2207+
sage: repr(mp2.pi)
22072208
'3.14159265358979'
2208-
sage: mp.pretty = False
2209-
sage: repr(pi)
2209+
sage: mp2.pretty = False
2210+
sage: repr(mp2.pi)
22102211
'<pi: 3.14159~>'
22112212
"""
22122213
if global_context.pretty:
@@ -2372,11 +2373,12 @@ cdef class mpc(mpnumber):
23722373
TESTS::
23732374
23742375
sage: from mpmath import mp
2375-
sage: mp.pretty = True
2376-
sage: repr(mp.mpc(2,3))
2376+
sage: mp2 = mp.clone()
2377+
sage: mp2.pretty = True
2378+
sage: repr(mp2.mpc(2,3))
23772379
'(2.0 + 3.0j)'
2378-
sage: mp.pretty = False
2379-
sage: repr(mp.mpc(2,3))
2380+
sage: mp2.pretty = False
2381+
sage: repr(mp2.mpc(2,3))
23802382
"mpc(real='2.0', imag='3.0')"
23812383
"""
23822384
if global_context.pretty:

0 commit comments

Comments
 (0)