reeval-python 0.10.0__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.
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ *.egg-info/
5
+ dist/
6
+ .venv/
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.10.0](https://github.com/invertase/reeval/compare/reeval-python-v0.9.0...reeval-python-v0.10.0) (2026-10-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * **language-runner:** LanguageAdapter with Python eval SDK ([#380](https://github.com/invertase/reeval/issues/380)) ([a15d9cb](https://github.com/invertase/reeval/commit/a15d9cb917843532c3a127f2f8c024eba59fa966))
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Invertase Limited
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.5
2
+ Name: reeval-python
3
+ Version: 0.10.0
4
+ Summary: Python authoring SDK for reeval (*.eval.py eval files)
5
+ Project-URL: Homepage, https://reeval.ai
6
+ Project-URL: Repository, https://github.com/invertase/reeval
7
+ Project-URL: Documentation, https://github.com/invertase/reeval/tree/main/packages/reeval-python#readme
8
+ Project-URL: Issues, https://github.com/invertase/reeval/issues
9
+ Author: Invertase
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Testing
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+
24
+ # reeval-python
25
+
26
+ Python authoring SDK for [reeval](https://github.com/invertase/reeval). Write `*.eval.py` files,
27
+ declare evals with the same options as TypeScript, and run them through reeval's language runner
28
+ (loopback TCP, attempt protocol v2).
29
+
30
+ Import as `reeval_python` (`from reeval_python import evaluate`). The PyPI distribution is
31
+ **reeval-python** (the name `reeval` is already taken on PyPI by another project).
32
+
33
+ With reeval installed, default discovery includes `evals/**/*.eval.py`. When your project has
34
+ `pyproject.toml` or `uv.lock` and [uv](https://docs.astral.sh/uv/) is on `PATH`, reeval starts the
35
+ runner with `uv run --project <root> python -m reeval_python`. Otherwise it uses `<root>/.venv/bin/python`
36
+ when present, then `python3`. Set `REEVAL_PYTHON` to override the interpreter.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ uv add reeval-python
42
+ # or: pip install reeval-python
43
+ ```
44
+
45
+ Monorepo development:
46
+
47
+ ```bash
48
+ cd packages/reeval-python
49
+ uv sync --dev
50
+ uv run pytest
51
+ uv run ruff check .
52
+ uv run pyright
53
+ ```
54
+
55
+ Declare trees are checked against `packages/reeval/test/conformance/declare/` goldens. From the
56
+ reeval package, `test/python-sdk.test.ts` runs the same suite in CI.
57
+
58
+ ## Writing evals
59
+
60
+ ```python
61
+ from reeval_python import evaluate, expect
62
+
63
+
64
+ @evaluate("lands")
65
+ def lands(c):
66
+ c.send("Create greet.py that prints hi")
67
+ assert c.exec("test -f greet.py").ok
68
+ expect(c.judge("Does greet.py print hi?")).to_pass()
69
+ ```
70
+
71
+ Plain `assert` is first-class: failures become hard checks in the run record (same shape as
72
+ TypeScript). Use typed results (`ExecResult.ok`, `Verdict.passed`, `Turn.text`, …) and `c.file(path)`
73
+ for quick checks. Keep `expect` for reeval matchers (`to_have_file`, `to_succeed`, soft checks,
74
+ labels) — Playwright-style.
75
+
76
+ Use snake_case on the context (`read_file`, `write_file`, `file`) and on matchers (`to_succeed`,
77
+ `to_pass`, `to_equal`, `to_contain`, …). Matcher failures raise `ReevalAssertionError`. Async bodies use
78
+ `async def`, `await c.send(...)`, and `await expect(await c.exec(...)).to_succeed()`; sync bodies
79
+ use plain `def` and block on the runner loop.
80
+
81
+ ## Examples
82
+
83
+ - Feature smoke: `packages/reeval/test/features/python-sdk/hello/` (uv project with a project dependency)
84
+ - Plan case: `packages/reeval/test/plan/python/`
85
+ - Contributor guide: `.agents/skills/add-a-language/SKILL.md` in the reeval repo
@@ -0,0 +1,62 @@
1
+ # reeval-python
2
+
3
+ Python authoring SDK for [reeval](https://github.com/invertase/reeval). Write `*.eval.py` files,
4
+ declare evals with the same options as TypeScript, and run them through reeval's language runner
5
+ (loopback TCP, attempt protocol v2).
6
+
7
+ Import as `reeval_python` (`from reeval_python import evaluate`). The PyPI distribution is
8
+ **reeval-python** (the name `reeval` is already taken on PyPI by another project).
9
+
10
+ With reeval installed, default discovery includes `evals/**/*.eval.py`. When your project has
11
+ `pyproject.toml` or `uv.lock` and [uv](https://docs.astral.sh/uv/) is on `PATH`, reeval starts the
12
+ runner with `uv run --project <root> python -m reeval_python`. Otherwise it uses `<root>/.venv/bin/python`
13
+ when present, then `python3`. Set `REEVAL_PYTHON` to override the interpreter.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ uv add reeval-python
19
+ # or: pip install reeval-python
20
+ ```
21
+
22
+ Monorepo development:
23
+
24
+ ```bash
25
+ cd packages/reeval-python
26
+ uv sync --dev
27
+ uv run pytest
28
+ uv run ruff check .
29
+ uv run pyright
30
+ ```
31
+
32
+ Declare trees are checked against `packages/reeval/test/conformance/declare/` goldens. From the
33
+ reeval package, `test/python-sdk.test.ts` runs the same suite in CI.
34
+
35
+ ## Writing evals
36
+
37
+ ```python
38
+ from reeval_python import evaluate, expect
39
+
40
+
41
+ @evaluate("lands")
42
+ def lands(c):
43
+ c.send("Create greet.py that prints hi")
44
+ assert c.exec("test -f greet.py").ok
45
+ expect(c.judge("Does greet.py print hi?")).to_pass()
46
+ ```
47
+
48
+ Plain `assert` is first-class: failures become hard checks in the run record (same shape as
49
+ TypeScript). Use typed results (`ExecResult.ok`, `Verdict.passed`, `Turn.text`, …) and `c.file(path)`
50
+ for quick checks. Keep `expect` for reeval matchers (`to_have_file`, `to_succeed`, soft checks,
51
+ labels) — Playwright-style.
52
+
53
+ Use snake_case on the context (`read_file`, `write_file`, `file`) and on matchers (`to_succeed`,
54
+ `to_pass`, `to_equal`, `to_contain`, …). Matcher failures raise `ReevalAssertionError`. Async bodies use
55
+ `async def`, `await c.send(...)`, and `await expect(await c.exec(...)).to_succeed()`; sync bodies
56
+ use plain `def` and block on the runner loop.
57
+
58
+ ## Examples
59
+
60
+ - Feature smoke: `packages/reeval/test/features/python-sdk/hello/` (uv project with a project dependency)
61
+ - Plan case: `packages/reeval/test/plan/python/`
62
+ - Contributor guide: `.agents/skills/add-a-language/SKILL.md` in the reeval repo
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "reeval-python",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "description": "Python authoring SDK for reeval (*.eval.py); npm private workspace helper only"
6
+ }
@@ -0,0 +1,59 @@
1
+ [project]
2
+ name = "reeval-python"
3
+ version = "0.10.0"
4
+ description = "Python authoring SDK for reeval (*.eval.py eval files)"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ authors = [{ name = "Invertase" }]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: Apache Software License",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Topic :: Software Development :: Testing",
19
+ "Typing :: Typed",
20
+ ]
21
+ dependencies = []
22
+
23
+ [project.urls]
24
+ Homepage = "https://reeval.ai"
25
+ Repository = "https://github.com/invertase/reeval"
26
+ Documentation = "https://github.com/invertase/reeval/tree/main/packages/reeval-python#readme"
27
+ Issues = "https://github.com/invertase/reeval/issues"
28
+
29
+ [dependency-groups]
30
+ dev = [
31
+ "pytest>=8.0",
32
+ "ruff>=0.9",
33
+ "pyright>=1.1",
34
+ ]
35
+
36
+ [tool.pytest.ini_options]
37
+ testpaths = ["tests"]
38
+ pythonpath = ["."]
39
+
40
+ [tool.ruff]
41
+ line-length = 100
42
+ target-version = "py311"
43
+
44
+ [tool.ruff.lint]
45
+ select = ["E", "F", "I", "UP", "B"]
46
+
47
+ [tool.pyright]
48
+ include = ["src"]
49
+ exclude = ["tests"]
50
+ typeCheckingMode = "strict"
51
+ pythonVersion = "3.11"
52
+ reportUnknownLambdaType = false
53
+
54
+ [build-system]
55
+ requires = ["hatchling"]
56
+ build-backend = "hatchling.build"
57
+
58
+ [tool.hatch.build.targets.wheel]
59
+ packages = ["src/reeval_python"]
@@ -0,0 +1,23 @@
1
+ """Python eval authoring API for reeval (*.eval.py)."""
2
+
3
+ from reeval_python.context import AttemptContext, SyncAttemptContext
4
+ from reeval_python.declare import collect_module_tree, evaluate, group, reset_collector
5
+ from reeval_python.errors import ReevalAssertionError
6
+ from reeval_python.expect import expect, soft
7
+ from reeval_python.types import BackgroundHandle, ExecResult, Turn, Verdict
8
+
9
+ __all__ = [
10
+ "AttemptContext",
11
+ "BackgroundHandle",
12
+ "ExecResult",
13
+ "ReevalAssertionError",
14
+ "SyncAttemptContext",
15
+ "Turn",
16
+ "Verdict",
17
+ "collect_module_tree",
18
+ "evaluate",
19
+ "expect",
20
+ "group",
21
+ "reset_collector",
22
+ "soft",
23
+ ]
@@ -0,0 +1,4 @@
1
+ from reeval_python.runner import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,168 @@
1
+ """Turn plain Python assert failures into attempt-protocol expect calls."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+ import linecache
7
+ from dataclasses import dataclass
8
+ from types import FrameType
9
+ from typing import Any
10
+
11
+
12
+ @dataclass(frozen=True, slots=True)
13
+ class AssertExpect:
14
+ subject: dict[str, Any]
15
+ matcher: str
16
+ args: list[Any]
17
+ label: str | None
18
+ not_: bool = False
19
+
20
+
21
+ @dataclass(frozen=True, slots=True)
22
+ class _EvalFrame:
23
+ filename: str
24
+ lineno: int
25
+ frame: FrameType
26
+
27
+
28
+ def _safe_eval(node: ast.expr, frame: FrameType) -> Any:
29
+ code = compile(ast.Expression(node), "<assert>", "eval")
30
+ return eval(code, frame.f_globals, frame.f_locals) # noqa: S307
31
+
32
+
33
+ def _show(value: Any) -> str:
34
+ try:
35
+ return repr(value)
36
+ except Exception: # noqa: BLE001
37
+ return "<unrepr>"
38
+
39
+
40
+ def _frame_for_assert(exc: BaseException) -> _EvalFrame | None:
41
+ tb = exc.__traceback__
42
+ found: _EvalFrame | None = None
43
+ while tb is not None:
44
+ if tb.tb_frame.f_code.co_filename.endswith(".eval.py"):
45
+ found = _EvalFrame(tb.tb_frame.f_code.co_filename, tb.tb_lineno, tb.tb_frame)
46
+ tb = tb.tb_next
47
+ return found
48
+
49
+
50
+ def _parse_assert_line(source: str, lineno: int, filename: str) -> ast.Assert | None:
51
+ try:
52
+ tree = ast.parse(source, mode="exec")
53
+ except SyntaxError:
54
+ tree = None
55
+ if tree is not None:
56
+ for node in ast.walk(tree):
57
+ if isinstance(node, ast.Assert) and node.lineno == lineno:
58
+ return node
59
+ line = linecache.getline(filename, lineno).strip()
60
+ if not line.startswith("assert"):
61
+ return None
62
+ try:
63
+ parsed = ast.parse(line)
64
+ except SyntaxError:
65
+ return None
66
+ stmt = parsed.body[0] if parsed.body else None
67
+ return stmt if isinstance(stmt, ast.Assert) else None
68
+
69
+
70
+ def _label_from_assert(node: ast.Assert, exc: AssertionError) -> str | None:
71
+ if node.msg is not None:
72
+ try:
73
+ if isinstance(node.msg, ast.Constant) and isinstance(node.msg.value, str):
74
+ return node.msg.value
75
+ except Exception: # noqa: BLE001
76
+ pass
77
+ if exc.args and isinstance(exc.args[0], str):
78
+ return exc.args[0]
79
+ return None
80
+
81
+
82
+ def _wire_for_test(test: ast.expr, frame: FrameType, label: str | None) -> AssertExpect:
83
+ if isinstance(test, ast.Compare) and len(test.ops) == 1 and len(test.comparators) == 1:
84
+ op = test.ops[0]
85
+ left = _safe_eval(test.left, frame)
86
+ right = _safe_eval(test.comparators[0], frame)
87
+ if isinstance(op, ast.Eq):
88
+ enriched = label or f"assert {_show(left)} == {_show(right)}"
89
+ return AssertExpect(
90
+ subject={"value": left},
91
+ matcher="toEqual",
92
+ args=[right],
93
+ label=enriched,
94
+ )
95
+ if isinstance(op, ast.Is):
96
+ enriched = label or f"assert {_show(left)} is {_show(right)}"
97
+ return AssertExpect(
98
+ subject={"value": left},
99
+ matcher="toBe",
100
+ args=[right],
101
+ label=enriched,
102
+ )
103
+ if isinstance(op, ast.IsNot):
104
+ enriched = label or f"assert {_show(left)} is not {_show(right)}"
105
+ return AssertExpect(
106
+ subject={"value": left},
107
+ matcher="toBe",
108
+ args=[right],
109
+ label=enriched,
110
+ not_=True,
111
+ )
112
+
113
+ if isinstance(test, ast.Constant) and test.value is False:
114
+ return AssertExpect(
115
+ subject={"value": False},
116
+ matcher="toBeTruthy",
117
+ args=[],
118
+ label=label or "assert False",
119
+ )
120
+
121
+ actual = _safe_eval(test, frame)
122
+ enriched = label
123
+ if enriched is None:
124
+ enriched = f"assert {_show(actual)}"
125
+ elif not actual:
126
+ enriched = f"{enriched} ({_show(actual)} is falsy)"
127
+ return AssertExpect(
128
+ subject={"value": actual},
129
+ matcher="toBeTruthy",
130
+ args=[],
131
+ label=enriched,
132
+ )
133
+
134
+
135
+ def assert_to_expect(exc: AssertionError) -> AssertExpect:
136
+ frame = _frame_for_assert(exc)
137
+ if frame is None:
138
+ msg = str(exc) if str(exc) else "assertion failed"
139
+ return AssertExpect(
140
+ subject={"value": False},
141
+ matcher="toBeTruthy",
142
+ args=[],
143
+ label=msg,
144
+ )
145
+
146
+ source = linecache.getlines(frame.filename)
147
+ if not source:
148
+ msg = str(exc) if str(exc) else "assertion failed"
149
+ return AssertExpect(
150
+ subject={"value": False},
151
+ matcher="toBeTruthy",
152
+ args=[],
153
+ label=msg,
154
+ )
155
+
156
+ block = "".join(source)
157
+ node = _parse_assert_line(block, frame.lineno, frame.filename)
158
+ if node is None:
159
+ msg = str(exc) if str(exc) else "assertion failed"
160
+ return AssertExpect(
161
+ subject={"value": False},
162
+ matcher="toBeTruthy",
163
+ args=[],
164
+ label=msg,
165
+ )
166
+
167
+ label = _label_from_assert(node, exc)
168
+ return _wire_for_test(node.test, frame.frame, label)