


"A quote."\n
After.']), - ("> One\n> line.\n>\n> Two.\n>\n> Three:\n\n- A list after it.\n", - ['
"One line.\n
Two.\n
Three:"']), + ( + "> One\n> line.\n>\n> Two.\n>\n> Three:\n\n- A list after it.\n", + ['
"One line.\n
Two.\n
Three:"'], + ), ("> [!NOTE]\n> One.\n>\n> Two.\n", ["One.\n
Two."]),
# a tag directly after a letter: SCDoc needs a character between them that is not a letter
- ("A word**bold**, a word*italic*, a word`code`, a word[link](https://example.com) and a word$x$.\n",
- ["A word\u2060bold, a word\u2060italic, a word\u2060code, "
- 'a word\u2060link and a word\u2060x.']),
- ("Café**bold** and x_**bold** and 2**bold**.\n",
- ["Café\u2060bold and x_bold and 2bold."]),
- ("A word[^1] and a word [^2].\n\n[^1]: One.\n[^2]: Two.\n",
- ["
A word[1] - Line one and line two."]), - ("Text.[^1] After.\n\n[^1]: Paragraph one,\n still one.\n\n Paragraph two.\n\n\tThree.\n\nNot in the note.\n", - ["] - Paragraph one, still one.\n
Paragraph two.\n
Three.", "
Not in the note."]),
+ (
+ "A word**bold**, a word*italic*, a word`code`, a word[link](https://example.com) and a word$x$.\n",
+ [
+ "A word\u2060bold, a word\u2060italic, a word\u2060code, "
+ "a word\u2060link and a word\u2060x."
+ ],
+ ),
+ (
+ "Café**bold** and x_**bold** and 2**bold**.\n",
+ ["Café\u2060bold and x_bold and 2bold."],
+ ),
+ (
+ "A word[^1] and a word [^2].\n\n[^1]: One.\n[^2]: Two.\n",
+ ["
A word[1] - Line one and line two."], + ), + ( + "Text.[^1] After.\n\n[^1]: Paragraph one,\n still one.\n\n Paragraph two.\n\n\tThree.\n\nNot in the note.\n", + ["] - Paragraph one, still one.\n
Paragraph two.\n
Three.", "
Not in the note."], + ), ("# A::B\n\nText.\n", ["
#1 is text."]),
("Math $a::b$ in text.\n", ["a::b"]),
("Before.\n\n$$\nx\n::\ny\n$$\n\nAfter.\n", ["x\n::\ny"]),
("Use `a::b` and `x\\` here.\n", ["a::b", "x\\ here."]),
("## Section: with a colon\n\nText.\n", ["
| A | B |
| 1 | 2 |
| A | B |
| 1 | 2 |
| 1 | 2 |
x | y"]),
+ (
+ "| A | |\n|---|---|\n| a \\|\\| b | `x \\| y` |\n",
+ ["x | y"],
+ ),
]
diff --git a/tests/schelp_fixtures.py b/tests/schelp_fixtures.py
index 101d3d9..6c4de6d 100644
--- a/tests/schelp_fixtures.py
+++ b/tests/schelp_fixtures.py
@@ -19,6 +19,7 @@
python3 tests/schelp_fixtures.py update
"""
+
import argparse
import importlib
import json
@@ -153,7 +154,10 @@ def render_texts(sclang: str, texts: dict, timeout: int = 180, copied: list = No
+ "0.exit;\n"
)
env = dict(
- os.environ, HOME=str(tmp / "home"), XDG_DATA_HOME=str(data), XDG_CONFIG_HOME=str(data),
+ os.environ,
+ HOME=str(tmp / "home"),
+ XDG_DATA_HOME=str(data),
+ XDG_CONFIG_HOME=str(data),
QT_QPA_PLATFORM="offscreen",
)
done = subprocess.run([sclang, str(script)], env=env, capture_output=True, text=True, timeout=timeout)
@@ -192,8 +196,11 @@ def render_all(sclang: str, timeout: int = 180) -> dict:
fixtures with a bibliography are not rendered.
"""
with_pandoc = find_pandoc() is not None
- results = render_texts(sclang, {md_path.stem: convert(md_path) for md_path in fixtures()
- if with_pandoc or not needs_pandoc(md_path)}, timeout)
+ results = render_texts(
+ sclang,
+ {md_path.stem: convert(md_path) for md_path in fixtures() if with_pandoc or not needs_pandoc(md_path)},
+ timeout,
+ )
errors = [f"{name}: {result}" for name, result in results.items() if isinstance(result, RenderError)]
if errors:
raise RenderError("\n".join(errors))
diff --git a/tests/test_schelp_behavior.py b/tests/test_schelp_behavior.py
index 4fc6617..ad42a25 100644
--- a/tests/test_schelp_behavior.py
+++ b/tests/test_schelp_behavior.py
@@ -2,6 +2,7 @@
How the schelp output is made, for the cases that the fixtures do not show: header values, special sections,
admonitions, math, code, insertion points and quotation marks.
"""
+
import pytest
from md2misc import convert_schelp
@@ -61,7 +62,7 @@ def test_metadata_lists_are_a_string_with_commas_or_a_list(value):
('summary: "Quoted: with a colon"', "SUMMARY::Quoted: with a colon\n"),
("summary: 'Single quoted'", "SUMMARY::Single quoted\n"),
("summary: Unquoted: with a colon", "SUMMARY::Unquoted: with a colon\n"),
- ('related: ["Classes/A", \'Classes/B\']', "RELATED::Classes/A, Classes/B\n"),
+ ("related: [\"Classes/A\", 'Classes/B']", "RELATED::Classes/A, Classes/B\n"),
("related: Classes/A, Classes/B", "RELATED::Classes/A, Classes/B\n"),
('categories:\n - "A"\n - B', "CATEGORIES::A, B\n"),
],
@@ -109,16 +110,19 @@ def test_header_without_title_or_class_is_an_error():
# ------------------------------------------------------ special sections
-@pytest.mark.parametrize("heading, expected", [
- ("## Description", "DESCRIPTION::"),
- ("## description", "DESCRIPTION::"),
- ("## Examples", "EXAMPLES::"),
- ("## EXAMPLES", "EXAMPLES::"),
- ("## Other", "SECTION::Other"),
- ("### Description", "SUBSECTION::Description"),
- ("#### Examples", "SUBSUBSECTION::Examples"),
- ("##### Deeper", "SUBSUBSECTION::Deeper"),
-])
+@pytest.mark.parametrize(
+ "heading, expected",
+ [
+ ("## Description", "DESCRIPTION::"),
+ ("## description", "DESCRIPTION::"),
+ ("## Examples", "EXAMPLES::"),
+ ("## EXAMPLES", "EXAMPLES::"),
+ ("## Other", "SECTION::Other"),
+ ("### Description", "SUBSECTION::Description"),
+ ("#### Examples", "SUBSUBSECTION::Examples"),
+ ("##### Deeper", "SUBSUBSECTION::Deeper"),
+ ],
+)
def test_headings(heading, expected):
assert convert_schelp(heading + "\n") == expected + "\n"
@@ -126,10 +130,18 @@ def test_headings(heading, expected):
# ------------------------------------------------------------ admonitions
-@pytest.mark.parametrize("mark, tag", [
- ("NOTE", "note"), ("TIP", "note"), ("IMPORTANT", "note"), ("WARNING", "warning"), ("CAUTION", "warning"),
- ("note", "note"), ("Warning", "warning"),
-])
+@pytest.mark.parametrize(
+ "mark, tag",
+ [
+ ("NOTE", "note"),
+ ("TIP", "note"),
+ ("IMPORTANT", "note"),
+ ("WARNING", "warning"),
+ ("CAUTION", "warning"),
+ ("note", "note"),
+ ("Warning", "warning"),
+ ],
+)
def test_admonition_tags(mark, tag):
assert convert_schelp(f"> [!{mark}]\n> The text.\n") == f"{tag}::\nThe text.\n\n::\n"
@@ -218,15 +230,18 @@ def test_insertion_point_inside_a_line_is_an_html_comment():
# ------------------------------------------------------------ inline tags
-@pytest.mark.parametrize("markdown, expected", [
- ("**Note:** text.", "strong::Note: :: text."),
- ("*Note:* text.", "emphasis::Note: :: text."),
- ("Use `foo:` here.", "Use code::foo: :: here."),
- ("Use `C:\\` here.", "Use code::C:\\ :: here."),
- ("[Note:](https://example.com) text.", "link::https://example.com##Note: :: text."),
- ("Math $a:$ here.", "Math math::a: :: here."),
- ("Text.[^1]\n\n[^1]: Ends:", "Text.footnote::Ends: ::"),
-])
+@pytest.mark.parametrize(
+ "markdown, expected",
+ [
+ ("**Note:** text.", "strong::Note: :: text."),
+ ("*Note:* text.", "emphasis::Note: :: text."),
+ ("Use `foo:` here.", "Use code::foo: :: here."),
+ ("Use `C:\\` here.", "Use code::C:\\ :: here."),
+ ("[Note:](https://example.com) text.", "link::https://example.com##Note: :: text."),
+ ("Math $a:$ here.", "Math math::a: :: here."),
+ ("Text.[^1]\n\n[^1]: Ends:", "Text.footnote::Ends: ::"),
+ ],
+)
def test_inline_tag_with_a_colon_or_backslash_at_the_end_gets_a_space(markdown, expected):
# SCDoc takes the character as part of the end-tag `::`
assert convert_schelp(markdown + "\n") == expected + "\n"
@@ -268,15 +283,19 @@ def test_quotation_marks_stay():
assert convert_schelp("He said \"it is 'fine' now\".\n") == "He said \"it is 'fine' now\".\n"
-@pytest.mark.parametrize("markdown, schelp", [
- ("A word**bold**.\n", "A word\u2060strong::bold::.\n"),
- ("A word*italic*.\n", "A word\u2060emphasis::italic::.\n"),
- ("A word`code`.\n", "A word\u2060code::code::.\n"),
- ("A word[link](https://example.com).\n", "A word\u2060link::https://example.com##link::.\n"),
- ("A word$x$.\n", "A word\u2060math::x::.\n"),
- ("A word[^1].\n\n[^1]: A note.\n", "A word footnote::A note.::.\n"),
- ("A word **bold** and 2**bold**.\n", "A word strong::bold:: and 2strong::bold::.\n"),
-], ids=["bold", "italic", "code", "link", "math", "footnote", "no letter before"])
+@pytest.mark.parametrize(
+ "markdown, schelp",
+ [
+ ("A word**bold**.\n", "A word\u2060strong::bold::.\n"),
+ ("A word*italic*.\n", "A word\u2060emphasis::italic::.\n"),
+ ("A word`code`.\n", "A word\u2060code::code::.\n"),
+ ("A word[link](https://example.com).\n", "A word\u2060link::https://example.com##link::.\n"),
+ ("A word$x$.\n", "A word\u2060math::x::.\n"),
+ ("A word[^1].\n\n[^1]: A note.\n", "A word footnote::A note.::.\n"),
+ ("A word **bold** and 2**bold**.\n", "A word strong::bold:: and 2strong::bold::.\n"),
+ ],
+ ids=["bold", "italic", "code", "link", "math", "footnote", "no letter before"],
+)
def test_tag_directly_after_a_letter(markdown, schelp):
# SCDoc takes letters directly before `::` as the name of a tag: a word joiner (U+2060), or a space before a
# footnote, keeps the word and the tag apart
diff --git a/tests/test_schelp_citations.py b/tests/test_schelp_citations.py
index 8b1ce7b..e0a4020 100644
--- a/tests/test_schelp_citations.py
+++ b/tests/test_schelp_citations.py
@@ -3,6 +3,7 @@
becomes a footnote. The first citation of a source gives its reference entry, later citations the short form.
A citation in a footnote gives the short form in parentheses. The tests that run pandoc are skipped without it.
"""
+
from pathlib import Path
import pytest
@@ -11,45 +12,51 @@
BIBLIOGRAPHY = Path(__file__).parent / "schelp" / "citations.bib"
DOE = "Doe, Jane. 1999. emphasis::Sound and Wood::. Acme"
-SMITH = ("Smith, John, and Ann Lee. 2000. “Bars and Rods: A Study of Modes.” emphasis::Journal of Acoustics:: 3: "
- "1–9. link::https://doi.org/10.1000/xyz::")
+SMITH = (
+ "Smith, John, and Ann Lee. 2000. “Bars and Rods: A Study of Modes.” emphasis::Journal of Acoustics:: 3: "
+ "1–9. link::https://doi.org/10.1000/xyz::"
+)
def schelp(markdown: str) -> str:
return convert_schelp(markdown, bibliography=BIBLIOGRAPHY)
-@pytest.mark.parametrize("citation, footnote", [
- ("[@doe1999]", DOE + "."),
- ("[@doe1999, p. 30]", DOE + ", p. 30."),
- ("[@doe1999, 30]", DOE + ", p. 30."),
- ("[@doe1999, 30-35]", DOE + ", pp. 30–35."),
- ("[@doe1999, chap. 2]", DOE + ", chap. 2."),
- ("[-@doe1999]", DOE + "."),
- ("[@doe1999; @smith2000]", DOE + "; " + SMITH + "."),
-], ids=["key", "page", "page number", "pages", "other locator", "no author", "two sources"])
+@pytest.mark.parametrize(
+ "citation, footnote",
+ [
+ ("[@doe1999]", DOE + "."),
+ ("[@doe1999, p. 30]", DOE + ", p. 30."),
+ ("[@doe1999, 30]", DOE + ", p. 30."),
+ ("[@doe1999, 30-35]", DOE + ", pp. 30–35."),
+ ("[@doe1999, chap. 2]", DOE + ", chap. 2."),
+ ("[-@doe1999]", DOE + "."),
+ ("[@doe1999; @smith2000]", DOE + "; " + SMITH + "."),
+ ],
+ ids=["key", "page", "page number", "pages", "other locator", "no author", "two sources"],
+)
def test_first_citation_gives_the_reference_entry(citation, footnote, pandoc):
assert schelp(f"A text {citation}.\n") == f"A text footnote::{footnote}::.\n"
def test_later_citation_gives_the_short_form(pandoc):
out = schelp("One [@doe1999]. Two [@doe1999, 31]. Three [@smith2000; @doe1999].\n")
- assert out == (f"One footnote::{DOE}.::. Two footnote::Doe 1999, 31.::. "
- f"Three footnote::{SMITH}; Doe 1999.::.\n")
+ assert out == (f"One footnote::{DOE}.::. Two footnote::Doe 1999, 31.::. Three footnote::{SMITH}; Doe 1999.::.\n")
def test_works_of_one_author_and_year_are_told_apart(pandoc):
out = schelp("One [@doe1999]. Two [@doe1999b]. Again [@doe1999b].\n")
- assert out == ("One footnote::Doe, Jane. 1999b. emphasis::Sound and Wood::. Acme.::. "
- # the style writes `———` for the second work of an author in a list; a footnote names the
- # author again
- "Two footnote::Doe, Jane. 1999a. emphasis::More Wood::. Acme.::. Again footnote::Doe 1999a.::.\n")
+ assert out == (
+ "One footnote::Doe, Jane. 1999b. emphasis::Sound and Wood::. Acme.::. "
+ # the style writes `———` for the second work of an author in a list; a footnote names the
+ # author again
+ "Two footnote::Doe, Jane. 1999a. emphasis::More Wood::. Acme.::. Again footnote::Doe 1999a.::.\n"
+ )
def test_citation_in_a_footnote_gives_the_short_form_in_parentheses(pandoc):
out = schelp("Text.[^1] More [@smith2000].\n\n[^1]: As in [@doe1999, 30].\n\n And [@smith2000].\n")
- assert out == ("Text.footnote::As in (Doe 1999, 30).\n\nAnd (Smith and Lee 2000).:: "
- f"More footnote::{SMITH}.::.\n")
+ assert out == (f"Text.footnote::As in (Doe 1999, 30).\n\nAnd (Smith and Lee 2000).:: More footnote::{SMITH}.::.\n")
def test_citation_directly_after_a_word(pandoc):
@@ -98,8 +105,9 @@ def test_text_without_citations_does_not_need_the_bibliography(monkeypatch):
def test_citation_without_a_bibliography_names_the_choices():
- with pytest.raises(UnsupportedConstruct, match="give a bibliography to the conversion, or write the citation "
- "as text"):
+ with pytest.raises(
+ UnsupportedConstruct, match="give a bibliography to the conversion, or write the citation as text"
+ ):
convert_schelp("A text [@doe1999].\n")
diff --git a/tests/test_schelp_errors.py b/tests/test_schelp_errors.py
index 9108ec4..5a2da0a 100644
--- a/tests/test_schelp_errors.py
+++ b/tests/test_schelp_errors.py
@@ -2,6 +2,7 @@
Markdown that has no schelp form stops the conversion: `convert_schelp` raises an error that holds the construct
and its line, and `describe()` names the file too. Markdown that only looks like such a construct is accepted.
"""
+
import re
import pytest
@@ -25,12 +26,15 @@ def test_error_names_the_file_and_the_line():
with pytest.raises(UnsupportedConstruct) as error:
convert_schelp("Text.\n\n---\n")
assert str(error.value) == "line 3: the schelp output cannot write this Markdown construct: horizontal rule"
- assert error.value.describe("page.md") == \
- "page.md:3: the schelp output cannot write this Markdown construct: horizontal rule"
+ assert (
+ error.value.describe("page.md")
+ == "page.md:3: the schelp output cannot write this Markdown construct: horizontal rule"
+ )
-@pytest.mark.parametrize("markdown, metadata, insertions, message", DOCUMENT_ERRORS,
- ids=[m for *_, m in DOCUMENT_ERRORS])
+@pytest.mark.parametrize(
+ "markdown, metadata, insertions, message", DOCUMENT_ERRORS, ids=[m for *_, m in DOCUMENT_ERRORS]
+)
def test_document_error_stops_the_conversion(markdown, metadata, insertions, message):
with pytest.raises((DocumentError, UnsupportedConstruct)) as error:
convert_schelp(markdown, metadata, insertions)
diff --git a/tests/test_schelp_golden.py b/tests/test_schelp_golden.py
index f941cdc..d329ee6 100644
--- a/tests/test_schelp_golden.py
+++ b/tests/test_schelp_golden.py
@@ -2,6 +2,7 @@
The schelp output has not changed: every fixture in tests/schelp is converted and compared with the .schelp file
next to it.
"""
+
import pytest
from schelp_fixtures import convert, fixtures, needs_pandoc
diff --git a/tests/test_schelp_methods.py b/tests/test_schelp_methods.py
index 3c1a01c..8ef9c3c 100644
--- a/tests/test_schelp_methods.py
+++ b/tests/test_schelp_methods.py
@@ -3,6 +3,7 @@
gives `METHOD::`, the rows of the argument table of a method give `ARGUMENT::` entries, and a `Returns:`
paragraph gives `returns::`. The checks that stop the conversion are in schelp_cases.py.
"""
+
import re
import pytest
@@ -28,15 +29,18 @@ def arguments(schelp: str) -> list:
def test_method_with_an_argument_table_and_a_return_value():
out = methods("### *ar\n\n" + TABLE + "\nReturns: one channel.\n\n## Examples\n\nText.\n")
- assert out == ("CLASSMETHODS::\n\nMETHOD::ar\n\n"
- "ARGUMENT::freq\nThe frequency.\n\nARGUMENT::amp\nThe level.\n\n"
- "returns::one channel.\n\nEXAMPLES::\n\nText.\n")
+ assert out == (
+ "CLASSMETHODS::\n\nMETHOD::ar\n\n"
+ "ARGUMENT::freq\nThe frequency.\n\nARGUMENT::amp\nThe level.\n\n"
+ "returns::one channel.\n\nEXAMPLES::\n\nText.\n"
+ )
def test_methods_without_tables_and_text_before_the_first_method():
out = methods("Intro.\n\n### *ar, *kr\n\nText.\n\nReturns: two\nchannels.\n\n### *new\n\nMakes one.\n")
- assert out == ("CLASSMETHODS::\n\nIntro.\n\nMETHOD::ar, kr\n\nText.\n\nreturns::two\nchannels.\n\n"
- "METHOD::new\n\nMakes one.\n")
+ assert out == (
+ "CLASSMETHODS::\n\nIntro.\n\nMETHOD::ar, kr\n\nText.\n\nreturns::two\nchannels.\n\nMETHOD::new\n\nMakes one.\n"
+ )
def test_text_of_a_method_comes_before_its_arguments():
@@ -47,8 +51,13 @@ def test_text_of_a_method_comes_before_its_arguments():
def test_two_methods_with_tables():
out = methods("### *ar\n\n" + TABLE + "\n### *kr\n\n" + TABLE.replace("freq", "rate"))
assert re.findall(r"^(METHOD|ARGUMENT)::(.*)$", out, re.M) == [
- ("METHOD", "ar"), ("ARGUMENT", "freq"), ("ARGUMENT", "amp"),
- ("METHOD", "kr"), ("ARGUMENT", "rate"), ("ARGUMENT", "amp")]
+ ("METHOD", "ar"),
+ ("ARGUMENT", "freq"),
+ ("ARGUMENT", "amp"),
+ ("METHOD", "kr"),
+ ("ARGUMENT", "rate"),
+ ("ARGUMENT", "amp"),
+ ]
def test_section_heading_is_not_case_sensitive():
@@ -61,10 +70,18 @@ def test_next_level_2_heading_ends_the_section():
assert "SECTION::More\n\nReturns: text, as it is not in a method." in out
-@pytest.mark.parametrize("heading, names", [
- ("### *ar", "ar"), ("### *ar, *kr", "ar, kr"), ("### *ar,*kr", "ar, kr"), ("### *ar , *kr ", "ar, kr"),
- ("### *new_2", "new_2"), ("### *ar, *kr, *new", "ar, kr, new"),
-], ids=["one name", "two names", "no space", "more spaces", "underscore and digit", "three names"])
+@pytest.mark.parametrize(
+ "heading, names",
+ [
+ ("### *ar", "ar"),
+ ("### *ar, *kr", "ar, kr"),
+ ("### *ar,*kr", "ar, kr"),
+ ("### *ar , *kr ", "ar, kr"),
+ ("### *new_2", "new_2"),
+ ("### *ar, *kr, *new", "ar, kr, new"),
+ ],
+ ids=["one name", "two names", "no space", "more spaces", "underscore and digit", "three names"],
+)
def test_method_headings(heading, names):
assert f"METHOD::{names}\n" in methods(heading + "\n\nText.\n")
@@ -72,21 +89,35 @@ def test_method_headings(heading, names):
# ---------------------------------------------------- forms of the argument table
-@pytest.mark.parametrize("table", [
- TABLE,
- "Argument | Text\n---|---\nfreq | The frequency.\namp | The level.\n",
- "| Argument | Text\n|---|---\n| freq | The frequency.\n| amp | The level.\n",
- "Argument | Text |\n---|---|\nfreq | The frequency. |\namp | The level. |\n",
- "| Argument | Text |\n---|---\nfreq | The frequency. |\n| amp | The level.\n",
- "|Argument|Text|\n|-|-|\n|freq|The frequency.|\n|amp|The level.|\n",
- "| Argument | Text |\n|:---|---:|\n| freq | The frequency. |\n| amp | The level. |\n",
- "| Argument | Text |\n| :---: | :-- |\n| freq | The frequency. |\n| amp | The level. |\n",
- " | Argument | Text |\n |---|---|\n | freq | The frequency. |\n | amp | The level. |\n",
- "| Argument | Text |\n|---|---|\n|\tfreq\t| The frequency. |\n| amp | The level. | \n",
- "| `Argument` | **Text** |\n|---|---|\n| freq | The frequency. |\n| amp | The level. |\n",
-], ids=["outer pipes", "no outer pipes", "leading pipes only", "trailing pipes only", "mixed pipes",
- "no spaces", "alignment colons", "spaces in the delimiter row", "indent of 3", "spaces and tabs",
- "markup in the header"])
+@pytest.mark.parametrize(
+ "table",
+ [
+ TABLE,
+ "Argument | Text\n---|---\nfreq | The frequency.\namp | The level.\n",
+ "| Argument | Text\n|---|---\n| freq | The frequency.\n| amp | The level.\n",
+ "Argument | Text |\n---|---|\nfreq | The frequency. |\namp | The level. |\n",
+ "| Argument | Text |\n---|---\nfreq | The frequency. |\n| amp | The level.\n",
+ "|Argument|Text|\n|-|-|\n|freq|The frequency.|\n|amp|The level.|\n",
+ "| Argument | Text |\n|:---|---:|\n| freq | The frequency. |\n| amp | The level. |\n",
+ "| Argument | Text |\n| :---: | :-- |\n| freq | The frequency. |\n| amp | The level. |\n",
+ " | Argument | Text |\n |---|---|\n | freq | The frequency. |\n | amp | The level. |\n",
+ "| Argument | Text |\n|---|---|\n|\tfreq\t| The frequency. |\n| amp | The level. | \n",
+ "| `Argument` | **Text** |\n|---|---|\n| freq | The frequency. |\n| amp | The level. |\n",
+ ],
+ ids=[
+ "outer pipes",
+ "no outer pipes",
+ "leading pipes only",
+ "trailing pipes only",
+ "mixed pipes",
+ "no spaces",
+ "alignment colons",
+ "spaces in the delimiter row",
+ "indent of 3",
+ "spaces and tabs",
+ "markup in the header",
+ ],
+)
def test_forms_of_the_table_give_the_same_arguments(table):
assert arguments(methods("### *ar\n\n" + table)) == ARGUMENTS
@@ -98,10 +129,17 @@ def test_table_directly_after_a_paragraph_line():
assert arguments(out) == ARGUMENTS
-@pytest.mark.parametrize("after", ["\n## Examples\n", "## Examples\n", "\nReturns: x.\n", "\n### *kr\n",
- "### *kr\n"],
- ids=["section after an empty line", "section directly after", "return value",
- "method after an empty line", "method directly after"])
+@pytest.mark.parametrize(
+ "after",
+ ["\n## Examples\n", "## Examples\n", "\nReturns: x.\n", "\n### *kr\n", "### *kr\n"],
+ ids=[
+ "section after an empty line",
+ "section directly after",
+ "return value",
+ "method after an empty line",
+ "method directly after",
+ ],
+)
def test_what_can_follow_the_table(after):
assert arguments(methods("### *ar\n\n" + TABLE + after)) == ARGUMENTS
@@ -121,35 +159,55 @@ def test_argument_names_with_underscores_and_digits(name):
assert arguments(out) == [(name, "A.")]
-@pytest.mark.parametrize("cell, text", [
- ("Uses `In.ar`.", "Uses code::In.ar::."),
- ("A **loud** sound.", "A strong::loud:: sound."),
- ("An *odd* one.", "An emphasis::odd:: one."),
- ("See [SinOsc](sc:Classes/SinOsc).", "See link::Classes/SinOsc::."),
- ("See [the site](https://example.com).", "See link::https://example.com##the site::."),
- ("One \\| two.", "One | two."),
- ("Code `a \\| b`.", "Code code::a | b::."),
- ("A \\|\\| B.", "A \\|| B."),
- ("Tag:: and ## here.", "Tag\\:: and \\## here."),
- ("> 0 is on.", "> 0 is on."),
- ("- 1 is off.", "- 1 is off."),
- ("1. is first.", "1. is first."),
- ("# is a sign.", "# is a sign."),
- ("−1 to 1, ≥ 0.5.", "−1 to 1, ≥ 0.5."),
- ("Math $x^2$.", "Math math::x^2::."),
-], ids=["code", "bold", "italic", "sc link", "web link", "escaped pipe", "escaped pipe in code",
- "two escaped pipes", "schelp marks", "quote mark", "list mark", "number mark", "heading mark",
- "not ASCII", "math"])
+@pytest.mark.parametrize(
+ "cell, text",
+ [
+ ("Uses `In.ar`.", "Uses code::In.ar::."),
+ ("A **loud** sound.", "A strong::loud:: sound."),
+ ("An *odd* one.", "An emphasis::odd:: one."),
+ ("See [SinOsc](sc:Classes/SinOsc).", "See link::Classes/SinOsc::."),
+ ("See [the site](https://example.com).", "See link::https://example.com##the site::."),
+ ("One \\| two.", "One | two."),
+ ("Code `a \\| b`.", "Code code::a | b::."),
+ ("A \\|\\| B.", "A \\|| B."),
+ ("Tag:: and ## here.", "Tag\\:: and \\## here."),
+ ("> 0 is on.", "> 0 is on."),
+ ("- 1 is off.", "- 1 is off."),
+ ("1. is first.", "1. is first."),
+ ("# is a sign.", "# is a sign."),
+ ("−1 to 1, ≥ 0.5.", "−1 to 1, ≥ 0.5."),
+ ("Math $x^2$.", "Math math::x^2::."),
+ ],
+ ids=[
+ "code",
+ "bold",
+ "italic",
+ "sc link",
+ "web link",
+ "escaped pipe",
+ "escaped pipe in code",
+ "two escaped pipes",
+ "schelp marks",
+ "quote mark",
+ "list mark",
+ "number mark",
+ "heading mark",
+ "not ASCII",
+ "math",
+ ],
+)
def test_text_of_an_argument(cell, text):
out = methods(f"### *ar\n\n| Argument | Text |\n|---|---|\n| x | {cell} |\n")
assert arguments(out) == [("x", text)]
def test_columns_between_the_name_and_the_text():
- table = ("| Argument | Range | Unit | Text |\n|---|---|---|---|\n"
- "| freq | 20 to 20000 | Hz | The frequency. |\n"
- "| amp | | | The level. |\n"
- "| pan | −1 to 1 | | The position. |\n")
+ table = (
+ "| Argument | Range | Unit | Text |\n|---|---|---|---|\n"
+ "| freq | 20 to 20000 | Hz | The frequency. |\n"
+ "| amp | | | The level. |\n"
+ "| pan | −1 to 1 | | The position. |\n"
+ )
assert arguments(methods("### *ar\n\n" + table)) == [
("freq", "The frequency.\nRange: 20 to 20000\nUnit: Hz"),
("amp", "The level."),
@@ -165,21 +223,29 @@ def test_markup_in_the_other_columns():
# ------------------------------------------------------------- the return value
-@pytest.mark.parametrize("paragraph, returns", [
- ("Returns: one channel.", "returns::one channel."),
- ("Returns:one channel.", "returns::one channel."),
- ("Returns: an `Array`, two\nchannels.", "returns::an code::Array::, two\nchannels."),
-], ids=["one line", "no space", "markup and two lines"])
+@pytest.mark.parametrize(
+ "paragraph, returns",
+ [
+ ("Returns: one channel.", "returns::one channel."),
+ ("Returns:one channel.", "returns::one channel."),
+ ("Returns: an `Array`, two\nchannels.", "returns::an code::Array::, two\nchannels."),
+ ],
+ ids=["one line", "no space", "markup and two lines"],
+)
def test_return_value(paragraph, returns):
assert returns in methods("### *ar\n\n" + TABLE + "\n" + paragraph + "\n")
-@pytest.mark.parametrize("markdown", [
- "## Class methods\n\nReturns: before a method.\n",
- "## Description\n\nReturns: in another section.\n",
- "## Class methods\n\n### *ar\n\nThe text. Returns: in a paragraph.\n",
- "## Class methods\n\n### *ar\n\nThe text.\nReturns: on the second line of a paragraph.\n",
-], ids=["before a method", "in another section", "in the text", "second line of a paragraph"])
+@pytest.mark.parametrize(
+ "markdown",
+ [
+ "## Class methods\n\nReturns: before a method.\n",
+ "## Description\n\nReturns: in another section.\n",
+ "## Class methods\n\n### *ar\n\nThe text. Returns: in a paragraph.\n",
+ "## Class methods\n\n### *ar\n\nThe text.\nReturns: on the second line of a paragraph.\n",
+ ],
+ ids=["before a method", "in another section", "in the text", "second line of a paragraph"],
+)
def test_returns_that_is_text(markdown):
out = convert_schelp(markdown)
assert "returns::" not in out
@@ -190,17 +256,18 @@ def test_returns_that_is_text(markdown):
def test_instance_methods_section():
- out = convert_schelp("## Instance methods\n\n### -play, -stop\n\nPlays it.\n\n" + TABLE
- + "\nReturns: this.\n")
- assert out == ("INSTANCEMETHODS::\n\nMETHOD::play, stop\n\nPlays it.\n\n"
- "ARGUMENT::freq\nThe frequency.\n\nARGUMENT::amp\nThe level.\n\nreturns::this.\n")
+ out = convert_schelp("## Instance methods\n\n### -play, -stop\n\nPlays it.\n\n" + TABLE + "\nReturns: this.\n")
+ assert out == (
+ "INSTANCEMETHODS::\n\nMETHOD::play, stop\n\nPlays it.\n\n"
+ "ARGUMENT::freq\nThe frequency.\n\nARGUMENT::amp\nThe level.\n\nreturns::this.\n"
+ )
def test_both_methods_sections():
- out = convert_schelp("## Class methods\n\n### *new\n\nMakes one.\n\n"
- "## Instance methods\n\n### -free\n\nFrees it.\n")
- assert out == ("CLASSMETHODS::\n\nMETHOD::new\n\nMakes one.\n\n"
- "INSTANCEMETHODS::\n\nMETHOD::free\n\nFrees it.\n")
+ out = convert_schelp(
+ "## Class methods\n\n### *new\n\nMakes one.\n\n## Instance methods\n\n### -free\n\nFrees it.\n"
+ )
+ assert out == ("CLASSMETHODS::\n\nMETHOD::new\n\nMakes one.\n\nINSTANCEMETHODS::\n\nMETHOD::free\n\nFrees it.\n")
def test_instance_method_heading_outside_a_methods_section_is_a_heading():
@@ -210,8 +277,11 @@ def test_instance_method_heading_outside_a_methods_section_is_a_heading():
# ------------------------------------------------------------------ the discussion
-@pytest.mark.parametrize("before", ["", TABLE + "\n", "Returns: x.\n\n", TABLE + "\nReturns: x.\n\n"],
- ids=["after the text", "after the table", "after the return value", "after both"])
+@pytest.mark.parametrize(
+ "before",
+ ["", TABLE + "\n", "Returns: x.\n\n", TABLE + "\nReturns: x.\n\n"],
+ ids=["after the text", "after the table", "after the return value", "after both"],
+)
def test_discussion(before):
out = methods("### *ar\n\nText.\n\n" + before + "#### Discussion\n\nMore text.\n\n```\nx = 1;\n```\n")
assert out.endswith("discussion::\n\nMore text.\n\ncode::\nx = 1;\n::\n")
@@ -219,8 +289,10 @@ def test_discussion(before):
def test_discussion_can_hold_any_text():
- out = methods("### *ar\n\n" + TABLE + "\n#### discussion\n\nReturns: text here.\n\n- A list.\n\n"
- "> [!NOTE]\n> A note.\n\n### *kr\n\nText.\n")
+ out = methods(
+ "### *ar\n\n" + TABLE + "\n#### discussion\n\nReturns: text here.\n\n- A list.\n\n"
+ "> [!NOTE]\n> A note.\n\n### *kr\n\nText.\n"
+ )
assert "discussion::\n\nReturns: text here.\n\nLIST::\n## A list.\n::" in out
assert out.count("returns::") == 0
assert "METHOD::kr" in out
diff --git a/tests/test_schelp_render.py b/tests/test_schelp_render.py
index 17d6b16..b234021 100644
--- a/tests/test_schelp_render.py
+++ b/tests/test_schelp_render.py
@@ -5,6 +5,7 @@
All versions of sclang must parse the output with no error and give the expected parts of the pages. Only the
version that made the .html files must give the same whole pages.
"""
+
import re
import pytest
diff --git a/tests/test_schelp_tables.py b/tests/test_schelp_tables.py
index 98cd168..0c683ee 100644
--- a/tests/test_schelp_tables.py
+++ b/tests/test_schelp_tables.py
@@ -2,34 +2,51 @@
Tables outside the methods sections: a pipe table of GitHub Flavored Markdown gives `table::`. SCDoc has no header
row, thus the header row is a first row in bold. The checks that stop the conversion are in schelp_cases.py.
"""
+
import pytest
from md2misc import convert, convert_schelp
-@pytest.mark.parametrize("markdown, schelp", [
- ("| A | B |\n|---|---|\n| 1 | 2 |\n| 3 | 4 |\n",
- "table::\n## strong::A:: || strong::B::\n## 1 || 2\n## 3 || 4\n::\n"),
- ("| | |\n|---|---|\n| 1 | 2 |\n", "table::\n## 1 || 2\n::\n"),
- ("| A | |\n|---|---|\n| 1 | 2 |\n", "table::\n## strong::A:: ||\n## 1 || 2\n::\n"),
- ("| A | B |\n|---|---|\n| 1 |\n", "table::\n## strong::A:: || strong::B::\n## 1 ||\n::\n"),
- ("A | B\n:-:|--:\n1 | 2\n", "table::\n## strong::A:: || strong::B::\n## 1 || 2\n::\n"),
- ("| A |\n|---|\n| 1 |\n", "table::\n## strong::A::\n## 1\n::\n"),
-], ids=["header and rows", "empty header row", "empty header cell", "short row", "no outer pipes and alignment",
- "one column"])
+@pytest.mark.parametrize(
+ "markdown, schelp",
+ [
+ (
+ "| A | B |\n|---|---|\n| 1 | 2 |\n| 3 | 4 |\n",
+ "table::\n## strong::A:: || strong::B::\n## 1 || 2\n## 3 || 4\n::\n",
+ ),
+ ("| | |\n|---|---|\n| 1 | 2 |\n", "table::\n## 1 || 2\n::\n"),
+ ("| A | |\n|---|---|\n| 1 | 2 |\n", "table::\n## strong::A:: ||\n## 1 || 2\n::\n"),
+ ("| A | B |\n|---|---|\n| 1 |\n", "table::\n## strong::A:: || strong::B::\n## 1 ||\n::\n"),
+ ("A | B\n:-:|--:\n1 | 2\n", "table::\n## strong::A:: || strong::B::\n## 1 || 2\n::\n"),
+ ("| A |\n|---|\n| 1 |\n", "table::\n## strong::A::\n## 1\n::\n"),
+ ],
+ ids=[
+ "header and rows",
+ "empty header row",
+ "empty header cell",
+ "short row",
+ "no outer pipes and alignment",
+ "one column",
+ ],
+)
def test_table(markdown, schelp):
assert convert_schelp(markdown) == schelp
-@pytest.mark.parametrize("cell, text", [
- ("Uses `In.ar`.", "Uses code::In.ar::."),
- ("A **loud** sound.", "A strong::loud:: sound."),
- ("See [SinOsc](sc:Classes/SinOsc).", "See link::Classes/SinOsc::."),
- ("One \\| two.", "One | two."),
- ("Code `a \\| b`.", "Code code::a | b::."),
- ("A \\|\\| B and ## C.", "A \\|| B and \\## C."),
- ("Math $x^2$.", "Math math::x^2::."),
-], ids=["code", "bold", "link", "escaped pipe", "escaped pipe in code", "schelp marks", "math"])
+@pytest.mark.parametrize(
+ "cell, text",
+ [
+ ("Uses `In.ar`.", "Uses code::In.ar::."),
+ ("A **loud** sound.", "A strong::loud:: sound."),
+ ("See [SinOsc](sc:Classes/SinOsc).", "See link::Classes/SinOsc::."),
+ ("One \\| two.", "One | two."),
+ ("Code `a \\| b`.", "Code code::a | b::."),
+ ("A \\|\\| B and ## C.", "A \\|| B and \\## C."),
+ ("Math $x^2$.", "Math math::x^2::."),
+ ],
+ ids=["code", "bold", "link", "escaped pipe", "escaped pipe in code", "schelp marks", "math"],
+)
def test_markup_in_a_cell(cell, text):
assert convert_schelp(f"| A |\n|---|\n| {cell} |\n") == f"table::\n## strong::A::\n## {text}\n::\n"
diff --git a/tests/test_schelp_writer.py b/tests/test_schelp_writer.py
index a8fa76a..c10afff 100644
--- a/tests/test_schelp_writer.py
+++ b/tests/test_schelp_writer.py
@@ -2,6 +2,7 @@
The writers of the schelp backend stop at the constructs that have no schelp form, too, if the check of the
Markdown source does not find them first. The error has no line then.
"""
+
import pytest
from md2misc import convert_schelp
diff --git a/tests/test_tables.py b/tests/test_tables.py
index 3a3af48..1dfa0b2 100644
--- a/tests/test_tables.py
+++ b/tests/test_tables.py
@@ -3,6 +3,7 @@
table ends. The expected values are those of cmark-gfm 0.29.0.gfm.13, the GitHub Flavored Markdown parser of
GitHub, where the comments do not say otherwise (checked on 2026-11-17).
"""
+
import pytest
from md2misc import tables
@@ -15,70 +16,112 @@ def table(markdown: str):
if tables.starts_table(lines, number):
header = tables.split_row(lines[number])
rows = [header]
- for row in lines[number + 2:tables.table_end(lines, number)]:
+ for row in lines[number + 2 : tables.table_end(lines, number)]:
cells = tables.split_row(row)
rows.append(cells + [""] * (len(header) - len(cells)))
return rows
return None
-@pytest.mark.parametrize("markdown, rows", [
- ("| a | b |\n|---|---|\n| 1 | 2 |\n", [["a", "b"], ["1", "2"]]),
- ("a | b\n---|---\n1 | 2\n", [["a", "b"], ["1", "2"]]),
- ("| a | b\n|--|--\n| 1 | 2\n", [["a", "b"], ["1", "2"]]),
- ("a | b |\n--|--|\n1 | 2 |\n", [["a", "b"], ["1", "2"]]),
- ("| abc | defghi |\n:-: | -----------:\nbar | baz\n", [["abc", "defghi"], ["bar", "baz"]]),
- ("|a|b|\n|-|-|\n|1|2|\n", [["a", "b"], ["1", "2"]]),
- ("|a|b|c|d|\n|:--|:-:|--:|---|\n|1|2|3|4|\n", [["a", "b", "c", "d"], ["1", "2", "3", "4"]]),
- ("|a|b|\n| :---: | ---: |\n|1|2|\n", [["a", "b"], ["1", "2"]]),
- ("|a|b| \n|-|-| \n|1|2| \n", [["a", "b"], ["1", "2"]]),
- (" |a|b|\n |-|-|\n |1|2|\n", [["a", "b"], ["1", "2"]]),
-], ids=["outer pipes", "no outer pipes", "leading pipes only", "trailing pipes only", "mixed outer pipes",
- "one hyphen", "alignment", "spaces around delimiter cells", "trailing spaces", "indent of 3"])
+@pytest.mark.parametrize(
+ "markdown, rows",
+ [
+ ("| a | b |\n|---|---|\n| 1 | 2 |\n", [["a", "b"], ["1", "2"]]),
+ ("a | b\n---|---\n1 | 2\n", [["a", "b"], ["1", "2"]]),
+ ("| a | b\n|--|--\n| 1 | 2\n", [["a", "b"], ["1", "2"]]),
+ ("a | b |\n--|--|\n1 | 2 |\n", [["a", "b"], ["1", "2"]]),
+ ("| abc | defghi |\n:-: | -----------:\nbar | baz\n", [["abc", "defghi"], ["bar", "baz"]]),
+ ("|a|b|\n|-|-|\n|1|2|\n", [["a", "b"], ["1", "2"]]),
+ ("|a|b|c|d|\n|:--|:-:|--:|---|\n|1|2|3|4|\n", [["a", "b", "c", "d"], ["1", "2", "3", "4"]]),
+ ("|a|b|\n| :---: | ---: |\n|1|2|\n", [["a", "b"], ["1", "2"]]),
+ ("|a|b| \n|-|-| \n|1|2| \n", [["a", "b"], ["1", "2"]]),
+ (" |a|b|\n |-|-|\n |1|2|\n", [["a", "b"], ["1", "2"]]),
+ ],
+ ids=[
+ "outer pipes",
+ "no outer pipes",
+ "leading pipes only",
+ "trailing pipes only",
+ "mixed outer pipes",
+ "one hyphen",
+ "alignment",
+ "spaces around delimiter cells",
+ "trailing spaces",
+ "indent of 3",
+ ],
+)
def test_forms_of_a_table(markdown, rows):
assert table(markdown) == rows
-@pytest.mark.parametrize("markdown", [
- "|a|b|\n|- -|---|\n|1|2|\n",
- "|a|b|\n|:|---|\n",
- "|a|b|\n|=|=|\n",
- "|a|b|\n|-||\n",
- "|a|\n---\n|1|\n",
- " |a|b|\n |-|-|\n |1|2|\n",
- "|a|b|\n |-|-|\n|1|2|\n",
- "|a|b|\n\n|-|-|\n|1|2|\n",
- "| a | b |\n| --- \\|| --- |\n",
- "- a | b\n- c | d\n",
- "a | b\n--- ---\n",
- "Text without a pipe.\n---|---\n",
-], ids=["space in a delimiter cell", "colon only", "equals signs", "empty delimiter cell",
- "delimiter row without a pipe (a heading)", "indent of 4 (code)", "delimiter row with an indent of 4",
- "empty line after the header", "escaped pipe in the delimiter row", "list items with pipes",
- "delimiter row without pipes", "header without a pipe"])
+@pytest.mark.parametrize(
+ "markdown",
+ [
+ "|a|b|\n|- -|---|\n|1|2|\n",
+ "|a|b|\n|:|---|\n",
+ "|a|b|\n|=|=|\n",
+ "|a|b|\n|-||\n",
+ "|a|\n---\n|1|\n",
+ " |a|b|\n |-|-|\n |1|2|\n",
+ "|a|b|\n |-|-|\n|1|2|\n",
+ "|a|b|\n\n|-|-|\n|1|2|\n",
+ "| a | b |\n| --- \\|| --- |\n",
+ "- a | b\n- c | d\n",
+ "a | b\n--- ---\n",
+ "Text without a pipe.\n---|---\n",
+ ],
+ ids=[
+ "space in a delimiter cell",
+ "colon only",
+ "equals signs",
+ "empty delimiter cell",
+ "delimiter row without a pipe (a heading)",
+ "indent of 4 (code)",
+ "delimiter row with an indent of 4",
+ "empty line after the header",
+ "escaped pipe in the delimiter row",
+ "list items with pipes",
+ "delimiter row without pipes",
+ "header without a pipe",
+ ],
+)
def test_not_a_table(markdown):
assert table(markdown) is None
-@pytest.mark.parametrize("markdown, rows", [
- ("|a|\n|---|\n|1|\n", [["a"], ["1"]]),
- ("a |\n--|\n1 |\n", [["a"], ["1"]]),
- ("| a\n|--\n| 1\n", [["a"], ["1"]]),
- ("||\n|-|\n|1|\n", [[""], ["1"]]),
-], ids=["outer pipes", "trailing pipes", "leading pipes", "empty header"])
+@pytest.mark.parametrize(
+ "markdown, rows",
+ [
+ ("|a|\n|---|\n|1|\n", [["a"], ["1"]]),
+ ("a |\n--|\n1 |\n", [["a"], ["1"]]),
+ ("| a\n|--\n| 1\n", [["a"], ["1"]]),
+ ("||\n|-|\n|1|\n", [[""], ["1"]]),
+ ],
+ ids=["outer pipes", "trailing pipes", "leading pipes", "empty header"],
+)
def test_one_column(markdown, rows):
assert table(markdown) == rows
-@pytest.mark.parametrize("markdown, rows", [
- ("|a|b|\n|-|-|\n", [["a", "b"]]),
- ("|a|b|\n|-|-|\n|1|\n", [["a", "b"], ["1", ""]]),
- ("|a|b|\n|-|-|\n||2|\n|1||\n", [["a", "b"], ["", "2"], ["1", ""]]),
- ("| a | b |\n|-|-|\n| 1 |\t2\t|\n", [["a", "b"], ["1", "2"]]),
- ("| | |\n|-|-|\n|1|2|\n", [["", ""], ["1", "2"]]),
- ("| name | range |\n|---|---|\n| pan | −1 to 1 |\n", [["name", "range"], ["pan", "−1 to 1"]]),
-], ids=["header only", "short row padded", "empty cells", "spaces and tabs trimmed", "empty header cells",
- "text that is not ASCII"])
+@pytest.mark.parametrize(
+ "markdown, rows",
+ [
+ ("|a|b|\n|-|-|\n", [["a", "b"]]),
+ ("|a|b|\n|-|-|\n|1|\n", [["a", "b"], ["1", ""]]),
+ ("|a|b|\n|-|-|\n||2|\n|1||\n", [["a", "b"], ["", "2"], ["1", ""]]),
+ ("| a | b |\n|-|-|\n| 1 |\t2\t|\n", [["a", "b"], ["1", "2"]]),
+ ("| | |\n|-|-|\n|1|2|\n", [["", ""], ["1", "2"]]),
+ ("| name | range |\n|---|---|\n| pan | −1 to 1 |\n", [["name", "range"], ["pan", "−1 to 1"]]),
+ ],
+ ids=[
+ "header only",
+ "short row padded",
+ "empty cells",
+ "spaces and tabs trimmed",
+ "empty header cells",
+ "text that is not ASCII",
+ ],
+)
def test_cells(markdown, rows):
assert table(markdown) == rows
@@ -99,12 +142,16 @@ def test_delimiter_row_with_another_number_of_cells_starts_a_table():
assert table("|a|b|\n|---|---|---|\n|1|2|\n") == [["a", "b"], ["1", "2"]]
-@pytest.mark.parametrize("row, cells", [
- ("|x\\|y|2|", ["x\\|y", "2"]),
- ("|`x\\|y`|2|", ["`x\\|y`", "2"]),
- ("|1|2\\|", ["1", "2\\|"]),
- ("|`x|y`|2|", ["`x", "y`", "2"]),
-], ids=["escaped pipe", "escaped pipe in code", "escaped pipe at the end", "pipe in code splits the cell"])
+@pytest.mark.parametrize(
+ "row, cells",
+ [
+ ("|x\\|y|2|", ["x\\|y", "2"]),
+ ("|`x\\|y`|2|", ["`x\\|y`", "2"]),
+ ("|1|2\\|", ["1", "2\\|"]),
+ ("|`x|y`|2|", ["`x", "y`", "2"]),
+ ],
+ ids=["escaped pipe", "escaped pipe in code", "escaped pipe at the end", "pipe in code splits the cell"],
+)
def test_split_row_with_pipes_in_cells(row, cells):
assert tables.split_row(row) == cells
@@ -114,9 +161,20 @@ def test_unescape_gives_the_pipe():
assert tables.unescape("`x\\|y`") == "`x|y`"
-@pytest.mark.parametrize("after", ["", "\n\nnext", "\n# H", "\n> q", "\n```\nx\n```", "\n- x", "\n1. x", "\n***"],
- ids=["end of the text", "empty line", "heading", "block quote", "code block", "list",
- "numbered list", "horizontal rule"])
+@pytest.mark.parametrize(
+ "after",
+ ["", "\n\nnext", "\n# H", "\n> q", "\n```\nx\n```", "\n- x", "\n1. x", "\n***"],
+ ids=[
+ "end of the text",
+ "empty line",
+ "heading",
+ "block quote",
+ "code block",
+ "list",
+ "numbered list",
+ "horizontal rule",
+ ],
+)
def test_end_of_a_table(after):
lines = ("|a|b|\n|-|-|\n|1|2|" + after).split("\n")
assert tables.table_end(lines, 0) == 3
@@ -132,11 +190,15 @@ def test_second_delimiter_row_is_a_row():
assert table("|a|b|\n|-|-|\n|1|2|\n|-|-|\n") == [["a", "b"], ["1", "2"], ["-", "-"]]
-@pytest.mark.parametrize("markdown, header", [
- ("para\n|a|b|\n|-|-|\n|1|2|\n", 1),
- ("p1\np2\n|a|b|\n|-|-|\n", 2),
- ("|a|\n|b|\n|-|\n", 1),
-], ids=["after a paragraph line", "after two paragraph lines", "only one header row"])
+@pytest.mark.parametrize(
+ "markdown, header",
+ [
+ ("para\n|a|b|\n|-|-|\n|1|2|\n", 1),
+ ("p1\np2\n|a|b|\n|-|-|\n", 2),
+ ("|a|\n|b|\n|-|\n", 1),
+ ],
+ ids=["after a paragraph line", "after two paragraph lines", "only one header row"],
+)
def test_header_is_the_line_before_the_delimiter_row(markdown, header):
lines = markdown.split("\n")
assert [n for n in range(len(lines)) if tables.starts_table(lines, n)] == [header]
diff --git a/tests/test_tex_battery.py b/tests/test_tex_battery.py
index 2617c89..9e1db8a 100644
--- a/tests/test_tex_battery.py
+++ b/tests/test_tex_battery.py
@@ -3,6 +3,7 @@
.tex file that md2tex wrote for it. name@variant.tex is the Markdown of name.md with the convert() arguments from
name@variant.args. See battery.py for how the fixtures are made.
"""
+
import json
import pytest
diff --git a/tests/test_tex_library.py b/tests/test_tex_library.py
index 6ef330a..8212d14 100644
--- a/tests/test_tex_library.py
+++ b/tests/test_tex_library.py
@@ -1,6 +1,7 @@
"""
The TeX backend as a library: the arguments of `convert`, the default template, the warnings and the errors.
"""
+
import subprocess
import sys
from pathlib import Path
@@ -36,8 +37,9 @@ def test_unnumbered_headings():
def test_override_language_gives_every_code_block_the_language():
markdown = "```python\nx = 1\n```\n"
assert "\\begin{minted}{python}" in convert(markdown)
- assert "\\begin{minted}{supercollider}" in convert(markdown, minted_language="supercollider",
- override_language=True)
+ assert "\\begin{minted}{supercollider}" in convert(
+ markdown, minted_language="supercollider", override_language=True
+ )
def test_default_template_has_the_tokens_for_the_body_and_the_document_class():