Fix #3108: Show warning if :start-at: and other literalinclude options does not match to the text

This commit is contained in:
Takeshi KOMIYA 2017-03-26 18:13:31 +09:00
parent 8a98a1ad3d
commit 1dea386bc4
3 changed files with 34 additions and 0 deletions

View File

@ -97,6 +97,8 @@ Features added
and docutils 0.13 and newer is installed.
* LaTeX macros to customize space before and after tables in PDF output (refs #3504)
* #3348: Show decorators in literalinclude and viewcode directives
* #3108: Show warning if :start-at: and other literalinclude options does not
match to the text
Bugs fixed
----------

View File

@ -314,6 +314,11 @@ class LiteralIncludeReader(object):
self.lineno_start += lineno
return lines[lineno:]
else:
if inclusive is True:
raise ValueError('start-after pattern not found: %s' % start)
else:
raise ValueError('start-at pattern not found: %s' % start)
return lines
@ -338,6 +343,11 @@ class LiteralIncludeReader(object):
return []
else:
return lines[:lineno]
else:
if inclusive is True:
raise ValueError('end-at pattern not found: %s' % end)
else:
raise ValueError('end-before pattern not found: %s' % end)
return lines

View File

@ -161,6 +161,28 @@ def test_LiteralIncludeReader_start_at_and_lines():
assert reader.lineno_start == 1
def test_LiteralIncludeReader_missing_start_and_end():
options = {'start-at': 'NOTHING'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
options = {'end-at': 'NOTHING'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
options = {'start-after': 'NOTHING'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
options = {'end-before': 'NOTHING'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
def test_LiteralIncludeReader_prepend():
options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)