diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-19 22:47:02 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-19 22:47:02 +0900 |
commit | 347e301727c3b2b08e277b0d8a72c33a1eba13d8 (patch) | |
tree | 8b0c32ac6d5bd84ce4a8746eff3ef54acec93830 /tests/test_pycode_ast.py | |
parent | ad271f4ca33d298a880da8fdc75cc318b4a7842f (diff) | |
parent | eb273fdc08840945b9c2419f20fb2e0220b0a004 (diff) | |
download | sphinx-git-347e301727c3b2b08e277b0d8a72c33a1eba13d8.tar.gz |
Merge branch '2.0'
Diffstat (limited to 'tests/test_pycode_ast.py')
-rw-r--r-- | tests/test_pycode_ast.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_pycode_ast.py b/tests/test_pycode_ast.py new file mode 100644 index 000000000..af7e34a86 --- /dev/null +++ b/tests/test_pycode_ast.py @@ -0,0 +1,40 @@ +""" + test_pycode_ast + ~~~~~~~~~~~~~~~ + + Test pycode.ast + + :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest + +from sphinx.pycode import ast + + +@pytest.mark.parametrize('source,expected', [ + ("os.path", "os.path"), # Attribute + ("b'bytes'", "b'bytes'"), # Bytes + ("object()", "object()"), # Call + ("1234", "1234"), # Constant + ("{'key1': 'value1', 'key2': 'value2'}", + "{'key1': 'value1', 'key2': 'value2'}"), # Dict + ("...", "..."), # Ellipsis + ("Tuple[int, int]", "Tuple[int, int]"), # Index, Subscript + ("lambda x, y: x + y", + "<function <lambda>>"), # Lambda + ("[1, 2, 3]", "[1, 2, 3]"), # List + ("sys", "sys"), # Name, NameConstant + ("1234", "1234"), # Num + ("{1, 2, 3}", "{1, 2, 3}"), # Set + ("'str'", "'str'"), # Str + ("(1, 2, 3)", "1, 2, 3"), # Tuple +]) +def test_unparse(source, expected): + module = ast.parse(source) + assert ast.unparse(module.body[0].value) == expected + + +def test_unparse_None(): + assert ast.unparse(None) is None |