summaryrefslogtreecommitdiff
path: root/tests/test_directive_code.py
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2017-05-07 16:46:44 +0900
committershimizukawa <shimizukawa@gmail.com>2017-05-14 20:47:15 +0900
commitd497d743700704b10dc081c2a7d3508282155526 (patch)
tree34a509c10d38aff04d657a630582a880c5089aab /tests/test_directive_code.py
parent0512ebf2d45f5783755c3141754eac0f04755b9e (diff)
downloadsphinx-git-d497d743700704b10dc081c2a7d3508282155526.tar.gz
refs #3458: add sphinx.testing that are moved from /tests directory.
Diffstat (limited to 'tests/test_directive_code.py')
-rw-r--r--tests/test_directive_code.py121
1 files changed, 65 insertions, 56 deletions
diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py
index 0e702803d..5f67c5627 100644
--- a/tests/test_directive_code.py
+++ b/tests/test_directive_code.py
@@ -13,43 +13,52 @@ import pytest
from sphinx.config import Config
from sphinx.directives.code import LiteralIncludeReader
-from util import etree_parse, rootdir
+from sphinx.testing.util import etree_parse
-TESTROOT_PATH = rootdir / 'roots' / 'test-directive-code'
-LITERAL_INC_PATH = TESTROOT_PATH / 'literal.inc'
DUMMY_CONFIG = Config(None, None, {}, '')
-def test_LiteralIncludeReader():
+@pytest.fixture(scope='module')
+def testroot(rootdir):
+ testroot_path = rootdir / 'test-directive-code'
+ return testroot_path
+
+
+@pytest.fixture(scope='module')
+def literal_inc_path(testroot):
+ return testroot / 'literal.inc'
+
+
+def test_LiteralIncludeReader(literal_inc_path):
options = {'lineno-match': True}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
- assert content == LITERAL_INC_PATH.text()
+ assert content == literal_inc_path.text()
assert lines == 14
assert reader.lineno_start == 1
-def test_LiteralIncludeReader_lineno_start():
+def test_LiteralIncludeReader_lineno_start(literal_inc_path):
options = {'lineno-start': 5}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
- assert content == LITERAL_INC_PATH.text()
+ assert content == literal_inc_path.text()
assert lines == 14
assert reader.lineno_start == 5
-def test_LiteralIncludeReader_pyobject1():
+def test_LiteralIncludeReader_pyobject1(literal_inc_path):
options = {'lineno-match': True, 'pyobject': 'Foo'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ 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():
+def test_LiteralIncludeReader_pyobject2(literal_inc_path):
options = {'pyobject': 'Bar'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("class Bar:\n"
" def baz():\n"
@@ -57,25 +66,25 @@ def test_LiteralIncludeReader_pyobject2():
assert reader.lineno_start == 1 # no lineno-match
-def test_LiteralIncludeReader_pyobject3():
+def test_LiteralIncludeReader_pyobject3(literal_inc_path):
options = {'pyobject': 'Bar.baz'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (" def baz():\n"
" pass\n")
-def test_LiteralIncludeReader_pyobject_and_lines():
+def test_LiteralIncludeReader_pyobject_and_lines(literal_inc_path):
options = {'pyobject': 'Bar', 'lines': '2-'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (" def baz():\n"
" pass\n")
-def test_LiteralIncludeReader_lines1():
+def test_LiteralIncludeReader_lines1(literal_inc_path):
options = {'lines': '1-4'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (u"# Literally included file using Python highlighting\n"
u"# -*- coding: utf-8 -*-\n"
@@ -83,18 +92,18 @@ def test_LiteralIncludeReader_lines1():
u"foo = \"Including Unicode characters: üöä\"\n")
-def test_LiteralIncludeReader_lines2():
+def test_LiteralIncludeReader_lines2(literal_inc_path):
options = {'lines': '1,4,6'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (u"# Literally included file using Python highlighting\n"
u"foo = \"Including Unicode characters: üöä\"\n"
u"class Foo:\n")
-def test_LiteralIncludeReader_lines_and_lineno_match1():
+def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path):
options = {'lines': '4-6', 'lineno-match': True}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (u"foo = \"Including Unicode characters: üöä\"\n"
u"\n"
@@ -103,24 +112,24 @@ def test_LiteralIncludeReader_lines_and_lineno_match1():
@pytest.mark.sphinx() # init locale for errors
-def test_LiteralIncludeReader_lines_and_lineno_match2(app, status, warning):
+def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app, status, warning):
options = {'lines': '1,4,6', 'lineno-match': True}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
@pytest.mark.sphinx() # init locale for errors
-def test_LiteralIncludeReader_lines_and_lineno_match3(app, status, warning):
+def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app, status, warning):
options = {'lines': '100-', 'lineno-match': True}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
-def test_LiteralIncludeReader_start_at():
+def test_LiteralIncludeReader_start_at(literal_inc_path):
options = {'lineno-match': True, 'start-at': 'Foo', 'end-at': 'Bar'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("class Foo:\n"
" pass\n"
@@ -129,19 +138,19 @@ def test_LiteralIncludeReader_start_at():
assert reader.lineno_start == 6
-def test_LiteralIncludeReader_start_after():
+def test_LiteralIncludeReader_start_after(literal_inc_path):
options = {'lineno-match': True, 'start-after': 'Foo', 'end-before': 'Bar'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ 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_start_after_and_lines():
+def test_LiteralIncludeReader_start_after_and_lines(literal_inc_path):
options = {'lineno-match': True, 'lines': '6-',
'start-after': 'coding', 'end-before': 'comment'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("\n"
"class Bar:\n"
@@ -151,9 +160,9 @@ def test_LiteralIncludeReader_start_after_and_lines():
assert reader.lineno_start == 8
-def test_LiteralIncludeReader_start_at_and_lines():
+def test_LiteralIncludeReader_start_at_and_lines(literal_inc_path):
options = {'lines': '2, 3, 5', 'start-at': 'foo', 'end-before': '#'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("\n"
"class Foo:\n"
@@ -161,41 +170,41 @@ def test_LiteralIncludeReader_start_at_and_lines():
assert reader.lineno_start == 1
-def test_LiteralIncludeReader_missing_start_and_end():
+def test_LiteralIncludeReader_missing_start_and_end(literal_inc_path):
options = {'start-at': 'NOTHING'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ 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)
+ 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)
+ 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)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
with pytest.raises(ValueError):
content, lines = reader.read()
-def test_LiteralIncludeReader_prepend():
+def test_LiteralIncludeReader_prepend(literal_inc_path):
options = {'lines': '1', 'prepend': 'Hello', 'append': 'Sphinx'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("Hello\n"
"# Literally included file using Python highlighting\n"
"Sphinx\n")
-def test_LiteralIncludeReader_dedent():
+def test_LiteralIncludeReader_dedent(literal_inc_path):
# dedent: 2
options = {'lines': '10-12', 'dedent': 2}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == (" def baz():\n"
" pass\n"
@@ -203,7 +212,7 @@ def test_LiteralIncludeReader_dedent():
# dedent: 4
options = {'lines': '10-12', 'dedent': 4}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("def baz():\n"
" pass\n"
@@ -211,17 +220,17 @@ def test_LiteralIncludeReader_dedent():
# dedent: 6
options = {'lines': '10-12', 'dedent': 6}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("f baz():\n"
" pass\n"
"\n")
-def test_LiteralIncludeReader_tabwidth():
+def test_LiteralIncludeReader_tabwidth(testroot):
# tab-width: 4
options = {'tab-width': 4, 'pyobject': 'Qux'}
- reader = LiteralIncludeReader(TESTROOT_PATH / 'target.py', options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("class Qux:\n"
" def quux(self):\n"
@@ -229,27 +238,27 @@ def test_LiteralIncludeReader_tabwidth():
# tab-width: 8
options = {'tab-width': 8, 'pyobject': 'Qux'}
- reader = LiteralIncludeReader(TESTROOT_PATH / 'target.py', options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("class Qux:\n"
" def quux(self):\n"
" pass\n")
-def test_LiteralIncludeReader_tabwidth_dedent():
+def test_LiteralIncludeReader_tabwidth_dedent(testroot):
options = {'tab-width': 4, 'dedent': 4, 'pyobject': 'Qux.quux'}
- reader = LiteralIncludeReader(TESTROOT_PATH / 'target.py', options, DUMMY_CONFIG)
+ reader = LiteralIncludeReader(testroot / 'target.py', options, DUMMY_CONFIG)
content, lines = reader.read()
assert content == ("def quux(self):\n"
" pass\n")
-def test_LiteralIncludeReader_diff():
- options = {'diff': TESTROOT_PATH / 'literal-diff.inc'}
- reader = LiteralIncludeReader(LITERAL_INC_PATH, options, DUMMY_CONFIG)
+def test_LiteralIncludeReader_diff(testroot, literal_inc_path):
+ options = {'diff': testroot / 'literal-diff.inc'}
+ reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
content, lines = reader.read()
- assert content == ("--- " + TESTROOT_PATH + "/literal-diff.inc\n"
- "+++ " + TESTROOT_PATH + "/literal.inc\n"
+ assert content == ("--- " + testroot + "/literal-diff.inc\n"
+ "+++ " + testroot + "/literal.inc\n"
"@@ -7,8 +7,8 @@\n"
" pass\n"
" \n"