Skip to content

Commit f14f449

Browse files
committed
Move tests into the flint module
1 parent a8563cf commit f14f449

File tree

9 files changed

+157
-64
lines changed

9 files changed

+157
-64
lines changed

.github/workflows/buildwheel.yml

+3-27
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,6 @@ jobs:
6868
python-version: ['3.9', '3.10', '3.11']
6969

7070
steps:
71-
- uses: actions/checkout@v3
72-
- uses: actions/setup-python@v4
73-
with:
74-
python-version: ${{ matrix.python-version }}
75-
- uses: actions/download-artifact@v3
76-
with:
77-
name: artifact
78-
path: wheelhouse
79-
- run: pip install --find-links wheelhouse python_flint
80-
- run: python test/test.py
81-
82-
doctest_wheels:
83-
needs: build_wheels
84-
name: Doctests for ${{ matrix.python-version }} wheel on ${{ matrix.os }}
85-
runs-on: ${{ matrix.os }}
86-
strategy:
87-
fail-fast: false
88-
matrix:
89-
os: [ubuntu-20.04, windows-2019, macos-12]
90-
python-version: ['3.9', '3.10', '3.11']
91-
92-
steps:
93-
- uses: actions/checkout@v3
9471
- uses: actions/setup-python@v4
9572
with:
9673
python-version: ${{ matrix.python-version }}
@@ -99,7 +76,7 @@ jobs:
9976
name: artifact
10077
path: wheelhouse
10178
- run: pip install --find-links wheelhouse python_flint
102-
- run: python test/dtest.py
79+
- run: python -m flint.test --verbose
10380

10481
test_pip_linux_vcs:
10582
name: Install from git checkout on Ubuntu
@@ -110,8 +87,7 @@ jobs:
11087
with:
11188
python-version: 3.11
11289
- run: bin/pip_install_ubuntu.sh . # Install from checkout
113-
- run: python test/test.py
114-
- run: python test/dtest.py
90+
- run: python -m flint.test --verbose
11591

11692
test_pip_linux_pypi:
11793
name: Install from PyPI sdist on Ubuntu
@@ -123,4 +99,4 @@ jobs:
12399
python-version: 3.11
124100
- run: bin/pip_install_ubuntu.sh python-flint # Install from PyPI sdist
125101
- run: python test/test.py
126-
- run: python test/dtest.py
102+
- run: python -m flint.test --verbose

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ install:
2828
- pip install .
2929

3030
script:
31-
- python test/test.py
31+
- python -m flint.test

bin/cibw.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export CIBW_BEFORE_BUILD_WINDOWS='C:\\msys64\\usr\\bin\\bash bin/cibw_before_bui
2929
export CIBW_REPAIR_WHEEL_COMMAND_WINDOWS='bin\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}'
3030

3131
# export CIBW_TEST_COMMAND="python -c 'import flint; print(str(flint.fmpz(2)))'"
32-
export CIBW_TEST_COMMAND="python {project}/test/test.py && python {project}/test/dtest.py"
32+
export CIBW_TEST_COMMAND="python -m flint.test"
3333

3434
# cibuildwheel --platform linux
3535
# cibuildwheel --platform windows

bin/coverage.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export PYTHON_FLINT_COVERAGE=true
3333

3434
python setup.py build_ext --inplace
3535

36-
pytest --cov flint test/test.py
37-
coverage run --append test/dtest.py
36+
coverage run -m flint.test $@
3837

3938
#coverage report -m
4039
coverage html

doc/source/setup.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ Then run::
4242

4343
Run the test suite::
4444

45-
python test/test.py
46-
python test/dtest.py
45+
python -m flint.test
4746

4847
Build the documentation::
4948

@@ -86,8 +85,7 @@ you can then build Python-FLINT in place with::
8685

8786
and run the test suite with::
8887

89-
python test/test.py
90-
python test/dtest.py
88+
python -m flint.test
9189

9290
This way of building Python-FLINT depends on the ``bin/activate`` script to
9391
locate the shared libraries at runtime. The script will also set ``PYTHONPATH``

src/flint/test/__init__.py

Whitespace-only changes.

