Skip to content

Commit 48805ec

Browse files
authored
add more tests (#14)
1 parent 45087e8 commit 48805ec

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "uv_build"
55
[project]
66
name = "mcp-run-python"
77
description = "Model Context Protocol server to run Python code in a sandbox."
8-
version = "0.0.20"
8+
version = "0.0.21"
99
authors = [{ name = "Samuel Colvin", email = "samuel@pydantic.dev" }]
1010
license = "MIT"
1111
readme = "README.md"

tests/test_mcp_servers.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,21 @@ async def test_list_tools(run_mcp_session: Callable[[list[str]], AbstractAsyncCo
8181
assert tool.name == 'run_python_code'
8282
assert tool.description
8383
assert tool.description.startswith('Tool to execute Python code and return stdout, stderr, and return value.')
84-
assert tool.inputSchema['properties'] == snapshot(
84+
assert tool.inputSchema == snapshot(
8585
{
86-
'python_code': {'type': 'string', 'description': 'Python code to run'},
87-
'global_variables': {
88-
'type': 'object',
89-
'additionalProperties': {},
90-
'default': {},
91-
'description': 'Map of global variables in context when the code is executed',
86+
'type': 'object',
87+
'properties': {
88+
'python_code': {'type': 'string', 'description': 'Python code to run'},
89+
'global_variables': {
90+
'type': 'object',
91+
'additionalProperties': {},
92+
'default': {},
93+
'description': 'Map of global variables in context when the code is executed',
94+
},
9295
},
96+
'required': ['python_code'],
97+
'additionalProperties': False,
98+
'$schema': 'http://json-schema.org/draft-07/schema#',
9399
}
94100
)
95101

tests/test_sandbox.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Foobar:
1717

1818

1919
@pytest.mark.parametrize(
20-
'deps,code,locals,expected',
20+
'deps,code,globals,expected',
2121
[
2222
pytest.param(
2323
[],
@@ -26,6 +26,13 @@ class Foobar:
2626
snapshot({'status': 'success', 'output': [], 'return_value': 2}),
2727
id='return-value-success',
2828
),
29+
pytest.param(
30+
[],
31+
'"foobar"',
32+
{},
33+
snapshot({'status': 'success', 'output': [], 'return_value': 'foobar'}),
34+
id='return-string',
35+
),
2936
pytest.param(
3037
[],
3138
'print(123)',
@@ -38,28 +45,35 @@ class Foobar:
3845
'a',
3946
{'a': [1, 2, 3]},
4047
snapshot({'status': 'success', 'output': [], 'return_value': [1, 2, 3]}),
41-
id='access-local-variables',
48+
id='access-global-variables',
4249
),
4350
pytest.param(
4451
[],
4552
'a + b',
4653
{'a': 4, 'b': 5},
4754
snapshot({'status': 'success', 'output': [], 'return_value': 9}),
48-
id='multiple-locals',
55+
id='multiple-globals',
4956
),
5057
pytest.param(
5158
[],
5259
'print(f)',
5360
{'f': Foobar(1, '2', b'3')},
5461
snapshot({'status': 'success', 'output': ["{'a': 1, 'b': '2', 'c': '3'}"], 'return_value': None}),
55-
id='print-complex-local',
62+
id='print-complex-global',
63+
),
64+
pytest.param(
65+
[],
66+
'f',
67+
{'f': Foobar(1, '2', b'3')},
68+
snapshot({'status': 'success', 'output': [], 'return_value': {'a': 1, 'b': '2', 'c': '3'}}),
69+
id='return-complex-global',
5670
),
5771
pytest.param(
5872
[],
5973
'f',
6074
{'f': Foobar(1, '2', b'3')},
6175
snapshot({'status': 'success', 'output': [], 'return_value': {'a': 1, 'b': '2', 'c': '3'}}),
62-
id='return-complex-local',
76+
id='return-complex-global',
6377
),
6478
pytest.param(
6579
[],
@@ -134,9 +148,9 @@ def baz():
134148
),
135149
],
136150
)
137-
async def test_sandbox(deps: list[str], code: str, locals: dict[str, Any], expected: Any):
151+
async def test_sandbox(deps: list[str], code: str, globals: dict[str, Any], expected: Any):
138152
async with code_sandbox(dependencies=deps) as sandbox:
139-
result = await sandbox.eval(code, locals)
153+
result = await sandbox.eval(code, globals)
140154
assert result == expected
141155

142156

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)