|
5 | 5 |
|
6 | 6 | import flint |
7 | 7 |
|
8 | | -dunder_test_regex = re.compile(r'^(.*?)__test__\.(.*?\.)(.*) \(line (\d+)\)$') |
| 8 | +dunder_test_regex = re.compile(r'^(.*?)__test__\.(.*?) \(line (\d+)\)$') |
9 | 9 |
|
10 | 10 | test_flint_at_least = { |
11 | 11 | "flint.types._gr.gr_ctx.gens": 30100, |
12 | 12 | "flint.types._gr.gr_ctx.neg": 30100, |
| 13 | + "flint.types.acb_theta.acb_theta": 30300, |
13 | 14 | } |
14 | 15 |
|
15 | 16 |
|
16 | 17 | def find_doctests(module): |
17 | 18 | finder = doctest.DocTestFinder() |
18 | 19 | tests = [] |
| 20 | + tests_seen = set() |
19 | 21 | for module_info in pkgutil.walk_packages(module.__path__, flint.__name__ + "."): |
20 | 22 | try: |
21 | 23 | module = importlib.import_module(module_info.name) |
22 | 24 |
|
23 | 25 | res = [] |
24 | 26 | for test in filter(lambda x: bool(x.examples), finder.find(module)): |
| 27 | + |
25 | 28 | m = dunder_test_regex.match(test.name) |
26 | 29 | if m is not None: |
27 | 30 | groups = m.groups() |
28 | | - test.name = groups[0] + groups[2] |
29 | | - test.lineno = int(groups[3]) |
30 | | - |
31 | | - if ( |
32 | | - test_flint_at_least.get("".join(groups[:3]), flint.__FLINT_RELEASE__) |
33 | | - <= flint.__FLINT_RELEASE__ |
34 | | - ): |
35 | | - res.append(test) |
| 31 | + test.name = groups[0] + groups[1] |
| 32 | + test.lineno = int(groups[2]) |
| 33 | + |
| 34 | + # Prefer the __test__ version of the test (remove the other) |
| 35 | + if test.name in tests_seen: |
| 36 | + n = len(res) |
| 37 | + res = [r for r in res if r.name != test.name] |
| 38 | + if len(res) != n - 1: |
| 39 | + raise Exception(f"Duplicate test name: {test.name}") |
| 40 | + tests_seen.remove(test.name) |
| 41 | + |
| 42 | + # Doctests that fail without latest flint |
| 43 | + if test.name in test_flint_at_least: |
| 44 | + if test_flint_at_least[test.name] > flint.__FLINT_RELEASE__: |
| 45 | + continue |
| 46 | + |
| 47 | + if test.name not in tests_seen: |
| 48 | + tests_seen.add(test.name) |
| 49 | + res.append(test) |
36 | 50 |
|
37 | 51 | tests.append((module_info.name, res)) |
38 | 52 |
|
|
0 commit comments