Skip to content

Commit 63b92c8

Browse files
committed
revert comment, improve script
1 parent a6bd920 commit 63b92c8

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

pydantic_evals/pydantic_evals/generation.py

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async def generate_dataset(
5959
"""
6060
output_schema = dataset_type.model_json_schema_with_evaluators(custom_evaluator_types)
6161

62+
# TODO(DavidM): Update this once we add better response_format and/or ResultTool support to PydanticAI
6263
agent = Agent(
6364
model,
6465
system_prompt=(

tests/wrong_coverage.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ def main() -> int:
1515
with NamedTemporaryFile(mode='w', suffix='.toml') as config_file:
1616
config_file.write(f"[tool.coverage.report]\nexclude_lines = ['{EXCLUDE_COMMENT}']\n")
1717
config_file.flush()
18-
subprocess.run(
18+
p = subprocess.run(
1919
['uv', 'run', 'coverage', 'json', f'--rcfile={config_file.name}', '-o', coverage_json.name],
20-
check=True,
20+
stdout=subprocess.PIPE,
2121
)
22+
if p.returncode != 0:
23+
print(f'Error running coverage: {p.stderr.decode()}', file=sys.stderr)
24+
return p.returncode
2225

2326
r = CoverageReport.model_validate_json(coverage_json.read())
2427

@@ -40,13 +43,11 @@ def add_block(start: int, end: int):
4043
if code_analysise is None:
4144
code_analysise = CodeAnalyzer(file_name)
4245

43-
if all(code_analysise.is_expression_start(line_no) for line_no in range(start, end + 1)):
44-
return
45-
46-
b = str(start) if start == end else f'{start}-{end}'
47-
if not blocks or blocks[-1] != b:
48-
total_lines += end - start + 1
49-
blocks.append(f' [link=file://{cwd / file_name}]{file_name} {b}[/link]')
46+
if not code_analysise.all_block_openings(start, end):
47+
b = str(start) if start == end else f'{start}-{end}'
48+
if not blocks or blocks[-1] != b:
49+
total_lines += end - start + 1
50+
blocks.append(f' [link=file://{cwd / file_name}]{file_name} {b}[/link]')
5051

5152
first_line, *rest = common_lines
5253
current_start = current_end = first_line
@@ -98,7 +99,9 @@ class CoverageReport(BaseModel):
9899
files: dict[str, FileCoverage]
99100

100101

101-
EXPRESSION_START_REGEX = re.compile(r'\s*(?:def|async def|@|class|if|elif|else)')
102+
# python expressions that can open blocks so can have the `# pragma: no cover` comment on them
103+
# even though they're covered
104+
BLOCK_OPENINGS = re.compile(r'\s*(?:def|async def|@|class|if|elif|else)')
102105

103106

104107
class CodeAnalyzer:
@@ -107,9 +110,11 @@ def __init__(self, file_path: str) -> None:
107110
content = f.read()
108111
self.lines: dict[int, str] = dict(enumerate(content.splitlines(), start=1))
109112

110-
def is_expression_start(self, line_no: int) -> bool:
111-
line = self.lines[line_no]
112-
return bool(EXPRESSION_START_REGEX.match(line))
113+
def all_block_openings(self, start: int, end: int) -> bool:
114+
return all(self._is_block_opening(line_no) for line_no in range(start, end + 1))
115+
116+
def _is_block_opening(self, line_no: int) -> bool:
117+
return bool(BLOCK_OPENINGS.match(self.lines[line_no]))
113118

114119

115120
if __name__ == '__main__':

0 commit comments

Comments
 (0)