summaryrefslogtreecommitdiff
path: root/tests/test_pycode_parser.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-26 21:42:55 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-28 01:24:29 +0900
commit9c98b92c6a477c7a21fb6a70331f56fc20ae3e50 (patch)
tree497dc828c215e23e4508fdd878336a9c22937041 /tests/test_pycode_parser.py
parentf388114d10753a201b961a2b440601667da615d6 (diff)
downloadsphinx-git-9c98b92c6a477c7a21fb6a70331f56fc20ae3e50.tar.gz
pycode: Detect @final decorators
Diffstat (limited to 'tests/test_pycode_parser.py')
-rw-r--r--tests/test_pycode_parser.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_pycode_parser.py b/tests/test_pycode_parser.py
index 0bf505a33..398c9f8a4 100644
--- a/tests/test_pycode_parser.py
+++ b/tests/test_pycode_parser.py
@@ -374,3 +374,81 @@ def test_formfeed_char():
parser = Parser(source)
parser.parse()
assert parser.comments == {('Foo', 'attr'): 'comment'}
+
+
+def test_typing_final():
+ source = ('import typing\n'
+ '\n'
+ '@typing.final\n'
+ 'def func(): pass\n'
+ '\n'
+ '@typing.final\n'
+ 'class Foo:\n'
+ ' @typing.final\n'
+ ' def meth(self):\n'
+ ' pass\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.finals == ['func', 'Foo', 'Foo.meth']
+
+
+def test_typing_final_from_import():
+ source = ('from typing import final\n'
+ '\n'
+ '@final\n'
+ 'def func(): pass\n'
+ '\n'
+ '@final\n'
+ 'class Foo:\n'
+ ' @final\n'
+ ' def meth(self):\n'
+ ' pass\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.finals == ['func', 'Foo', 'Foo.meth']
+
+
+def test_typing_final_import_as():
+ source = ('import typing as foo\n'
+ '\n'
+ '@foo.final\n'
+ 'def func(): pass\n'
+ '\n'
+ '@foo.final\n'
+ 'class Foo:\n'
+ ' @typing.final\n'
+ ' def meth(self):\n'
+ ' pass\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.finals == ['func', 'Foo']
+
+
+def test_typing_final_from_import_as():
+ source = ('from typing import final as bar\n'
+ '\n'
+ '@bar\n'
+ 'def func(): pass\n'
+ '\n'
+ '@bar\n'
+ 'class Foo:\n'
+ ' @final\n'
+ ' def meth(self):\n'
+ ' pass\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.finals == ['func', 'Foo']
+
+
+def test_typing_final_not_imported():
+ source = ('@typing.final\n'
+ 'def func(): pass\n'
+ '\n'
+ '@typing.final\n'
+ 'class Foo:\n'
+ ' @final\n'
+ ' def meth(self):\n'
+ ' pass\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.finals == []