mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #3108: Show warning if :start-at: and other literalinclude options does not match to the text
This commit is contained in:
parent
8a98a1ad3d
commit
1dea386bc4
2
CHANGES
2
CHANGES
@ -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
|
||||
----------
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user