diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6f90b51..f62d15b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.9, "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v2 diff --git a/mktestdocs/__main__.py b/mktestdocs/__main__.py index 8428954..6989d41 100644 --- a/mktestdocs/__main__.py +++ b/mktestdocs/__main__.py @@ -95,14 +95,14 @@ def grab_code_blocks(docstring, lang="python"): block = "" codeblocks = [] for idx, line in enumerate(docstring.split("\n")): - if line.startswith("```"): + if "```" in line: if in_block: codeblocks.append(check_codeblock(block, lang=lang)) block = "" in_block = not in_block if in_block: block += line + "\n" - return [c for c in codeblocks if c != ""] + return [textwrap.dedent(c) for c in codeblocks if c != ""] def format_docstring(docstring): """Formats docstring to be able to successfully go through dedent.""" diff --git a/tests/test_actual_docstrings.py b/tests/test_actual_docstrings.py index cf82bbe..0f2c05c 100644 --- a/tests/test_actual_docstrings.py +++ b/tests/test_actual_docstrings.py @@ -16,43 +16,57 @@ def foobar_good(a, b): assert 1 + 2 == 3 ``` """ - return a + b + pass def foobar_also_good(a, b): """ - Returns a + b. - - Examples: - ```python import random assert random.random() < 10 ``` """ - return a + b + pass def foobar_bad(a, b): """ - Returns a + b. - - Examples: - ```python assert foobar(1, 2) == 4 ``` """ - return a + b + pass -@pytest.mark.parametrize("func", [foobar_good, foobar_also_good]) +def admonition_edge_cases(): + """ + !!! note + + All cells of a table are initialized with an empty string. Therefore, to delete the content of a cell, + you need to assign an empty string, i.e. `''`. For instance, to delete the first row after the header: + + ```python + assert 1 + 2 == 3 + ```""" + pass + +def adminition_edge_case_bad(): + """Test that we can handle the edge cases of admonitions.""" + example = """!!! note + + Another one. + ```python + assert 1 + 2 == 4 + ```""" + pass + +@pytest.mark.parametrize("func", [foobar_good, foobar_also_good, admonition_edge_cases]) def test_base_docstrings(func): check_docstring(func) -@pytest.mark.parametrize("func", [foobar_bad]) +@pytest.mark.parametrize("func", [foobar_bad, adminition_edge_case_bad]) def test_base_docstrings_bad(func, capsys): with pytest.raises(Exception): check_docstring(func)