inspect-test-utils 0.2.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,210 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ # Inspect AI
210
+ logs
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 METR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: inspect-test-utils
3
+ Version: 0.2.0
4
+ Summary: Simple models and tasks for integration testing
5
+ Project-URL: Repository, https://github.com/METR/inspect-test-utils
6
+ Project-URL: Issues, https://github.com/METR/inspect-test-utils/issues
7
+ Author-email: METR <rasmus.faber-espensen@metr.org>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: inspect-ai
20
+ Requires-Dist: inspect-scout
21
+ Requires-Dist: pytest>=8.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: basedpyright; extra == 'dev'
24
+ Requires-Dist: pytest; extra == 'dev'
25
+ Requires-Dist: pytest-asyncio; extra == 'dev'
26
+ Requires-Dist: pytest-mock; extra == 'dev'
27
+ Requires-Dist: ruff; extra == 'dev'
28
+ Requires-Dist: types-aiofiles; extra == 'dev'
29
+ Requires-Dist: types-pyyaml; extra == 'dev'
30
+ Requires-Dist: types-requests; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ inspect-test-utils
34
+
35
+ A small collection of tasks, scorers, and a simple model for use with the Inspect AI framework. It is designed to support integration/acceptance tests, demos, and reproductions by providing:
36
+ - Ready-made Tasks that exercise common evaluation patterns (simple generation, numeric closeness, failure injection, and sandbox configuration).
37
+ - Scorers for deterministic or parameterized scoring (including hardcoded outputs and a logarithmic closeness score).
38
+ - A hardcoded ModelAPI implementation that can deterministically emit tool calls and/or final answers, useful for testing tool-calling flows without hitting external APIs.
39
+
40
+ Passing arguments
41
+ Most tasks and the hardcoded model accept parameters. With the Inspect CLI you can pass them via --task-arg and --model-arg repeatedly:
42
+ - Example: make the task generate 3 samples and set a numeric target for guessing:
43
+ inspect eval inspect_test_utils/guess_number \
44
+ --task-arg sample_count=3 \
45
+ --task-arg target=42.7 \
46
+ --model hardcoded --model-arg answer=42.6
47
+
48
+ What’s included
49
+ - Tasks (inspect_test_utils.tasks)
50
+ - say_hello(sample_count=1): Simple task; expects a response that includes "hello".
51
+ - guess_number(sample_count=1, target="42.7"): Uses a logarithmic closeness scorer for numeric answers.
52
+ - hardcoded_score(sample_count=10, hardcoded_score=None, hardcoded_score_by_sample_id_and_epoch=None): Scores are injected from parameters; useful for testing aggregations and edge cases (including NaN).
53
+ - sometimes_fails_setup(sample_count=10, fail_setup_on_epochs=None, failure_rate=0.2): Randomly raises during setup via a failing solver; useful to test retry/resume behavior.
54
+ - sometimes_fails_scoring(sample_count=10, fail_score_on_epochs=None, failure_rate=0.2): Randomly raises during scoring; useful to test scorer error handling.
55
+ - configurable_sandbox(sample_count=1, cpu=0.5, memory="2G", storage="2G", gpu=None, gpu_model=None, allow_internet=False): A task with runtime configurable sandbox.
56
+
57
+ - Scorers (inspect_test_utils.scorers)
58
+ - failing_scorer(fail_on_epochs=None, failure_rate=0.2): Raises errors at a controlled rate for selected epochs.
59
+ - closeness_log(): Scores 1.0 for exact equality, otherwise 1/(1+log1p(relative_error)) for numeric strings.
60
+ - hardcoded_scorer(hardcoded_score=None, hardcoded_score_by_sample_id_and_epoch=None): Returns pre-specified Score objects or looks them up by sample id and epoch.
61
+
62
+ - Model (inspect_test_utils.hardcoded)
63
+ - hardcoded: A ModelAPI that can emit a sequence of tool calls (e.g., bash) for a number of repetitions and then submit a final answer.
64
+ Parameters include:
65
+ - answer: final answer string (default: "done").
66
+ - repetitions: how many tool-call "turns" before submitting.
67
+ - tool_calls: list of tool calls or shell strings (e.g., ["echo hi", "ls -la"]) to simulate; defaults to none.
68
+ - delay: optional delay (seconds) before returning each model output.
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ pip install inspect-test-utils
74
+ ```
75
+
76
+ ## License
77
+
78
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,46 @@
1
+ inspect-test-utils
2
+
3
+ A small collection of tasks, scorers, and a simple model for use with the Inspect AI framework. It is designed to support integration/acceptance tests, demos, and reproductions by providing:
4
+ - Ready-made Tasks that exercise common evaluation patterns (simple generation, numeric closeness, failure injection, and sandbox configuration).
5
+ - Scorers for deterministic or parameterized scoring (including hardcoded outputs and a logarithmic closeness score).
6
+ - A hardcoded ModelAPI implementation that can deterministically emit tool calls and/or final answers, useful for testing tool-calling flows without hitting external APIs.
7
+
8
+ Passing arguments
9
+ Most tasks and the hardcoded model accept parameters. With the Inspect CLI you can pass them via --task-arg and --model-arg repeatedly:
10
+ - Example: make the task generate 3 samples and set a numeric target for guessing:
11
+ inspect eval inspect_test_utils/guess_number \
12
+ --task-arg sample_count=3 \
13
+ --task-arg target=42.7 \
14
+ --model hardcoded --model-arg answer=42.6
15
+
16
+ What’s included
17
+ - Tasks (inspect_test_utils.tasks)
18
+ - say_hello(sample_count=1): Simple task; expects a response that includes "hello".
19
+ - guess_number(sample_count=1, target="42.7"): Uses a logarithmic closeness scorer for numeric answers.
20
+ - hardcoded_score(sample_count=10, hardcoded_score=None, hardcoded_score_by_sample_id_and_epoch=None): Scores are injected from parameters; useful for testing aggregations and edge cases (including NaN).
21
+ - sometimes_fails_setup(sample_count=10, fail_setup_on_epochs=None, failure_rate=0.2): Randomly raises during setup via a failing solver; useful to test retry/resume behavior.
22
+ - sometimes_fails_scoring(sample_count=10, fail_score_on_epochs=None, failure_rate=0.2): Randomly raises during scoring; useful to test scorer error handling.
23
+ - configurable_sandbox(sample_count=1, cpu=0.5, memory="2G", storage="2G", gpu=None, gpu_model=None, allow_internet=False): A task with runtime configurable sandbox.
24
+
25
+ - Scorers (inspect_test_utils.scorers)
26
+ - failing_scorer(fail_on_epochs=None, failure_rate=0.2): Raises errors at a controlled rate for selected epochs.
27
+ - closeness_log(): Scores 1.0 for exact equality, otherwise 1/(1+log1p(relative_error)) for numeric strings.
28
+ - hardcoded_scorer(hardcoded_score=None, hardcoded_score_by_sample_id_and_epoch=None): Returns pre-specified Score objects or looks them up by sample id and epoch.
29
+
30
+ - Model (inspect_test_utils.hardcoded)
31
+ - hardcoded: A ModelAPI that can emit a sequence of tool calls (e.g., bash) for a number of repetitions and then submit a final answer.
32
+ Parameters include:
33
+ - answer: final answer string (default: "done").
34
+ - repetitions: how many tool-call "turns" before submitting.
35
+ - tool_calls: list of tool calls or shell strings (e.g., ["echo hi", "ls -la"]) to simulate; defaults to none.
36
+ - delay: optional delay (seconds) before returning each model output.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install inspect-test-utils
42
+ ```
43
+
44
+ ## License
45
+
46
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,37 @@
1
+ """Reusable testing framework for Inspect AI evaluation tasks.
2
+
3
+ This framework provides:
4
+ - Model-level mocking (HardcodedModelAPI)
5
+ - Solver-level hardcoded execution
6
+ - Test scorers and tasks
7
+ - Pytest fixtures and assertion helpers
8
+ - Eval runner for integration tests
9
+ """
10
+
11
+ from inspect_test_utils.assertions import (
12
+ assert_contains,
13
+ assert_eval_score,
14
+ assert_files_exist,
15
+ assert_score_in_range,
16
+ )
17
+ from inspect_test_utils.eval_runner import (
18
+ EvalTestResult,
19
+ run_eval_test,
20
+ )
21
+ from inspect_test_utils.solvers import (
22
+ hardcoded_bash_solver,
23
+ hardcoded_python_solver,
24
+ inspection_solver,
25
+ )
26
+
27
+ __all__ = [
28
+ "assert_contains",
29
+ "assert_eval_score",
30
+ "assert_files_exist",
31
+ "assert_score_in_range",
32
+ "EvalTestResult",
33
+ "hardcoded_bash_solver",
34
+ "hardcoded_python_solver",
35
+ "inspection_solver",
36
+ "run_eval_test",
37
+ ]
@@ -0,0 +1,39 @@
1
+ from inspect_test_utils.hardcoded import hardcoded
2
+ from inspect_test_utils.mockllm import mockllm_wrapper
3
+ from inspect_test_utils.scanners import (
4
+ model_roles_scanner,
5
+ suspicious_behaviour,
6
+ word_counter,
7
+ )
8
+ from inspect_test_utils.tasks import (
9
+ configurable_sandbox,
10
+ guess_number,
11
+ guess_number_keep_guessing,
12
+ hardcoded_score,
13
+ network_sandbox,
14
+ say_hello,
15
+ say_hello_with_tools,
16
+ sometimes_fails_scoring,
17
+ sometimes_fails_setup,
18
+ timeout,
19
+ uses_model_roles,
20
+ )
21
+
22
+ __all__ = [
23
+ "configurable_sandbox",
24
+ "guess_number",
25
+ "guess_number_keep_guessing",
26
+ "hardcoded",
27
+ "hardcoded_score",
28
+ "mockllm_wrapper",
29
+ "model_roles_scanner",
30
+ "network_sandbox",
31
+ "say_hello",
32
+ "say_hello_with_tools",
33
+ "sometimes_fails_scoring",
34
+ "sometimes_fails_setup",
35
+ "suspicious_behaviour",
36
+ "timeout",
37
+ "uses_model_roles",
38
+ "word_counter",
39
+ ]
@@ -0,0 +1,114 @@
1
+ """Assertion helpers for Inspect AI evaluation tests.
2
+
3
+ These functions provide convenient assertions for common test patterns.
4
+ """
5
+
6
+ from typing import TYPE_CHECKING
7
+
8
+ if TYPE_CHECKING:
9
+ from inspect_test_utils.eval_runner import EvalTestResult
10
+
11
+
12
+ def assert_eval_score(
13
+ result: "EvalTestResult",
14
+ expected: float,
15
+ tolerance: float = 0.01,
16
+ *,
17
+ message: str | None = None,
18
+ ) -> None:
19
+ """Assert that the eval score matches the expected value.
20
+
21
+ Args:
22
+ result: The EvalTestResult from run_eval_test.
23
+ expected: Expected score value.
24
+ tolerance: Acceptable deviation from expected score.
25
+ message: Optional custom failure message.
26
+
27
+ Raises:
28
+ AssertionError: If score doesn't match within tolerance.
29
+ """
30
+ actual = result.score
31
+ if actual is None:
32
+ raise AssertionError(f"No score returned. Error: {result.error}")
33
+
34
+ if abs(actual - expected) > tolerance:
35
+ msg = message or f"Expected score {expected}, got {actual}"
36
+ if result.explanation:
37
+ msg += f"\nExplanation: {result.explanation}"
38
+ raise AssertionError(msg)
39
+
40
+
41
+ def assert_score_in_range(
42
+ result: "EvalTestResult",
43
+ min_score: float,
44
+ max_score: float,
45
+ *,
46
+ message: str | None = None,
47
+ ) -> None:
48
+ """Assert that the eval score is within a range.
49
+
50
+ Args:
51
+ result: The EvalTestResult from run_eval_test.
52
+ min_score: Minimum acceptable score (inclusive).
53
+ max_score: Maximum acceptable score (inclusive).
54
+ message: Optional custom failure message.
55
+
56
+ Raises:
57
+ AssertionError: If score is outside the range.
58
+ """
59
+ actual = result.score
60
+ if actual is None:
61
+ raise AssertionError(f"No score returned. Error: {result.error}")
62
+
63
+ if not (min_score <= actual <= max_score):
64
+ msg = message or f"Expected score in [{min_score}, {max_score}], got {actual}"
65
+ if result.explanation:
66
+ msg += f"\nExplanation: {result.explanation}"
67
+ raise AssertionError(msg)
68
+
69
+
70
+ def assert_files_exist(
71
+ files: list[str],
72
+ actual_files: list[str],
73
+ *,
74
+ message: str | None = None,
75
+ ) -> None:
76
+ """Assert that expected files exist in the actual file list.
77
+
78
+ Args:
79
+ files: List of expected file paths/names.
80
+ actual_files: List of actual files found.
81
+ message: Optional custom failure message.
82
+
83
+ Raises:
84
+ AssertionError: If any expected file is missing.
85
+ """
86
+ missing = [f for f in files if f not in actual_files]
87
+ if missing:
88
+ msg = message or f"Missing files: {missing}"
89
+ msg += f"\nFound: {actual_files}"
90
+ raise AssertionError(msg)
91
+
92
+
93
+ def assert_contains(
94
+ needle: str,
95
+ haystack: str,
96
+ *,
97
+ message: str | None = None,
98
+ ) -> None:
99
+ """Assert that a string contains a substring.
100
+
101
+ Args:
102
+ needle: String to search for.
103
+ haystack: String to search in.
104
+ message: Optional custom failure message.
105
+
106
+ Raises:
107
+ AssertionError: If needle not found in haystack.
108
+ """
109
+ if needle not in haystack:
110
+ msg = message or f"Expected to find '{needle}' in output"
111
+ # Show a preview of the haystack
112
+ preview = haystack[:500] + "..." if len(haystack) > 500 else haystack
113
+ msg += f"\nActual output:\n{preview}"
114
+ raise AssertionError(msg)