Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failures due to global mpmath state #38776

Merged
merged 4 commits into from
Oct 12, 2024

Commits on Oct 6, 2024

  1. src/sage/functions/orthogonal_polys.py: avoid global state in doctests

    We have an mpmath test in this file that sets the global precision
    (decimal places) and "pretty" variable for all of mpmath. Instead it
    is safer to use a context manager for the precision, and to call
    print(foo) to obtain the string representation of foo. This fixes
    the following two test failures:
    
      Failed example:
        gegenbauer_mp(-7,0.5,0.3)
      Expected:
        0.1291811875
      Got:
        mpf('0.1291811874999999999999999952')
    
    and
    
      Failed example:
        gegenbauer_mp(2+3j, -0.75, -1000j)
      Expected:
        (-5038991.358609026523401901 + 9414549.285447104177860806j)
      Got:
        mpc(real='-5038991.358609026523401901035', imag='9414549.285447104177860806274')
    orlitzky committed Oct 6, 2024
    Configuration menu
    Copy the full SHA
    ddbae0e View commit details
    Browse the repository at this point in the history
  2. src/sage/libs/mpmath/ext_main.pyx: disable pretty printing for a test

    One test in this file sets mp.pretty=True but is failing for me, most
    likely due to the shared state inherent to mp.pretty. Since this test
    is inside a TESTS block and not visible to end users, the simplest way
    to fix it is to delete the mp.pretty=True and to look for the ugly
    output.
    orlitzky committed Oct 6, 2024
    Configuration menu
    Copy the full SHA
    980411c View commit details
    Browse the repository at this point in the history
  3. src/sage/libs/mpmath/ext_main.pyx: handle ugly mpmath output

    There's a test in this file that is trying to use the global property
    mp.pretty=True but is failing on my machine. Since the test is inside
    a TESTS block and not visible to end users, the simplest way to fix it
    is to expect the ugly output from mpmath; although in one instance we
    do call str() on an mpmath real number to obtain '2.3' instead of some
    2.999... thing that would require a tolerance.
    orlitzky committed Oct 6, 2024
    Configuration menu
    Copy the full SHA
    b918a1c View commit details
    Browse the repository at this point in the history
  4. 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.
    orlitzky committed Oct 6, 2024
    Configuration menu
    Copy the full SHA
    441ee05 View commit details
    Browse the repository at this point in the history