summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_domain_py.py13
-rw-r--r--tests/test_pycode_ast.py14
2 files changed, 22 insertions, 5 deletions
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py
index b98f37912..8040af9cc 100644
--- a/tests/test_domain_py.py
+++ b/tests/test_domain_py.py
@@ -386,6 +386,19 @@ def test_pyfunction_signature_full_py38(app):
[desc_parameter, desc_sig_operator, "/"])])
+@pytest.mark.skipif(sys.version_info < (3, 8), reason='python 3.8+ is required.')
+def test_pyfunction_with_number_literals(app):
+ text = ".. py:function:: hello(age=0x10, height=1_6_0)"
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree[1][0][1],
+ [desc_parameterlist, ([desc_parameter, ([desc_sig_name, "age"],
+ [desc_sig_operator, "="],
+ [nodes.inline, "0x10"])],
+ [desc_parameter, ([desc_sig_name, "height"],
+ [desc_sig_operator, "="],
+ [nodes.inline, "1_6_0"])])])
+
+
def test_optional_pyfunction_signature(app):
text = ".. py:function:: compile(source [, filename [, symbol]]) -> ast object"
doctree = restructuredtext.parse(app, text)
diff --git a/tests/test_pycode_ast.py b/tests/test_pycode_ast.py
index 32a784b74..bbff64dd0 100644
--- a/tests/test_pycode_ast.py
+++ b/tests/test_pycode_ast.py
@@ -58,7 +58,7 @@ from sphinx.pycode import ast
])
def test_unparse(source, expected):
module = ast.parse(source)
- assert ast.unparse(module.body[0].value) == expected
+ assert ast.unparse(module.body[0].value, source) == expected
def test_unparse_None():
@@ -66,8 +66,12 @@ def test_unparse_None():
@pytest.mark.skipif(sys.version_info < (3, 8), reason='python 3.8+ is required.')
-def test_unparse_py38():
- source = "lambda x=0, /, y=1, *args, z, **kwargs: x + y + z"
- expected = "lambda x=0, /, y=1, *args, z, **kwargs: ..."
+@pytest.mark.parametrize('source,expected', [
+ ("lambda x=0, /, y=1, *args, z, **kwargs: x + y + z",
+ "lambda x=0, /, y=1, *args, z, **kwargs: ..."), # posonlyargs
+ ("0x1234", "0x1234"), # Constant
+ ("1_000_000", "1_000_000"), # Constant
+])
+def test_unparse_py38(source, expected):
module = ast.parse(source)
- assert ast.unparse(module.body[0].value) == expected
+ assert ast.unparse(module.body[0].value, source) == expected