mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add tests
Signed-off-by: Ray Lehtiniemi <rayl@mail.com>
This commit is contained in:
parent
c5060079e4
commit
06b6e07b98
16
tests/roots/test-directive-code/py-decorators.inc
Normal file
16
tests/roots/test-directive-code/py-decorators.inc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Literally included file using Python highlighting
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
@class_decorator
|
||||||
|
@other_decorator()
|
||||||
|
class TheClass(object):
|
||||||
|
|
||||||
|
@method_decorator
|
||||||
|
@other_decorator()
|
||||||
|
def the_method():
|
||||||
|
pass
|
||||||
|
|
||||||
|
@function_decorator
|
||||||
|
@other_decorator()
|
||||||
|
def the_function():
|
||||||
|
pass
|
17
tests/roots/test-directive-code/py-decorators.rst
Normal file
17
tests/roots/test-directive-code/py-decorators.rst
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
py-decorators
|
||||||
|
=============
|
||||||
|
|
||||||
|
Various decorators
|
||||||
|
------------------
|
||||||
|
|
||||||
|
.. literalinclude:: py-decorators.inc
|
||||||
|
:name: literal_include_pydecorators_1
|
||||||
|
:pyobject: TheClass
|
||||||
|
|
||||||
|
.. literalinclude:: py-decorators.inc
|
||||||
|
:name: literal_include_pydecorators_2
|
||||||
|
:pyobject: TheClass.the_method
|
||||||
|
|
||||||
|
.. literalinclude:: py-decorators.inc
|
||||||
|
:name: literal_include_pydecorators_3
|
||||||
|
:pyobject: the_function
|
@ -454,3 +454,45 @@ def test_literalinclude_classes(app, status, warning):
|
|||||||
assert len(literalinclude) > 0
|
assert len(literalinclude) > 0
|
||||||
assert 'bar baz' == literalinclude[0].get('classes')
|
assert 'bar baz' == literalinclude[0].get('classes')
|
||||||
assert 'literal_include' == literalinclude[0].get('names')
|
assert 'literal_include' == literalinclude[0].get('names')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('xml', testroot='directive-code')
|
||||||
|
def test_literalinclude_pydecorators(app, status, warning):
|
||||||
|
app.builder.build(['py-decorators'])
|
||||||
|
et = etree_parse(app.outdir / 'py-decorators.xml')
|
||||||
|
secs = et.findall('./section/section')
|
||||||
|
|
||||||
|
literal_include = secs[0].findall('literal_block')
|
||||||
|
assert len(literal_include) == 3
|
||||||
|
|
||||||
|
actual = literal_include[0].text
|
||||||
|
expect = (
|
||||||
|
'@class_decorator\n'
|
||||||
|
'@other_decorator()\n'
|
||||||
|
'class TheClass(object):\n'
|
||||||
|
'\n'
|
||||||
|
' @method_decorator\n'
|
||||||
|
' @other_decorator()\n'
|
||||||
|
' def the_method():\n'
|
||||||
|
' pass\n'
|
||||||
|
)
|
||||||
|
assert actual == expect
|
||||||
|
|
||||||
|
actual = literal_include[1].text
|
||||||
|
expect = (
|
||||||
|
' @method_decorator\n'
|
||||||
|
' @other_decorator()\n'
|
||||||
|
' def the_method():\n'
|
||||||
|
' pass\n'
|
||||||
|
)
|
||||||
|
assert actual == expect
|
||||||
|
|
||||||
|
actual = literal_include[2].text
|
||||||
|
expect = (
|
||||||
|
'@function_decorator\n'
|
||||||
|
'@other_decorator()\n'
|
||||||
|
'def the_function():\n'
|
||||||
|
' pass\n'
|
||||||
|
)
|
||||||
|
assert actual == expect
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user