ai-joe-here commited on
Commit
80e65e7
·
1 Parent(s): c0a23ca

Made the test context aware. Since windows will called npx subprocess twice, once to find it, and once to execute it, but unix will only call once.

Browse files
Files changed (1) hide show
  1. tests/test_cli.py +48 -13
tests/test_cli.py CHANGED
@@ -1,6 +1,7 @@
1
  """Tests for the FastMCP CLI."""
2
 
3
  import json
 
4
  from pathlib import Path
5
  from unittest.mock import patch, call
6
 
@@ -276,7 +277,6 @@ def test_server_dependencies_empty(mock_config, server_file):
276
 
277
  def test_dev_with_dependencies(mock_config, server_file):
278
  """Test that dev command handles dependencies correctly."""
279
- # Create a server file with dependencies
280
  server_file = server_file.parent / "server_with_deps.py"
281
  server_file.write_text(
282
  """from fastmcp import FastMCP
@@ -287,21 +287,56 @@ mcp = FastMCP("test", dependencies=["pandas", "numpy"])
287
  runner = CliRunner()
288
 
289
  with patch("subprocess.run") as mock_run:
290
- mock_run.return_value.returncode = 0 # Set successful return code
291
  result = runner.invoke(app, ["dev", str(server_file)])
292
  assert result.exit_code == 0
293
 
294
- # Check that dependencies were passed to subprocess.run
295
- mock_run.assert_called_once()
296
- args = mock_run.call_args[0][0]
297
- assert "npx" in args
298
- assert "@modelcontextprotocol/inspector" in args
299
- assert "uv" in args
300
- assert "run" in args
301
- assert "--with" in args
302
- assert "pandas" in args
303
- assert "numpy" in args
304
- assert "fastmcp" in args
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
 
307
  def test_run_with_dependencies(mock_config, server_file):
 
1
  """Tests for the FastMCP CLI."""
2
 
3
  import json
4
+ import sys
5
  from pathlib import Path
6
  from unittest.mock import patch, call
7
 
 
277
 
278
  def test_dev_with_dependencies(mock_config, server_file):
279
  """Test that dev command handles dependencies correctly."""
 
280
  server_file = server_file.parent / "server_with_deps.py"
281
  server_file.write_text(
282
  """from fastmcp import FastMCP
 
287
  runner = CliRunner()
288
 
289
  with patch("subprocess.run") as mock_run:
290
+ mock_run.return_value.returncode = 0
291
  result = runner.invoke(app, ["dev", str(server_file)])
292
  assert result.exit_code == 0
293
 
294
+ if sys.platform == "win32":
295
+ # On Windows, expect two calls
296
+ assert mock_run.call_count == 2
297
+ assert mock_run.call_args_list[0] == call(
298
+ ["npx.cmd", "--version"], check=True, capture_output=True, shell=True
299
+ )
300
+ assert mock_run.call_args_list[1] == call(
301
+ [
302
+ "npx.cmd",
303
+ "@modelcontextprotocol/inspector",
304
+ "uv",
305
+ "run",
306
+ "--with",
307
+ "fastmcp",
308
+ "--with",
309
+ "numpy",
310
+ "--with",
311
+ "pandas",
312
+ "fastmcp",
313
+ "run",
314
+ str(server_file),
315
+ ],
316
+ check=True,
317
+ shell=True,
318
+ )
319
+ else:
320
+ # On Unix, expect one call
321
+ mock_run.assert_called_once_with(
322
+ [
323
+ "npx",
324
+ "@modelcontextprotocol/inspector",
325
+ "uv",
326
+ "run",
327
+ "--with",
328
+ "fastmcp",
329
+ "--with",
330
+ "numpy",
331
+ "--with",
332
+ "pandas",
333
+ "fastmcp",
334
+ "run",
335
+ str(server_file),
336
+ ],
337
+ check=True,
338
+ shell=False, # Note: shell=False on Unix
339
+ )
340
 
341
 
342
  def test_run_with_dependencies(mock_config, server_file):