Skip to content

Increase triple quote search #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 10 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ include = ["/README.md", "/Makefile", "/pytest_examples", "/tests"]

[project]
name = "pytest-examples"
version = "0.0.17"
version = "0.0.18"
description = "Pytest plugin for testing examples in docstrings and markdown files."
authors = [
{name = "Samuel Colvin", email = "s@muelcolvin.com"},
]
authors = [{ name = "Samuel Colvin", email = "s@muelcolvin.com" }]
license = "MIT"
readme = "README.md"
classifiers = [
Expand All @@ -36,11 +34,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
requires-python = ">=3.8"
dependencies = [
"pytest>=7",
"black>=23",
"ruff>=0.5.0",
]
dependencies = ["pytest>=7", "black>=23", "ruff>=0.5.0"]

[project.entry-points.pytest11]
examples = "pytest_examples"
Expand All @@ -49,15 +43,8 @@ examples = "pytest_examples"
repository = "https://github.com/pydantic/pytest-examples"

[dependency-groups]
dev = [
"coverage[toml]>=7.6.1",
"pytest-pretty>=1.2.0",
]
lint = [
"pre-commit>=3.5.0",
"pyright>=1.1.389",
"ruff>=0.7.4",
]
dev = ["coverage[toml]>=7.6.1", "pytest-pretty>=1.2.0"]
lint = ["pre-commit>=3.5.0", "pyright>=1.1.389", "ruff>=0.7.4"]

[tool.pytest.ini_options]
testpaths = ["tests", "example"]
Expand All @@ -67,22 +54,11 @@ xfail_strict = true
[tool.ruff]
line-length = 120
target-version = "py39"
include = [
"pytest_examples/**/*.py",
"tests/**/*.py",
"examples/**/*.py",
]
include = ["pytest_examples/**/*.py", "tests/**/*.py", "examples/**/*.py"]
exclude = ["tests/cases_update/*.py"]

[tool.ruff.lint]
extend-select = [
"Q",
"RUF100",
"C90",
"UP",
"I",
"D",
]
extend-select = ["Q", "RUF100", "C90", "UP", "I", "D"]
flake8-quotes = { inline-quotes = "single", multiline-quotes = "double" }
isort = { combine-as-imports = true, known-first-party = ["pytest_examples"] }
mccabe = { max-complexity = 15 }
Expand Down Expand Up @@ -120,5 +96,8 @@ exclude_lines = [
#typeCheckingMode = "strict"
reportUnnecessaryTypeIgnoreComment = true
reportMissingTypeStubs = false
reportUnusedCallResult = false
reportExplicitAny = false
reportAny = false
include = ["pytest_examples"]
venvPath = ".venv"
8 changes: 4 additions & 4 deletions pytest_examples/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def hash(self) -> str:
return hashlib.md5(str(self).encode()).hexdigest()

def ruff_config(self) -> tuple[str, ...]:
config_lines = []
select = []
ignore = []
args = []
config_lines: list[str] = []
select: list[str] = []
ignore: list[str] = []
args: list[str] = []

# line length is enforced by black
if self.ruff_line_length is None:
Expand Down
4 changes: 2 additions & 2 deletions pytest_examples/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def ruff_check(
stdout, stderr = p.communicate(example.source, timeout=10)
if p.returncode == 1 and stdout:

def replace_offset(m: re.Match):
def replace_offset(m: re.Match[str]):
line_number = int(m.group(1))
return f'{example.path}:{line_number + example.start_line}'

Expand Down Expand Up @@ -88,7 +88,7 @@ def black_check(example: CodeExample, config: ExamplesConfig) -> None:
def code_diff(example: CodeExample, after: str, config: ExamplesConfig) -> str:
diff = black_diff(sub_space(example.source, config), sub_space(after, config), 'before', 'after')

def replace_at_line(match: re.Match) -> str:
def replace_at_line(match: re.Match[str]) -> str:
offset = re.sub(r'\d+', lambda m: str(int(m.group(0)) + example.start_line), match.group(2))
return f'{match.group(1)}{offset}{match.group(3)}'

Expand Down
2 changes: 1 addition & 1 deletion pytest_examples/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def remove_old_print(lines: list[str], line_index: int) -> None:
return

if triple_quotes_prefix_re.search(next_line):
for i in range(2, 100):
for i in range(2, 10_000):
if triple_quotes_prefix_re.search(lines[line_index + i]):
del lines[line_index + 1 : line_index + i + 1]
return
Expand Down
Loading
Loading