Skip to content

Commit a686ec4

Browse files
author
Release Manager
committed
gh-40443: Run function field TestSuites via pytest * Fix two slow doctest warnings in the CI by moving these tests to pytest. * Speed some test suites up by using fewer repeated runs. Nowadays we run the tests on every PR, so repeated runs within repeated runs are less valuable. * Use `QQ` instead of `QQbar` for some tests where this was the original intention. * Clean up the docs by eliminating pure-test code from the docstrings. URL: #40443 Reported by: Michael Orlitzky Reviewer(s): Tobias Diez
2 parents 2d2b52f + b9e65d1 commit a686ec4

File tree

3 files changed

+124
-17
lines changed

3 files changed

+124
-17
lines changed

src/sage/rings/function_field/function_field.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,6 @@
122122
sage: m(y)^2 + m(y) + m(x) + 1/m(x) # long time (8s)
123123
O(s^5)
124124
125-
TESTS::
126-
127-
sage: TestSuite(J).run()
128-
sage: TestSuite(K).run(max_runs=256) # long time (10s) # needs sage.rings.function_field sage.rings.number_field
129-
sage: TestSuite(L).run(max_runs=8) # long time (25s) # needs sage.rings.function_field sage.rings.number_field
130-
131-
sage: # needs sage.rings.finite_rings sage.rings.function_field
132-
sage: TestSuite(M).run(max_runs=8) # long time (35s)
133-
sage: TestSuite(N).run(max_runs=8, skip='_test_derivation') # long time (15s)
134-
sage: TestSuite(O).run()
135-
sage: TestSuite(R).run()
136-
sage: TestSuite(S).run() # long time (4s)
137-
138125
Global function fields
139126
----------------------
140127
@@ -301,10 +288,12 @@ def __init__(self, base_field, names, category=FunctionFields()):
301288
"""
302289
Initialize.
303290
304-
TESTS::
291+
EXAMPLES::
292+
293+
sage: K = FunctionField(QQ, 'z')
294+
sage: K
295+
Rational function field in z over Rational Field
305296
306-
sage: K.<x> = FunctionField(QQ)
307-
sage: TestSuite(K).run() # long time (3s)
308297
"""
309298
Field.__init__(self, base_field, names=names, category=category)
310299

@@ -747,7 +736,8 @@ def _test_derivation(self, **options):
747736
EXAMPLES::
748737
749738
sage: K.<x> = FunctionField(QQ)
750-
sage: TestSuite(K).run() # indirect doctest, long time (3s)
739+
sage: K._test_derivation() # long time
740+
751741
"""
752742
tester = self._tester(**options)
753743
S = tester.some_elements()
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import pytest
2+
3+
from sage.rings.finite_rings.finite_field_constructor import FiniteField
4+
from sage.rings.function_field.constructor import FunctionField
5+
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
6+
from sage.rings.rational_field import QQ
7+
8+
9+
@pytest.fixture
10+
def F():
11+
return FunctionField(QQ, 'x')
12+
13+
14+
@pytest.fixture
15+
def J():
16+
return FunctionField(FiniteField(5), 'x')
17+
18+
19+
@pytest.fixture
20+
def K():
21+
return FunctionField(FiniteField(5**2,'a'), 'x')
22+
23+
24+
@pytest.fixture
25+
def L(F):
26+
x = F.gen()
27+
Y = PolynomialRing(F, 'Y').gen()
28+
return F.extension(Y**2 + Y + x + 1/x, 'y')
29+
30+
31+
@pytest.fixture
32+
def M(K, R, S):
33+
x = K.gen()
34+
y = R.gen()
35+
L = K.extension(y**3 - (x**3 + 2*x*y + 1/x))
36+
t = S.gen()
37+
return L.extension(t**2 - x*y)
38+
39+
40+
@pytest.fixture
41+
def N(K):
42+
return FunctionField(K, 'u')
43+
44+
45+
@pytest.fixture
46+
def O(L):
47+
return L.maximal_order()
48+
49+
50+
@pytest.fixture
51+
def R(K):
52+
return PolynomialRing(K, 'y')
53+
54+
55+
@pytest.fixture
56+
def S(K, R):
57+
x = K.gen()
58+
y = R.gen()
59+
L = K.extension(y**3 - (x**3 + 2*x*y + 1/x))
60+
return PolynomialRing(L, 't')
61+
62+
63+
@pytest.fixture
64+
def T(F):
65+
return PolynomialRing(F, 'Y')
66+
67+
68+
# Use strings for the fixture names here, and then later convert them
69+
# to the actual fixture objects using request.getfixturevalue(). This
70+
# is a workaround for being unable to pass fixtures directly as
71+
# parameters:
72+
#
73+
# https://github.com/pytest-dev/pytest/issues/349
74+
#
75+
pairs = [ ("J", None),
76+
("K", 16),
77+
("L", 2),
78+
("M", 1),
79+
("N", 1),
80+
("O", None),
81+
("T", None),
82+
("S", 8) ]
83+
84+
85+
@pytest.mark.parametrize("ff,max_runs", pairs)
86+
def test_function_field_testsuite(ff, max_runs, request):
87+
r"""
88+
Run the TestSuite() on some function fields that are
89+
constructed in the documentation. They are slow, random, and not
90+
intended for end users. All of this makes them more appropriate to
91+
be run separately, here, than in the doctests.
92+
93+
INPUT:
94+
95+
The inputs are essentially all fixtures.
96+
97+
- ``ff`` -- string; a function field fixture name
98+
- ``max_runs`` -- integer; the maxmimum number of times to
99+
repeat the test suite
100+
- ``request`` -- fixture; a pytest built-in
101+
102+
"""
103+
# The sage.misc.sage_unittest.TestSuite import is local to avoid
104+
# pytest warnings.
105+
from sage.misc.sage_unittest import TestSuite
106+
107+
# Convert the fixture name (string) to an actual object using the
108+
# built-in "request" fixture.
109+
ff = request.getfixturevalue(ff)
110+
111+
# Pass max_runs only if it's not None; otherwise use the default
112+
run_args = { "verbose": True, "raise_on_failure": True }
113+
if max_runs:
114+
run_args["max_runs"] = max_runs
115+
116+
TestSuite(ff).run(**run_args)

src/sage/rings/function_field/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ py.install_sources(
1212
'function_field.py',
1313
'function_field_polymod.py',
1414
'function_field_rational.py',
15+
'function_field_test.py',
1516
'ideal.py',
1617
'ideal_polymod.py',
1718
'ideal_rational.py',

0 commit comments

Comments
 (0)