From f8dfc03c6d68e65f8db79a54fcb6ceb730c7c3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:24:19 +0200 Subject: [PATCH 1/8] better comment organization --- src/pytest_codeblocks/main.py | 145 ++++++++++++++++++-------------- src/pytest_codeblocks/plugin.py | 67 ++++++--------- tests/test_expect_error.py | 41 +++++++-- tests/test_general.py | 2 +- tests/test_shell.py | 4 +- tests/test_skipif.py | 6 ++ 6 files changed, 147 insertions(+), 118 deletions(-) diff --git a/src/pytest_codeblocks/main.py b/src/pytest_codeblocks/main.py index 1292b36..4ed9895 100644 --- a/src/pytest_codeblocks/main.py +++ b/src/pytest_codeblocks/main.py @@ -6,7 +6,7 @@ # namedtuple with default arguments # -from dataclasses import dataclass +from dataclasses import dataclass, field from io import StringIO from pathlib import Path @@ -17,10 +17,8 @@ class CodeBlock: lineno: int syntax: str | None = None expected_output: str | None = None - expect_exception: bool = False - skip: bool = False - skipif: str | None = None importorskip: str | None = None + marks: list[str] = field(default_factory=lambda: []) def extract_from_file( @@ -32,7 +30,10 @@ def extract_from_file( def extract_from_buffer(f, max_num_lines: int = 10000) -> list[CodeBlock]: out = [] - previous_nonempty_line = None + marks = [] + continued_block = None + expected_output_block = None + importorskip = None k = 1 while True: @@ -49,44 +50,12 @@ def extract_from_buffer(f, max_num_lines: int = 10000) -> list[CodeBlock]: if line.strip() == "": continue - if line.lstrip()[:3] == "```": - syntax = line.strip()[3:] - num_leading_spaces = len(line) - len(line.lstrip()) - lineno = k - 1 - # read the block - code_block = [] - while True: - line = f.readline() - k += 1 - if not line: - raise RuntimeError("Hit end-of-file prematurely. Syntax error?") - if k > max_num_lines: - raise RuntimeError( - f"File too large (> {max_num_lines} lines). Set max_num_lines." - ) - # check if end of block - if line.lstrip()[:3] == "```": - break - # Cut (at most) num_leading_spaces leading spaces - nls = min(num_leading_spaces, len(line) - len(line.lstrip())) - line = line[nls:] - code_block.append(line) - - if previous_nonempty_line is None: - out.append(CodeBlock("".join(code_block), lineno, syntax)) - continue - - # check for keywords - m = re.match( - r"", - previous_nonempty_line.strip(), - ) - if m is None: - out.append(CodeBlock("".join(code_block), lineno, syntax)) - continue - + m = re.match( + r"", + line.strip(), + ) + if m is not None: keyword = m.group(1).strip("- ") - # handle special tags if keyword == "expected-output": if len(out) == 0: @@ -99,33 +68,28 @@ def extract_from_buffer(f, max_num_lines: int = 10000) -> list[CodeBlock]: "Found " + "but block already has expected_output." ) - out[-1].expected_output = "".join(code_block) + expected_output_block = out[-1] elif keyword == "cont": if len(out) == 0: raise RuntimeError( "Found but no previous code block." ) - out[-1] = CodeBlock( - out[-1].code + "".join(code_block), - out[-1].lineno, - out[-1].syntax, - out[-1].expected_output, - out[-1].expect_exception, - ) + continued_block = out[-1] elif keyword == "skip": - out.append(CodeBlock("".join(code_block), lineno, syntax, skip=True)) + # TODO deprecate + marks.append("pytest.mark.skip") + # out.append(CodeBlock("".join(code_block), lineno, syntax, skip=True)) elif keyword.startswith("skipif"): + # TODO deprecate m = re.match(r"skipif\((.*)\)", keyword) if m is None: raise RuntimeError( "pytest-codeblocks: Expected skipif(some-condition)" ) - out.append( - CodeBlock("".join(code_block), lineno, syntax, skipif=m.group(1)) - ) + marks.append(f"pytest.mark.skipif({m.group(1)}, reason='')") elif keyword.startswith("importorskip"): m = re.match(r"importorskip\((.*)\)", keyword) @@ -133,23 +97,74 @@ def extract_from_buffer(f, max_num_lines: int = 10000) -> list[CodeBlock]: raise RuntimeError( "pytest-codeblocks: Expected importorskip(some-module)" ) - out.append( - CodeBlock( - "".join(code_block), lineno, syntax, importorskip=m.group(1) - ) - ) + importorskip = m.group(1) elif keyword in ["expect-exception", "expect-error"]: - out.append( - CodeBlock( - "".join(code_block), lineno, syntax, expect_exception=True - ) - ) + # TODO deprecate + marks.append("pytest.mark.xfail") else: raise RuntimeError(f'Unknown pytest-codeblocks keyword "{keyword}."') - previous_nonempty_line = line + continue + + m = re.match( + r"", + line.strip(), + ) + if m is not None: + marks.append(m.group(1)) + continue + + lsline = line.lstrip() + if lsline.startswith("```"): + # normally 3, but can be more: + num_leading_backticks = len(lsline) - len(lsline.lstrip("`")) + syntax = line.strip()[num_leading_backticks:] + num_leading_spaces = len(line) - len(lsline) + lineno = k - 1 + # read the block + code_block = [] + while True: + line = f.readline() + lsline = line.lstrip() + k += 1 + if not line: + raise RuntimeError("Hit end-of-file prematurely. Syntax error?") + if k > max_num_lines: + raise RuntimeError( + f"File too large (> {max_num_lines} lines). Set max_num_lines." + ) + # check if end of block + if lsline[:num_leading_backticks] == "`" * num_leading_backticks: + break + # Cut (at most) num_leading_spaces leading spaces + nls = min(num_leading_spaces, len(line) - len(lsline)) + line = line[nls:] + code_block.append(line) + + code = "".join(code_block) + + if continued_block: + continued_block.code += code + continued_block = None + + elif expected_output_block: + expected_output_block.expected_output = code + expected_output_block = None + + else: + out.append( + CodeBlock( + code, + lineno, + syntax, + marks=marks, + importorskip=importorskip, + ) + ) + marks = [] + importorskip = None return out diff --git a/src/pytest_codeblocks/plugin.py b/src/pytest_codeblocks/plugin.py index dc3bd48..9fe3beb 100644 --- a/src/pytest_codeblocks/plugin.py +++ b/src/pytest_codeblocks/plugin.py @@ -39,6 +39,10 @@ def collect(self): # ``` out = TestBlock.from_parent(parent=self, name=f"line {block.lineno}") out.obj = block + + for mark in block.marks: + out.add_marker(eval(mark)) + yield out @@ -51,16 +55,6 @@ def runtest(self): assert self.obj is not None output = None - if self.obj.skip: - pytest.skip() - - if self.obj.skipif is not None: - # needed for sys.version_info in skipif eval(): - import sys - - if eval(self.obj.skipif): - pytest.skip() - if self.obj.importorskip is not None: try: __import__(self.obj.importorskip) @@ -68,22 +62,18 @@ def runtest(self): pytest.skip() if self.obj.syntax == "python": - if self.obj.expect_exception: - with pytest.raises(Exception): + with stdout_io() as s: + try: + # https://stackoverflow.com/a/62851176/353337 exec(self.obj.code, {"__MODULE__": "__main__"}) - else: - with stdout_io() as s: - try: - # https://stackoverflow.com/a/62851176/353337 - exec(self.obj.code, {"__MODULE__": "__main__"}) - except Exception as e: - raise RuntimeError( - f"{self.name}, line {self.obj.lineno}:\n```\n" - + self.obj.code - + "```\n\n" - + f"{e}" - ) - output = s.getvalue() + except Exception as e: + raise RuntimeError( + f"{self.name}, line {self.obj.lineno}:\n```\n" + + self.obj.code + + "```\n\n" + + f"{e}" + ) + output = s.getvalue() else: assert self.obj.syntax in ["sh", "bash"] executable = { @@ -91,22 +81,17 @@ def runtest(self): "bash": "/bin/bash", "zsh": "/bin/zsh", }[self.obj.syntax] - if self.obj.expect_exception: - with pytest.raises(Exception): - subprocess.run( - self.obj.code, shell=True, check=True, executable=executable - ) - else: - # TODO for python 3.7+, stdout=subprocess.PIPE can be replaced - # by capture_output=True - ret = subprocess.run( - self.obj.code, - shell=True, - check=True, - stdout=subprocess.PIPE, - executable=executable, - ) - output = ret.stdout.decode() + + # TODO for python 3.7+, stdout=subprocess.PIPE can be replaced + # by capture_output=True + ret = subprocess.run( + self.obj.code, + shell=True, + check=True, + stdout=subprocess.PIPE, + executable=executable, + ) + output = ret.stdout.decode() if output is not None and self.obj.expected_output is not None: if self.obj.expected_output != output: diff --git a/tests/test_expect_error.py b/tests/test_expect_error.py index 72c8ae6..166127f 100644 --- a/tests/test_expect_error.py +++ b/tests/test_expect_error.py @@ -1,24 +1,47 @@ def test_expect_error(testdir): string = """ - Lorem ipsum - + ```python raise RuntimeError() ``` """ testdir.makefile(".md", string) result = testdir.runpytest("--codeblocks") - result.assert_outcomes(passed=1) + result.assert_outcomes(xfailed=1) -def test_expect_error_fail(testdir): - string1 = """ - Lorem ipsum - +def test_expect_error_runtimeerror(testdir): + string = """ + + ```python + raise RuntimeError() + ``` + """ + testdir.makefile(".md", string) + result = testdir.runpytest("--codeblocks") + result.assert_outcomes(xfailed=1) + + +def test_expect_error_indexerror(testdir): + string = """ + ```python - 1 + 1 + raise RuntimeError() ``` """ - testdir.makefile(".md", string1) + testdir.makefile(".md", string) result = testdir.runpytest("--codeblocks") result.assert_outcomes(failed=1) + + +# def test_expect_error_fail(testdir): +# string1 = """ +# Lorem ipsum +# +# ```python +# 1 + 1 +# ``` +# """ +# testdir.makefile(".md", string1) +# result = testdir.runpytest("--codeblocks") +# result.assert_outcomes(failed=1) diff --git a/tests/test_general.py b/tests/test_general.py index f649a5b..d1525e4 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -50,7 +50,7 @@ def test_reference(): ), pytest_codeblocks.CodeBlock("foobar\n", 16, "ruby"), pytest_codeblocks.CodeBlock("echo abc\n", 20, "sh"), - pytest_codeblocks.CodeBlock("bar\n", 25, "python", skip=True), + pytest_codeblocks.CodeBlock("bar\n", 25, "python", marks=["pytest.mark.skip"]), pytest_codeblocks.CodeBlock("# ```import math```\n", 30, "python"), pytest_codeblocks.CodeBlock("1 + 1 == 2\n", 35, "python"), pytest_codeblocks.CodeBlock("1 + 1 == 2\n", 40, "python"), diff --git a/tests/test_shell.py b/tests/test_shell.py index 40c4d81..2c227ea 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -42,7 +42,7 @@ def test_shell_expect_fail(testdir): """ testdir.makefile(".md", string) result = testdir.runpytest("--codeblocks") - result.assert_outcomes(passed=1) + result.assert_outcomes(xfailed=1) def test_shell_expect_fail_passed(testdir): @@ -54,7 +54,7 @@ def test_shell_expect_fail_passed(testdir): """ testdir.makefile(".md", string) result = testdir.runpytest("--codeblocks") - result.assert_outcomes(failed=1) + result.assert_outcomes(xpassed=1) def test_shell_expect_output(testdir): diff --git a/tests/test_skipif.py b/tests/test_skipif.py index 8e75582..e547666 100644 --- a/tests/test_skipif.py +++ b/tests/test_skipif.py @@ -49,6 +49,8 @@ def test_skipif(testdir): result = testdir.runpytest("--codeblocks") result.assert_outcomes(skipped=1) + +def test_skipif2(testdir): string = """ Lorem ipsum @@ -84,6 +86,8 @@ def test_skipif_expected_output(testdir): result = testdir.runpytest("--codeblocks") result.assert_outcomes(skipped=1) + +def test_skipif_expected_output2(testdir): string = """ Lorem ipsum @@ -119,6 +123,8 @@ def test_importorskip(testdir): result = testdir.runpytest("--codeblocks") result.assert_outcomes(skipped=1) + +def test_importorskip2(testdir): string = """ Lorem ipsum From 0a1f0d71a06ef4401371470284607690f40abac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:27:15 +0200 Subject: [PATCH 2/8] add deprecation notes --- src/pytest_codeblocks/main.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pytest_codeblocks/main.py b/src/pytest_codeblocks/main.py index 4ed9895..f0c46e6 100644 --- a/src/pytest_codeblocks/main.py +++ b/src/pytest_codeblocks/main.py @@ -3,6 +3,7 @@ import contextlib import re import sys +import warnings # namedtuple with default arguments # @@ -78,12 +79,17 @@ def extract_from_buffer(f, max_num_lines: int = 10000) -> list[CodeBlock]: continued_block = out[-1] elif keyword == "skip": - # TODO deprecate + warnings.warn( + "pytest-codeblocks:skip is deprecated. Use pytest.mark.skip", + DeprecationWarning, + ) marks.append("pytest.mark.skip") - # out.append(CodeBlock("".join(code_block), lineno, syntax, skip=True)) elif keyword.startswith("skipif"): - # TODO deprecate + warnings.warn( + "pytest-codeblocks:skipif is deprecated. Use pytest.mark.skipif", + DeprecationWarning, + ) m = re.match(r"skipif\((.*)\)", keyword) if m is None: raise RuntimeError( @@ -100,7 +106,10 @@ def extract_from_buffer(f, max_num_lines: int = 10000) -> list[CodeBlock]: importorskip = m.group(1) elif keyword in ["expect-exception", "expect-error"]: - # TODO deprecate + warnings.warn( + f"pytest-codeblocks:{keyword} is deprecated. Use pytest.mark.xfail", + DeprecationWarning, + ) marks.append("pytest.mark.xfail") else: From 86af38c0dba072ba8d536ae0ebd280f66bf509b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:35:10 +0200 Subject: [PATCH 3/8] use new syntax --- README.md | 10 ++++------ tests/example.md | 2 +- tests/test_expect_error.py | 22 +++++++++++----------- tests/test_general.py | 4 ++-- tests/test_shell.py | 4 ++-- tests/test_skipif.py | 12 ++++++------ 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 938e424..f7dab3b 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,12 @@ syntax highlighting. #### Skipping code blocks -Prefix your code block with a `pytest-codeblocks:skip` comment to skip +Prefix your code block with a `pytest.mark.skip` comment to skip ````markdown Lorem ipsum - + ```python foo + bar # not working @@ -66,7 +66,7 @@ dolor sit amet. Conditionally skipping code blocks works with `skipif`, e.g., ```markdown - + ``` You can skip code blocks on import errors with @@ -156,11 +156,9 @@ Some code blocks are expected to give errors. You can verify this with ````markdown The following gives an error: - + ```python 1 / 0 ``` ```` - -The keyword `expect-exception` is also possible. diff --git a/tests/example.md b/tests/example.md index bf3aaf5..c854cad 100644 --- a/tests/example.md +++ b/tests/example.md @@ -21,7 +21,7 @@ A shell script should be exectuted: echo abc ``` Again with an explicit skip: - + ```python bar ``` diff --git a/tests/test_expect_error.py b/tests/test_expect_error.py index 166127f..c4dbf65 100644 --- a/tests/test_expect_error.py +++ b/tests/test_expect_error.py @@ -34,14 +34,14 @@ def test_expect_error_indexerror(testdir): result.assert_outcomes(failed=1) -# def test_expect_error_fail(testdir): -# string1 = """ -# Lorem ipsum -# -# ```python -# 1 + 1 -# ``` -# """ -# testdir.makefile(".md", string1) -# result = testdir.runpytest("--codeblocks") -# result.assert_outcomes(failed=1) +def test_expect_error_fail(testdir): + string1 = """ + Lorem ipsum + + ```python + 1 + 1 + ``` + """ + testdir.makefile(".md", string1) + result = testdir.runpytest("--codeblocks") + result.assert_outcomes(xpassed=1) diff --git a/tests/test_general.py b/tests/test_general.py index d1525e4..4673c02 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -19,7 +19,7 @@ def test_basic(testdir): def test_skip(testdir): string1 = """ Lorem ipsum - + ```python 1 + 2 + 3 ``` @@ -27,7 +27,7 @@ def test_skip(testdir): Some newlines: - + ```python 1 + 2 + 3 diff --git a/tests/test_shell.py b/tests/test_shell.py index 2c227ea..f53607d 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -35,7 +35,7 @@ def test_shell_fail(testdir): def test_shell_expect_fail(testdir): string = """ - + ```sh cdc ``` @@ -47,7 +47,7 @@ def test_shell_expect_fail(testdir): def test_shell_expect_fail_passed(testdir): string = """ - + ```sh cd ``` diff --git a/tests/test_skipif.py b/tests/test_skipif.py index e547666..8348157 100644 --- a/tests/test_skipif.py +++ b/tests/test_skipif.py @@ -2,7 +2,7 @@ def test_skip(testdir): string = """ Lorem ipsum - + ```python print(1 + 3) @@ -17,7 +17,7 @@ def test_skip_expected_output(testdir): string = """ Lorem ipsum - + ```python print(1 + 3) @@ -39,7 +39,7 @@ def test_skipif(testdir): string = """ Lorem ipsum - + ```python print(1 + 3) @@ -54,7 +54,7 @@ def test_skipif2(testdir): string = """ Lorem ipsum - + ```python print(1 + 3) @@ -69,7 +69,7 @@ def test_skipif_expected_output(testdir): string = """ Lorem ipsum - + ```python print(1 + 3) @@ -91,7 +91,7 @@ def test_skipif_expected_output2(testdir): string = """ Lorem ipsum - + ```python print(1 + 3) From 9d7b3c447051f20643e39940cd322a3962e38175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:38:05 +0200 Subject: [PATCH 4/8] readme --- README.md | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f7dab3b..be6c0c9 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,10 @@ README.md ....................... pytest-codeblocks will only pick up code blocks with `python` and `sh`/`bash`/`zsh` syntax highlighting. -#### Skipping code blocks +#### Marking code blocks -Prefix your code block with a `pytest.mark.skip` comment to skip +It is possible to use `pytest.mark` for marking code blocks. For example, +to skip a code block use `pytest.mark.skip` or `pytest.mark.skipif`: ````markdown Lorem ipsum @@ -63,8 +64,6 @@ foo + bar # not working dolor sit amet. ```` -Conditionally skipping code blocks works with `skipif`, e.g., - ```markdown ``` @@ -83,6 +82,18 @@ Skip the entire file by putting in the first line. +For expected errors, use `pytest.mark.xfail`: + +````markdown +The following gives an error: + + + +```python +1 / 0 +``` +```` + #### Merging code blocks Broken-up code blocks can be merged into one with the `pytest-codeblocks:cont` prefix @@ -148,17 +159,3 @@ gives (Conditionally) Skipping the output verfication works by prepending the first block with `skip`/`skipif` (see [above](#skipping-code-blocks)). - -#### Expected errors - -Some code blocks are expected to give errors. You can verify this with - -````markdown -The following gives an error: - - - -```python -1 / 0 -``` -```` From 37ba9be32ec81dce4ea91153ca3b7199bad7bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:39:03 +0200 Subject: [PATCH 5/8] add prettier --- .pre-commit-config.yaml | 5 +++++ tests/example.md | 26 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 479c989..a1e83ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,3 +14,8 @@ repos: rev: 4.0.1 hooks: - id: flake8 + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.6.2 + hooks: + - id: prettier diff --git a/tests/example.md b/tests/example.md index c854cad..13059c5 100644 --- a/tests/example.md +++ b/tests/example.md @@ -1,42 +1,56 @@ ```python 1 + 1 ``` + Lorem ipsum + ```python 1 + 2 + 3 2 + 5 ``` + dolor sit amet. + ```python import pytest_codeblocks pytest_codeblocks.extract_from_buffer ``` + Something that should be skipped because of the language: + ```ruby foobar ``` + A shell script should be exectuted: + ```sh echo abc ``` + Again with an explicit skip: + + ```python bar ``` Something that contains triple fences -```python + +````python # ```import math``` -``` +```` Indented code blocks: - ```python - 1 + 1 == 2 - ``` + +```python +1 + 1 == 2 +``` "Wrong" indentation: + ```python 1 + 1 == 2 - ``` +``` From ad28dee35cc43936b1cb89d873b7c6d8af48197a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:39:20 +0200 Subject: [PATCH 6/8] version bump --- src/pytest_codeblocks/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_codeblocks/__about__.py b/src/pytest_codeblocks/__about__.py index 9da2f8f..5a313cc 100644 --- a/src/pytest_codeblocks/__about__.py +++ b/src/pytest_codeblocks/__about__.py @@ -1 +1 @@ -__version__ = "0.15.0" +__version__ = "0.16.0" From b09fa7ac05b01cb7222bfd487cf3f215787328a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:41:30 +0200 Subject: [PATCH 7/8] use setuptools --- pyproject.toml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e614c71..bcd66ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["flit_core >=3.2,<4"] -build-backend = "flit_core.buildapi" +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" [tool.isort] profile = "black" @@ -12,7 +12,7 @@ description = "Test code blocks in your READMEs" readme = "README.md" license = {file = "LICENSE.txt"} classifiers = [ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Framework :: Pytest", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", @@ -30,6 +30,9 @@ dependencies = [ "pytest >= 7.0.0" ] +[tool.setuptools.dynamic] +version = {attr = "pytest_codeblocks.__about__.__version__"} + [project.urls] Code = "https://github.com/nschloe/pytest-codeblocks" Issues = "https://github.com/nschloe/pytest-codeblocks/issues" From c8902c1cada3a85c9ff2a4ddc4733b9344daf8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Tue, 7 Jun 2022 13:45:57 +0200 Subject: [PATCH 8/8] test fix --- pyproject.toml | 1 + tests/test_general.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bcd66ec..78f4059 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ dependencies = [ version = {attr = "pytest_codeblocks.__about__.__version__"} [project.urls] +Homepage = "https://github.com/nschloe/pytest-codeblocks" Code = "https://github.com/nschloe/pytest-codeblocks" Issues = "https://github.com/nschloe/pytest-codeblocks/issues" Funding = "https://github.com/sponsors/nschloe" diff --git a/tests/test_general.py b/tests/test_general.py index 4673c02..9227bb7 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -42,18 +42,18 @@ def test_skip(testdir): def test_reference(): ref = [ pytest_codeblocks.CodeBlock("1 + 1\n", 1, "python"), - pytest_codeblocks.CodeBlock("1 + 2 + 3\n2 + 5\n", 5, "python"), + pytest_codeblocks.CodeBlock("1 + 2 + 3\n2 + 5\n", 7, "python"), pytest_codeblocks.CodeBlock( "import pytest_codeblocks\n\npytest_codeblocks.extract_from_buffer\n", - 10, + 14, "python", ), - pytest_codeblocks.CodeBlock("foobar\n", 16, "ruby"), - pytest_codeblocks.CodeBlock("echo abc\n", 20, "sh"), - pytest_codeblocks.CodeBlock("bar\n", 25, "python", marks=["pytest.mark.skip"]), - pytest_codeblocks.CodeBlock("# ```import math```\n", 30, "python"), - pytest_codeblocks.CodeBlock("1 + 1 == 2\n", 35, "python"), - pytest_codeblocks.CodeBlock("1 + 1 == 2\n", 40, "python"), + pytest_codeblocks.CodeBlock("foobar\n", 22, "ruby"), + pytest_codeblocks.CodeBlock("echo abc\n", 28, "sh"), + pytest_codeblocks.CodeBlock("bar\n", 36, "python", marks=["pytest.mark.skip"]), + pytest_codeblocks.CodeBlock("# ```import math```\n", 42, "python"), + pytest_codeblocks.CodeBlock("1 + 1 == 2\n", 48, "python"), + pytest_codeblocks.CodeBlock("1 + 1 == 2\n", 54, "python"), ] this_dir = pathlib.Path(__file__).resolve().parent lst = pytest_codeblocks.extract_from_file(this_dir / "example.md")