From 2ebcbc882ec0266b90a3b885cf098b17babeb5f5 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 18 Feb 2017 00:12:54 +0900 Subject: [PATCH] Refactor testcases --- tests/roots/test-directive-code/dedent.rst | 35 ---- .../roots/test-directive-code/dedent_code.rst | 53 ------ .../test-directive-code/lineno_match.rst | 32 ---- .../test-directive-code/lineno_start.rst | 6 - tests/roots/test-directive-code/linenos.rst | 12 ++ tests/test_directive_code.py | 158 +++++------------- 6 files changed, 51 insertions(+), 245 deletions(-) delete mode 100644 tests/roots/test-directive-code/dedent.rst delete mode 100644 tests/roots/test-directive-code/dedent_code.rst delete mode 100644 tests/roots/test-directive-code/lineno_match.rst delete mode 100644 tests/roots/test-directive-code/lineno_start.rst diff --git a/tests/roots/test-directive-code/dedent.rst b/tests/roots/test-directive-code/dedent.rst deleted file mode 100644 index 9ec1c0eeb..000000000 --- a/tests/roots/test-directive-code/dedent.rst +++ /dev/null @@ -1,35 +0,0 @@ -Dedent -====== - -Literal Include ---------------- - -.. literalinclude:: literal.inc - :language: python - :lines: 10-11 - :dedent: 0 - -.. literalinclude:: literal.inc - :language: python - :lines: 10-11 - :dedent: 1 - -.. literalinclude:: literal.inc - :language: python - :lines: 10-11 - :dedent: 2 - -.. literalinclude:: literal.inc - :language: python - :lines: 10-11 - :dedent: 3 - -.. literalinclude:: literal.inc - :language: python - :lines: 10-11 - :dedent: 4 - -.. literalinclude:: literal.inc - :language: python - :lines: 10-11 - :dedent: 1000 diff --git a/tests/roots/test-directive-code/dedent_code.rst b/tests/roots/test-directive-code/dedent_code.rst deleted file mode 100644 index 3e8dacd69..000000000 --- a/tests/roots/test-directive-code/dedent_code.rst +++ /dev/null @@ -1,53 +0,0 @@ -Dedent -====== - -Code blocks ------------ - -.. code-block:: ruby - :linenos: - :dedent: 0 - - def ruby? - false - end - -.. code-block:: ruby - :linenos: - :dedent: 1 - - def ruby? - false - end - -.. code-block:: ruby - :linenos: - :dedent: 2 - - def ruby? - false - end - -.. code-block:: ruby - :linenos: - :dedent: 3 - - def ruby? - false - end - -.. code-block:: ruby - :linenos: - :dedent: 4 - - def ruby? - false - end - -.. code-block:: ruby - :linenos: - :dedent: 1000 - - def ruby? - false - end diff --git a/tests/roots/test-directive-code/lineno_match.rst b/tests/roots/test-directive-code/lineno_match.rst deleted file mode 100644 index 6a982f87e..000000000 --- a/tests/roots/test-directive-code/lineno_match.rst +++ /dev/null @@ -1,32 +0,0 @@ -Literal Includes with Line Numbers Matching -=========================================== - -.. literalinclude:: literal.inc - :language: python - :pyobject: Foo - :lineno-match: - -.. literalinclude:: literal.inc - :language: python - :lines: 5-6,7,8-9 - :lineno-match: - -.. literalinclude:: literal.inc - :language: python - :start-after: pass - :lineno-match: - -.. literalinclude:: literal.inc - :language: python - :start-after: Literally - :lines: 1,2 - :lineno-match: - -.. literalinclude:: literal.inc - :language: python - :start-at: class Bar: - :end-at: pass - :lineno-match: - -.. literalinclude:: empty.inc - :lineno-match: diff --git a/tests/roots/test-directive-code/lineno_start.rst b/tests/roots/test-directive-code/lineno_start.rst deleted file mode 100644 index 1beaabbf1..000000000 --- a/tests/roots/test-directive-code/lineno_start.rst +++ /dev/null @@ -1,6 +0,0 @@ -Literal Includes with Line Numbers Starting from 200 -==================================================== - -.. literalinclude:: literal.inc - :language: python - :lineno-start: 200 diff --git a/tests/roots/test-directive-code/linenos.rst b/tests/roots/test-directive-code/linenos.rst index 2f64498d8..a8e5b69cd 100644 --- a/tests/roots/test-directive-code/linenos.rst +++ b/tests/roots/test-directive-code/linenos.rst @@ -4,3 +4,15 @@ Literal Includes with Line Numbers .. literalinclude:: literal.inc :language: python :linenos: + +.. literalinclude:: literal.inc + :language: python + :lineno-start: 200 + +.. literalinclude:: literal.inc + :language: python + :lines: 5-9 + :lineno-match: + +.. literalinclude:: empty.inc + :lineno-match: diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 5f0df2b08..977715fa2 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -226,25 +226,6 @@ def test_code_block(app, status, warning): assert actual == expect -@pytest.mark.sphinx('xml', testroot='directive-code') -def test_code_block_dedent(app, status, warning): - app.builder.build(['dedent_code']) - et = etree_parse(app.outdir / 'dedent_code.xml') - blocks = et.findall('./section/section/literal_block') - - for i in range(5): # 0-4 - actual = blocks[i].text - indent = " " * (4 - i) - expect = ( - indent + "def ruby?\n" + - indent + " false\n" + - indent + "end" - ) - assert (i, actual) == (i, expect) - - assert blocks[5].text == '\n\n' # dedent: 1000 - - @pytest.mark.sphinx('html', testroot='directive-code') def test_code_block_caption_html(app, status, warning): app.builder.build(['caption']) @@ -299,24 +280,6 @@ def test_literal_include(app, status, warning): assert actual == literal_src -@pytest.mark.sphinx('xml', testroot='directive-code') -def test_literal_include_dedent(app, status, warning): - literal_src = (app.srcdir / 'literal.inc').text(encoding='utf-8') - literal_lines = [l[4:] for l in literal_src.split('\n')[9:11]] - - app.builder.build(['dedent']) - et = etree_parse(app.outdir / 'dedent.xml') - blocks = et.findall('./section/section/literal_block') - - for i in range(5): # 0-4 - actual = blocks[i].text - indent = ' ' * (4 - i) - expect = '\n'.join(indent + l for l in literal_lines) + '\n' - assert (i, actual) == (i, expect) - - assert blocks[5].text == '\n\n' # dedent: 1000 - - @pytest.mark.sphinx('xml', testroot='directive-code') def test_literal_include_block_start_with_comment_or_brank(app, status, warning): app.builder.build(['python']) @@ -345,91 +308,48 @@ def test_literal_include_block_start_with_comment_or_brank(app, status, warning) def test_literal_include_linenos(app, status, warning): app.builder.build(['linenos']) html = (app.outdir / 'linenos.html').text(encoding='utf-8') - linenos = ( - '
'
-        ' 1\n'
-        ' 2\n'
-        ' 3\n'
-        ' 4\n'
-        ' 5\n'
-        ' 6\n'
-        ' 7\n'
-        ' 8\n'
-        ' 9\n'
-        '10\n'
-        '11\n'
-        '12\n'
-        '13\n'
-        '14
') - assert linenos in html + # :linenos: + assert ('
'
+            ' 1\n'
+            ' 2\n'
+            ' 3\n'
+            ' 4\n'
+            ' 5\n'
+            ' 6\n'
+            ' 7\n'
+            ' 8\n'
+            ' 9\n'
+            '10\n'
+            '11\n'
+            '12\n'
+            '13\n'
+            '14
' in html) -@pytest.mark.sphinx('html', testroot='directive-code') -def test_literal_include_lineno_start(app, status, warning): - app.builder.build(['lineno_start']) - html = (app.outdir / 'lineno_start.html').text(encoding='utf-8') - linenos = ( - '
'
-        '200\n'
-        '201\n'
-        '202\n'
-        '203\n'
-        '204\n'
-        '205\n'
-        '206\n'
-        '207\n'
-        '208\n'
-        '209\n'
-        '210\n'
-        '211\n'
-        '212\n'
-        '213
') - assert linenos in html + # :lineno-start: + assert ('
'
+            '200\n'
+            '201\n'
+            '202\n'
+            '203\n'
+            '204\n'
+            '205\n'
+            '206\n'
+            '207\n'
+            '208\n'
+            '209\n'
+            '210\n'
+            '211\n'
+            '212\n'
+            '213
' in html) - -@pytest.mark.sphinx('html', testroot='directive-code') -def test_literal_include_lineno_match(app, status, warning): - app.builder.build(['lineno_match']) - html = (app.outdir / 'lineno_match.html').text(encoding='utf-8') - pyobject = ( - '
'
-        '6\n'
-        '7
') - - assert pyobject in html - - lines = ( - '
'
-        '5\n'
-        '6\n'
-        '7\n'
-        '8\n'
-        '9
') - assert lines in html - - start_after = ( - '
'
-        ' 8\n'
-        ' 9\n'
-        '10\n'
-        '11\n'
-        '12\n'
-        '13\n'
-        '14
') - assert start_after in html - - start_after_with_lines = ( - '
'
-        '2\n'
-        '3
') - assert start_after_with_lines in html - - start_at_end_at = ( - '
'
-        ' 9\n'
-        '10\n'
-        '11
') - assert start_at_end_at in html + # :lineno-match: + assert ('
'
+            '5\n'
+            '6\n'
+            '7\n'
+            '8\n'
+            '9
' in html) @pytest.mark.sphinx('latex', testroot='directive-code')