Skip to content

Commit 80b5235

Browse files
committed
Add API tests
Closes #253
1 parent cbe0b14 commit 80b5235

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/test_functions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import inspect
12
import math
3+
import platform
4+
import sys
25

36
import gmp
47
import pytest
@@ -236,3 +239,13 @@ def test_interfaces():
236239
with pytest.raises(ValueError, match="invalid rounding mode specified"):
237240
_mpmath_normalize(1, mpz(111), 11, 12, 13, 1j)
238241
gmp._free_cache() # just for coverage
242+
243+
244+
@pytest.mark.skipif(platform.python_implementation() != "CPython"
245+
or sys.version_info < (3, 11),
246+
reason="no way to specify a signature")
247+
def test_func_api():
248+
for fn in ["comb", "factorial", "gcd", "isqrt", "lcm", "perm"]:
249+
f = getattr(math, fn)
250+
fz = getattr(gmp, fn)
251+
assert inspect.signature(f) == inspect.signature(fz)

tests/test_mpz.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import cmath
2+
import inspect
23
import locale
34
import math
45
import operator
@@ -1032,3 +1033,15 @@ def f(n):
10321033
with ThreadPoolExecutor(max_workers=7) as tpe:
10331034
futures = [tpe.submit(f, mpz(x)) for x in xs]
10341035
assert all(f.result() == 1 for f in futures)
1036+
1037+
1038+
@pytest.mark.skipif(platform.python_implementation() != "CPython"
1039+
or sys.version_info < (3, 13),
1040+
reason="no way to specify a signature")
1041+
def test_int_api():
1042+
for meth in dir(int):
1043+
m = getattr(int, meth)
1044+
if meth.startswith("_") or not callable(m):
1045+
continue
1046+
mz = getattr(mpz, meth)
1047+
assert inspect.signature(m) == inspect.signature(mz)

0 commit comments

Comments
 (0)