pytest-codeblock 0.3.2__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {pytest_codeblock-0.3.2/src/pytest_codeblock.egg-info → pytest_codeblock-0.3.4}/PKG-INFO +1 -1
  2. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/pyproject.toml +1 -1
  3. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/__init__.py +1 -1
  4. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/collector.py +1 -1
  5. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/constants.py +1 -1
  6. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/md.py +23 -7
  7. pytest_codeblock-0.3.4/src/pytest_codeblock/tests/conftest.py +49 -0
  8. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4/src/pytest_codeblock.egg-info}/PKG-INFO +1 -1
  9. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock.egg-info/SOURCES.txt +1 -0
  10. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/LICENSE +0 -0
  11. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/README.rst +0 -0
  12. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/setup.cfg +0 -0
  13. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/helpers.py +0 -0
  14. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/rst.py +0 -0
  15. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/tests/__init__.py +0 -0
  16. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock/tests/test_pytest_codeblock.py +0 -0
  17. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock.egg-info/dependency_links.txt +0 -0
  18. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock.egg-info/entry_points.txt +0 -0
  19. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock.egg-info/requires.txt +0 -0
  20. {pytest_codeblock-0.3.2 → pytest_codeblock-0.3.4}/src/pytest_codeblock.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-codeblock
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Pytest plugin to collect and test code blocks in reStructuredText and Markdown files.
5
5
  Author-email: Artur Barseghyan <artur.barseghyan@gmail.com>
6
6
  Maintainer-email: Artur Barseghyan <artur.barseghyan@gmail.com>
@@ -2,7 +2,7 @@
2
2
  name = "pytest-codeblock"
3
3
  description = "Pytest plugin to collect and test code blocks in reStructuredText and Markdown files."
4
4
  readme = "README.rst"
5
- version = "0.3.2"
5
+ version = "0.3.4"
6
6
  requires-python = ">=3.9"
