-
Notifications
You must be signed in to change notification settings - Fork 27
/
__main__.py
172 lines (140 loc) · 4.75 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#
# Run the python-flint test-suite as
#
# python -m flint.test
#
import sys
import doctest
import traceback
import argparse
import flint
from flint.test.test_all import all_tests
def run_tests(verbose=None):
"""Run all tests
This is usually called by
$ python -m flint.flint
"""
# Show the limited output by default
if verbose is None:
verbose = True
total = 0
failed = 0
for test in all_tests:
if verbose:
print(f'{test.__name__}...', end='', flush=True)
try:
test()
except Exception as e:
print(f'Error in {test.__name__}')
if verbose:
traceback.print_exc()
failed += 1
else:
if verbose:
print('OK')
total += 1
return failed, total
def run_doctests(verbose=None):
"""Run the python-flint doctests"""
# Here verbose=True shows a lot of output.
modules = [flint.pyflint,
flint.flint_base.flint_base,
flint.flint_base.flint_context,
flint.types.fmpz,
flint.types.fmpz_poly,
flint.types.fmpz_mat,
flint.types.fmpz_mpoly,
flint.types.fmpz_series,
flint.types.fmpz_mod,
flint.types.fmpz_mod_poly,
flint.types.fmpz_mod_mat,
flint.types.fmpq,
flint.types.fmpq_poly,
flint.types.fmpq_mat,
flint.types.fmpq_mpoly,
flint.types.fmpq_series,
flint.types.nmod,
flint.types.nmod_poly,
flint.types.nmod_mat,
flint.types.nmod_series,
flint.types.fq_default,
flint.types.fq_default_poly,
flint.types.arf,
flint.types.arb,
flint.types.arb_poly,
flint.types.arb_mat,
flint.types.arb_series,
flint.types.acb,
flint.types.acb_poly,
flint.types.acb_mat,
flint.types.acb_series,
flint.types.dirichlet,
flint.functions.showgood]
try:
from flint.types import acb_theta
modules.append(acb_theta)
except ImportError:
pass
results = []
for x in modules:
if verbose:
print(f" {x.__name__}")
results.append(doctest.testmod(x))
return tuple(sum(res) for res in zip(*results))
def run_all_tests(tests=True, doctests=True, verbose=None):
success = True
if tests:
print("Running tests...")
t_failed, t_total = run_tests(verbose=verbose)
if doctests:
print("Running doctests...")
d_failed, d_total = run_doctests(verbose=verbose)
if tests:
if t_failed:
print(f'flint.test: {t_failed} of {t_total} tests failed')
success = False
else:
print(f'flint.test: all {t_total} tests passed!')
if doctests:
if d_failed:
print(f'flint.test: {d_failed} of {d_total} doctests failed')
success = False
else:
print(f'flint.test: all {d_total} doctests passed!')
return success
def main(*args):
"""Run the python-flint test-suite"""
parser = argparse.ArgumentParser(description="Run the python-flint test-suite")
parser.add_argument("--quiet", "-q", action="store_true", help="less verbose output")
parser.add_argument("--verbose", "-v", action="store_true", help="more verbose output")
parser.add_argument("--tests", "-t", action="store_true", help="run tests")
parser.add_argument("--doctests", "-d", action="store_true", help="run doctests")
args = parser.parse_args(args)
if not args.tests and not args.doctests:
# Default is run all tests:
tests = True
doctests = True
else:
# Either --tests or --doctests was specified
tests = args.tests
doctests = args.doctests
# Default is show output from tests but keep the doctests quiet.
if args.verbose:
verbose = True
elif args.quiet:
verbose = False
else:
verbose = None
success = run_all_tests(tests=tests, doctests=doctests, verbose=verbose)
if not success:
print("----------------------------------------")
print("!!!FAILED!!!: Something is wrong with your installation of python-flint!")
print("----------------------------------------")
return 1
else:
print("----------------------------------------")
print("OK: Your installation of python-flint seems to be working just fine!")
print("----------------------------------------")
return 0
if __name__ == "__main__":
sys.exit(main(*sys.argv[1:]))