src/flint/test/__main__.py

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#
2+
# Run the python-flint test-suite as
3+
#
4+
# python -m flint.test
5+
#
6+
7+
import sys
8+
import doctest
9+
import traceback
10+
import argparse
11+
12+
import flint
13+
from flint.test.test import all_tests
14+
15+
16+
def run_tests(verbose=None):
17+
"""Run all tests
18+
19+
This is usually called by
20+
21+
$ python -m flint.flint
22+
"""
23+
# Show the limited output by default
24+
if verbose is None:
25+
verbose = True
26+
27+
total = 0
28+
failed = 0
29+
30+
for test in all_tests:
31+
32+
if verbose:
33+
print(f'{test.__name__}...', end='', flush=True)
34+
35+
try:
36+
test()
37+
except Exception as e:
38+
print(f'Error in {test.__name__}')
39+
if verbose:
40+
traceback.print_exc()
41+
failed += 1
42+
else:
43+
if verbose:
44+
print('OK')
45+
46+
total += 1
47+
48+
return failed, total
49+
50+
51+
def run_doctests(verbose=None):
52+
"""Run the python-flint doctests"""
53+
# Here verbose=True shows a lot of output.
54+
failed, total = doctest.testmod(flint._flint, verbose=verbose)
55+
return failed, total
56+
57+
58+
def run_all_tests(tests=True, doctests=True, verbose=None):
59+
60+
success = True
61+
62+
if tests:
63+
print("Running tests...")
64+
t_failed, t_total = run_tests(verbose=verbose)
65+
66+
if doctests:
67+
print("Running doctests...")
68+
d_failed, d_total = run_doctests(verbose=verbose)
69+
70+
if tests:
71+
if t_failed:
72+
print(f'flint.test: {t_failed} of {t_total} tests failed')
73+
success = False
74+
else:
75+
print(f'flint.test: all {t_total} tests passed!')
76+
77+
if doctests:
78+
if d_failed:
79+
print(f'flint.test: {d_failed} of {d_total} doctests failed')
80+
success = False
81+
else:
82+
print(f'flint.test: all {d_total} doctests passed!')
83+
84+
return success
85+
86+
87+
def main(*args):
88+
"""Run the python-flint test-suite"""
89+
90+
parser = argparse.ArgumentParser(description="Run the python-flint test-suite")
91+
parser.add_argument("--quiet", "-q", action="store_true", help="less verbose output")
92+
parser.add_argument("--verbose", "-v", action="store_true", help="more verbose output")
93+
parser.add_argument("--tests", "-t", action="store_true", help="run tests")
94+
parser.add_argument("--doctests", "-d", action="store_true", help="run doctests")
95+
args = parser.parse_args(args)
96+
97+
if not args.tests and not args.doctests:
98+
# Default is run all tests:
99+
tests = True
100+
doctests = True
101+
else:
102+
# Either --tests or --doctests was specified
103+
tests = args.tests
104+
doctests = args.doctests
105+
106+
# Default is show output from tests but keep the doctests quiet.
107+
if args.verbose:
108+
verbose = True
109+
elif args.quiet:
110+
verbose = False
111+
else:
112+
verbose = None
113+
114+
success = run_all_tests(tests=tests, doctests=doctests, verbose=verbose)
115+
116+
if not success:
117+
print("----------------------------------------")
118+
print("!!!FAILED!!!: Something is wrong with your installation of python-flint!")
119+
print("----------------------------------------")
120+
return 1
121+
else:
122+
print("----------------------------------------")
123+
print("OK: Your installation of python-flint seems to be working just fine!")
124+
print("----------------------------------------")
125+
return 0
126+
127+
128+
if __name__ == "__main__":
129+
sys.exit(main(*sys.argv[1:]))

test/test.py renamed to src/flint/test/test.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -1558,22 +1558,23 @@ def test_pickling():
15581558
obj2 = pickle.loads(s)
15591559
assert obj == obj2
15601560

1561-
if __name__ == "__main__":
1562-
sys.stdout.write("test_pyflint..."); test_pyflint(); print("OK")
1563-
sys.stdout.write("test_fmpz..."); test_fmpz(); print("OK")
1564-
sys.stdout.write("test_fmpz_factor..."); test_fmpz_factor(); print("OK")
1565-
sys.stdout.write("test_fmpz_functions..."); test_fmpz_functions(); print("OK")
1566-
sys.stdout.write("test_fmpz_poly..."); test_fmpz_poly(); print("OK")
1567-
sys.stdout.write("test_fmpz_poly_factor..."); test_fmpz_poly_factor(); print("OK")
1568-
sys.stdout.write("test_fmpz_poly_functions..."); test_fmpz_poly_functions(); print("OK")
1569-
sys.stdout.write("test_fmpz_mat..."); test_fmpz_mat(); print("OK")
1570-
sys.stdout.write("test_fmpz_series..."); test_fmpz_series(); print("OK")
1571-
sys.stdout.write("test_fmpq..."); test_fmpq(); print("OK")
1572-
sys.stdout.write("test_fmpq_poly..."); test_fmpq_poly(); print("OK")
1573-
sys.stdout.write("test_fmpq_mat..."); test_fmpq_mat(); print("OK")
1574-
sys.stdout.write("test_fmpq_series..."); test_fmpq_series(); print("OK")
1575-
sys.stdout.write("test_nmod..."); test_nmod(); print("OK")
1576-
sys.stdout.write("test_nmod_poly..."); test_nmod_poly(); print("OK")
1577-
sys.stdout.write("test_nmod_mat..."); test_nmod_mat(); print("OK")
1578-
sys.stdout.write("test_arb.."); test_arb(); print("OK")
1579-
print("OK")
1561+
1562+
all_tests = [
1563+
test_pyflint,
1564+
test_fmpz,
1565+
test_fmpz_factor,
1566+
test_fmpz_functions,
1567+
test_fmpz_poly,
1568+
test_fmpz_poly_factor,
1569+
test_fmpz_poly_functions,
1570+
test_fmpz_mat,
1571+
test_fmpz_series,
1572+
test_fmpq,
1573+
test_fmpq_poly,
1574+
test_fmpq_mat,
1575+
test_fmpq_series,
1576+
test_nmod,
1577+
test_nmod_poly,
1578+
test_nmod_mat,
1579+
test_arb,
1580+
]

test/dtest.py

-10
This file was deleted.

0 commit comments

Comments
 (0)