Add tests

Signed-off-by: Ray Lehtiniemi <rayl@mail.com>
This commit is contained in:
Ray Lehtiniemi 2017-03-11 11:46:03 -07:00
parent c5060079e4
commit 06b6e07b98
3 changed files with 75 additions and 0 deletions

View 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

View 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

View File

@ -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