summaryrefslogtreecommitdiff
path: root/tests/test_directive_code.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2017-02-17 23:03:05 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2017-02-17 23:36:12 +0900
commit88b84a532fbfd2df5917b2fc6800f756d313adc7 (patch)
tree597aa2f999000a4f3d5ddd71bd4ac0ba54eef0d5 /tests/test_directive_code.py
parent2f3a3d8cc2580e606e2e3dc595853a63d6ff7150 (diff)
downloadsphinx-git-88b84a532fbfd2df5917b2fc6800f756d313adc7.tar.gz
Add testcase for :lineno-match: option
Diffstat (limited to 'tests/test_directive_code.py')
-rw-r--r--tests/test_directive_code.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py
index a6d77fabf..8a2283daa 100644
--- a/tests/test_directive_code.py
+++ b/tests/test_directive_code.py
@@ -21,19 +21,30 @@ DUMMY_CONFIG = Config(None, None, {}, '')
def test_LiteralIncludeReader():
- options = {}
+ options = {'lineno-match': True}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == LITERAL_INC_PATH.text()
assert lines == 14
+ assert reader.lineno_start == 1
+
+
+def test_LiteralIncludeReader_lineno_start():
+ options = {'lineno-start': 5}
+ reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ content, lines = reader.read()
+ assert content == LITERAL_INC_PATH.text()
+ assert lines == 14
+ assert reader.lineno_start == 5
def test_LiteralIncludeReader_pyobject1():
- options = {'pyobject': 'Foo'}
+ options = {'lineno-match': True, 'pyobject': 'Foo'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("class Foo:\n"
" pass\n")
+ assert reader.lineno_start == 6
def test_LiteralIncludeReader_pyobject2():
@@ -43,6 +54,7 @@ def test_LiteralIncludeReader_pyobject2():
assert content == ("class Bar:\n"
" def baz():\n"
" pass\n")
+ assert reader.lineno_start == 1 # no lineno-match
def test_LiteralIncludeReader_pyobject3():
@@ -72,8 +84,18 @@ def test_LiteralIncludeReader_lines2():
u"class Foo:\n")
+def test_LiteralIncludeReader_lines_and_lineno_match1():
+ options = {'lines': '4-6', 'lineno-match': True}
+ reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ content, lines = reader.read()
+ assert content == (u"foo = \"Including Unicode characters: üöä\"\n"
+ u"\n"
+ u"class Foo:\n")
+ assert reader.lineno_start == 4
+
+
@pytest.mark.sphinx() # init locale for errors
-def test_LiteralIncludeReader_lines_and_lineno_match1(app, status, warning):
+def test_LiteralIncludeReader_lines_and_lineno_match2(app, status, warning):
options = {'lines': '1,4,6', 'lineno-match': True}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
@@ -81,7 +103,7 @@ def test_LiteralIncludeReader_lines_and_lineno_match1(app, status, warning):
@pytest.mark.sphinx() # init locale for errors
-def test_LiteralIncludeReader_lines_and_lineno_match2(app, status, warning):
+def test_LiteralIncludeReader_lines_and_lineno_match3(app, status, warning):
options = {'lines': '100-', 'lineno-match': True}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
@@ -89,21 +111,23 @@ def test_LiteralIncludeReader_lines_and_lineno_match2(app, status, warning):
def test_LiteralIncludeReader_start_at():
- options = {'start-at': 'Foo', 'end-at': 'Bar'}
+ options = {'lineno-match': True, 'start-at': 'Foo', 'end-at': 'Bar'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("class Foo:\n"
" pass\n"
"\n"
"class Bar:\n")
+ assert reader.lineno_start == 6
def test_LiteralIncludeReader_start_after():
- options = {'start-after': 'Foo', 'end-before': 'Bar'}
+ options = {'lineno-match': True, 'start-after': 'Foo', 'end-before': 'Bar'}
reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (" pass\n"
"\n")
+ assert reader.lineno_start == 7
def test_LiteralIncludeReader_prepend():