7
7
  dependencies = [
8
8
  "pytest",
@@ -4,7 +4,7 @@ from .md import MarkdownFile
4
4
  from .rst import RSTFile
5
5
 
6
6
  __title__ = "pytest-codeblock"
7
- __version__ = "0.3.2"
7
+ __version__ = "0.3.4"
8
8
  __author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
9
9
  __copyright__ = "2025-2026 Artur Barseghyan"
10
10
  __license__ = "MIT"
@@ -2,7 +2,7 @@ from dataclasses import dataclass, field
2
2
  from typing import Optional
3
3
 
4
4
  __author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
5
- __copyright__ = "2025 Artur Barseghyan"
5
+ __copyright__ = "2025-2026 Artur Barseghyan"
6
6
  __license__ = "MIT"
7
7
  __all__ = (
8
8
  "CodeSnippet",
@@ -1,5 +1,5 @@
1
1
  __author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
2
- __copyright__ = "2025 Artur Barseghyan"
2
+ __copyright__ = "2025-2026 Artur Barseghyan"
3
3
  __license__ = "MIT"
4
4
  __all__ = (
5
5
  "CODEBLOCK_MARK",
@@ -28,20 +28,22 @@ def parse_markdown(text: str) -> list[CodeSnippet]:
28
28
  Supports:
29
29
  - <!-- pytestmark: <mark> --> comments immediately before a code fence
30
30
  - <!-- codeblock-name: <name> --> comments for naming
31
+ - <!-- continue: <name> --> comments for grouping with a named snippet
31
32
  - Fenced code blocks with ```python (and optional name=<name> in the
32
33
  info string)
33
34
 
34
- Captures each snippets name, code, starting line, and any pytest marks.
35
+ Captures each snippet's name, code, starting line, and any pytest marks.
35
36
  """
36
- snippets: list[CodeSnippet] = []
37
+ snippets: list[CodeSnippet] = []
37
38
  lines = text.splitlines()
38
- pending_name: Optional[str] = None
39
+ pending_name: Optional[str] = None
40
+ pending_continue: Optional[str] = None
39
41
  pending_marks: list[str] = [CODEBLOCK_MARK]
40
42
  pending_fixtures: list[str] = []
41
43
  in_block = False
42
44
  fence = ""
43
45
  block_indent = 0
44
- code_buffer: list[str] = []
46
+ code_buffer: list[str] = []
45
47
  snippet_name: Optional[str] = None
46
48
  start_line = 0
47
49
 
@@ -63,6 +65,13 @@ def parse_markdown(text: str) -> list[CodeSnippet]:
63
65
  pending_fixtures.append(m.group(1))
64
66
  continue
65
67
 
68
+ # Check for continue comment
69
+ if stripped.startswith("<!--") and "continue:" in stripped:
70
+ m = re.match(r"<!--\s*continue:\s*(\S+)\s*-->", stripped)
71
+ if m:
72
+ pending_continue = m.group(1)
73
+ continue
74
+
66
75
  # Check for name comment
67
76
  if stripped.startswith("<!--") and "codeblock-name:" in stripped:
68
77
  m = re.match(
@@ -113,16 +122,23 @@ def parse_markdown(text: str) -> list[CodeSnippet]:
113
122
  # end of block
114
123
  in_block = False
115
124
  code_text = "\n".join(code_buffer)
125
+ # continue overrides snippet_name for grouping
126
+ if pending_continue:
127
+ final_name = pending_continue
128
+ pending_continue = None
129
+ else:
130
+ final_name = snippet_name
116
131
  snippets.append(CodeSnippet(
117
- name=snippet_name,
132
+ name=final_name,
118
133
  code=code_text,
119
134
  line=start_line,
120
135
  marks=pending_marks.copy(),
121
136
  fixtures=pending_fixtures.copy(),
122
137
  ))
123
138
  # reset pending marks after collecting
124
- pending_marks.clear()
139
+ pending_marks = [CODEBLOCK_MARK] # Reset to default
125
140
  snippet_name = None
141
+ pending_fixtures.clear() # Clear pending fixtures
126
142
  else:
127
143
  # collect code lines (dedent by block_indent)
128
144
  if line.strip() == "":
@@ -157,7 +173,7 @@ class MarkdownFile(pytest.File):
157
173
  _fpath = str(self.path)
158
174
 
159
175
  # Build list of fixture names requested by this snippet
160
- _fixture_names: list[str] = list(sn.fixtures)
176
+ _fixture_names: list[str] = list(sn.fixtures)
161
177
 
162
178
  # If snippet is marked as needing DB, also request the `db`
163
179
  # fixture, unless user already added it explicitly.
@@ -0,0 +1,49 @@
1
+ from types import SimpleNamespace
2
+
3
+ import pytest
4
+
5
+ __author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
6
+ __copyright__ = "2025-2026 Artur Barseghyan"
7
+ __license__ = "MIT"
8
+ __all__ = (
9
+ "http_request_factory",
10
+ "http_request",
11
+ "markdown_simple",
12
+ "markdown_with_pytest_mark",
13
+ )
14
+
15
+
16
+ @pytest.fixture
17
+ def http_request_factory():
18
+ """
19
+ Returns a function that creates a simple namespace object
20
+ with a 'GET' attribute set to the provided dictionary.
21
+ """
22
+ def _factory(get_data: dict):
23
+ # Creates an object like: object(GET={'key': 'value'})
24
+ return SimpleNamespace(GET=get_data)
25
+ return _factory
26
+
27
+
28
+ @pytest.fixture
29
+ def http_request(http_request_factory):
30
+ test_data = {"param1": "value1", "signature": "mock-sig"}
31
+ return http_request_factory(test_data)
32
+
33
+
34
+ @pytest.fixture
35
+ def markdown_simple():
36
+ return """
37
+ ```python name=test_example
38
+ x=1
39
+ assert x==1
40
+ ```"""
41
+
42
+
43
+ @pytest.fixture
44
+ def markdown_with_pytest_mark():
45
+ return """
46
+ <!-- pytestmark: django_db -->
47
+ ```python name=test_db
48
+ from django.db import models
49
+ ```"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-codeblock
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Pytest plugin to collect and test code blocks in reStructuredText and Markdown files.
5
5
  Author-email: Artur Barseghyan <artur.barseghyan@gmail.com>
6
6
  Maintainer-email: Artur Barseghyan <artur.barseghyan@gmail.com>
@@ -14,4 +14,5 @@ src/pytest_codeblock.egg-info/entry_points.txt
14
14
  src/pytest_codeblock.egg-info/requires.txt
15
15
  src/pytest_codeblock.egg-info/top_level.txt
16
16
  src/pytest_codeblock/tests/__init__.py
17
+ src/pytest_codeblock/tests/conftest.py
17
18
  src/pytest_codeblock/tests/test_pytest_codeblock.py