Skip to content

Commit 7a0b0b5

Browse files
remove empty lines with spaces.
1 parent 05a5918 commit 7a0b0b5

File tree

10 files changed

+164
-162
lines changed

10 files changed

+164
-162
lines changed

examples/test_emg_simulation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
async def test_emg():
99
"""Test EMG simulation."""
1010
print("\nTesting EMG simulation...")
11-
11+
1212
server = MatlabServer()
1313
await server.initialize()
14-
14+
1515
try:
1616
# Add matlab_scripts directory to MATLAB path
1717
script_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'matlab_scripts'))
1818
print(f"Adding script directory to path: {script_dir}")
1919
await server.engine.execute(f"addpath(genpath('{script_dir}'))")
20-
20+
2121
# Verify the path was added
2222
await server.engine.execute("path")
23-
23+
2424
print("Running EMG simulation...")
2525
# Run the EMG simulation
2626
result = await server.engine.execute(
2727
"simulate_emg",
2828
capture_plots=True
2929
)
3030
print(f"Simulation complete. Result: {result}")
31-
31+
3232
# Verify figures were captured
3333
print(f"Number of figures captured: {len(result.figures)}")
3434
if len(result.figures) > 0:
@@ -38,7 +38,7 @@ async def test_emg():
3838
print(f"- {fig}")
3939
else:
4040
print("No figures were captured")
41-
41+
4242
except Exception as e:
4343
print(f"Test failed: {str(e)}")
4444
raise

examples/test_engine.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
async def test_engine():
1414
"""Test basic MATLAB engine functionality."""
1515
engine = MatlabEngine()
16-
16+
1717
try:
1818
# Initialize engine
1919
await engine.initialize()
20-
20+
2121
# Run a simple MATLAB command
2222
result = await engine.execute('2 + 2')
2323
print(f"2 + 2 = {result.output}")
24-
24+
2525
# Try plotting
2626
script_path = Path(__file__).parent / "matlab_scripts" / "test_plot.m"
2727
if script_path.exists():
@@ -32,17 +32,17 @@ async def test_engine():
3232
capture_plots=True
3333
)
3434
print(f"Generated {len(result.figures)} figures")
35-
35+
3636
# Save figures
3737
output_dir = Path("test_output")
3838
output_dir.mkdir(exist_ok=True)
39-
39+
4040
for i, fig in enumerate(result.figures):
4141
ext = ".png" if fig.format.value == "png" else ".svg"
4242
output_file = output_dir / f"figure_{i}{ext}"
4343
output_file.write_bytes(fig.data)
4444
print(f"Saved {output_file}")
45-
45+
4646
except Exception as e:
4747
print(f"Error: {str(e)}")
4848
finally:

examples/test_initialization.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import asyncio
44
import os
5-
from pathlib import Path
65

76
from matlab_mcp.server import MatlabServer
87
from matlab_mcp.models import FigureFormat
@@ -12,25 +11,25 @@ async def test_server_initialization():
1211
"""Test server initialization sequence."""
1312
print("\nTesting server initialization with detailed logging...")
1413
print("Current MATLAB_PATH:", os.getenv('MATLAB_PATH', 'Not set'))
15-
14+
1615
server = MatlabServer()
17-
16+
1817
try:
1918
# Test initial state
2019
print("Checking initial state...")
2120
assert not server._initialized
2221
assert server.engine.eng is None
2322
print("Initial state verified")
24-
23+
2524
# Test initialization
2625
print("Attempting server initialization...")
2726
await server.initialize()
2827
print("Server initialized")
29-
28+
3029
assert server._initialized
3130
assert server.engine.eng is not None
3231
print("Server initialization successful")
33-
32+
3433
# Test MATLAB functionality
3534
print("Testing MATLAB functionality...")
3635
ver = server.engine.eng.version()
@@ -46,59 +45,59 @@ async def test_server_initialization():
4645
async def test_figure_cleanup():
4746
"""Test figure capture and cleanup."""
4847
print("\nTesting figure capture and cleanup...")
49-
48+
5049
server = MatlabServer()
5150
await server.initialize()
52-
51+
5352
# Create a test plot
5453
result = await server.engine.execute(
5554
"figure; plot(1:10); title('Test Plot')",
5655
capture_plots=True
5756
)
58-
57+
5958
# Verify figures were captured
6059
assert len(result.figures) > 0
6160
assert any(fig.format == FigureFormat.PNG for fig in result.figures)
6261
assert any(fig.format == FigureFormat.SVG for fig in result.figures)
6362
print("Figure capture successful")
64-
63+
6564
# Verify figures were cleaned up in MATLAB
6665
fig_count = server.engine.eng.eval('length(get(groot, "Children"))', nargout=1)
6766
assert fig_count == 0
6867
print("Figure cleanup successful")
69-
68+
7069
# Verify temporary files were cleaned up
7170
output_dir = server.engine.output_dir
7271
assert not any(output_dir.glob("figure_*.png"))
7372
assert not any(output_dir.glob("figure_*.svg"))
7473
print("Temporary file cleanup successful")
75-
74+
7675
# Clean up
7776
server.close()
7877

7978

8079
async def test_concurrent_requests():
8180
"""Test handling of concurrent protocol requests."""
8281
print("\nTesting concurrent protocol requests...")
83-
82+
8483
server = MatlabServer()
85-
84+
8685
# Simulate concurrent protocol requests
8786
results = await asyncio.gather(
8887
server._list_tools(),
8988
server._list_resources(),
9089
server._list_resource_templates()
9190
)
92-
91+
9392
# Verify all requests completed successfully
9493
assert all(result is not None for result in results)
9594
print("Concurrent request handling successful")
96-
95+
9796
# Verify server was initialized only once
9897
assert server._initialized
9998
assert server.engine.eng is not None
10099
print("Single initialization verified")
101-
100+
102101
# Clean up
103102
server.close()
104103

@@ -110,7 +109,7 @@ async def run_tests():
110109
await test_figure_cleanup()
111110
await test_concurrent_requests()
112111
print("\nAll initialization and cleanup tests passed!")
113-
112+
114113
except Exception as e:
115114
print(f"\nTest failed: {str(e)}")
116115
raise

examples/test_plot_capture.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def test_plot_capture():
1818
# Set MATLAB environment
1919
matlab_path = os.getenv('MATLAB_PATH', '/Applications/MATLAB_R2024a.app')
2020
print(f"MATLAB_PATH: {matlab_path}")
21-
21+
2222
# Ask user for correct MATLAB path if default doesn't exist
2323
if not os.path.exists(matlab_path):
2424
print(f"MATLAB not found at {matlab_path}")
@@ -32,53 +32,53 @@ async def test_plot_capture():
3232
return
3333
os.environ['MATLAB_PATH'] = matlab_path
3434
print(f"Set MATLAB_PATH to: {matlab_path}")
35-
35+
3636
server = MatlabServer()
3737
print("Created MatlabServer instance")
38-
38+
3939
try:
4040
print("Initializing MATLAB engine...")
4141
await server.engine.initialize()
4242
print("MATLAB engine initialized")
43-
43+
4444
# Execute test plot script
4545
script_path = Path(__file__).parent / "matlab_scripts" / "test_plot.m"
4646
if not script_path.exists():
4747
print(f"Test script not found at {script_path}")
4848
return
49-
49+
5050
print(f"Executing script: {script_path}")
5151
result = await server.engine.execute(
5252
str(script_path),
5353
is_file=True,
5454
capture_plots=True
5555
)
56-
56+
5757
if result.error:
5858
print(f"Error executing script: {result.error}")
5959
return
60-
60+
6161
# Verify we got both PNG and SVG versions
6262
png_figures = [f for f in result.figures if f.format == FigureFormat.PNG]
6363
svg_figures = [f for f in result.figures if f.format == FigureFormat.SVG]
64-
64+
6565
print(f"Generated {len(png_figures)} PNG figures")
6666
print(f"Generated {len(svg_figures)} SVG figures")
67-
67+
6868
# Save figures to verify content
6969
output_dir = Path("test_output")
7070
output_dir.mkdir(exist_ok=True)
71-
71+
7272
for i, fig in enumerate(result.figures):
7373
ext = ".png" if fig.format == FigureFormat.PNG else ".svg"
7474
output_file = output_dir / f"figure_{i}{ext}"
7575
output_file.write_bytes(fig.data)
7676
print(f"Saved {output_file}")
77-
77+
7878
except Exception as e:
7979
print("Error during execution:")
8080
print(traceback.format_exc())
81-
81+
8282
finally:
8383
print("Cleaning up MATLAB engine...")
8484
server.engine.cleanup()

examples/test_sections.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
async def test_section_execution():
1111
"""Test section-based MATLAB script execution."""
1212
print("Testing MATLAB Section Execution...")
13-
13+
1414
server = MatlabServer()
15-
15+
1616
# Test section parsing
1717
print("\nTesting section parsing...")
1818
script_path = Path("examples/matlab_scripts/section_test.m")
1919
if not script_path.exists():
2020
print(f"Error: Script not found at {script_path}")
2121
return
22-
22+
2323
sections = get_section_info(script_path)
2424
print(f"Found {len(sections)} sections:")
2525
for section in sections:
2626
print(f"- {section['title']} (lines {section['start_line']}-{section['end_line']})")
2727
print(f" Preview: {section['preview']}")
28-
28+
2929
# Test executing each section
3030
print("\nExecuting sections one by one...")
3131
for section in sections:
@@ -34,26 +34,26 @@ async def test_section_execution():
3434
str(script_path),
3535
(section['start_line'], section['end_line'])
3636
)
37-
37+
3838
print("Output:")
3939
print(result.output)
40-
40+
4141
print("Workspace variables:")
4242
for var, value in result.workspace.items():
4343
print(f"- {var}: {value}")
44-
44+
4545
if result.figures:
4646
print(f"Generated {len(result.figures)} figures")
47-
47+
4848
# Save figures
4949
output_dir = Path("test_output")
5050
output_dir.mkdir(exist_ok=True)
51-
51+
5252
for i, fig_data in enumerate(result.figures):
5353
output_path = output_dir / f"section_{section['start_line']}_figure_{i}.png"
5454
output_path.write_bytes(fig_data)
5555
print(f"Saved figure to: {output_path}")
56-
56+
5757
# Clean up
5858
server.engine.cleanup()
5959
print("\nTest completed successfully!")

examples/test_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,41 @@
99
async def test_basic_execution():
1010
"""Test basic MATLAB script execution."""
1111
print("Testing MATLAB MCP Server...")
12-
12+
1313
server = MatlabServer()
14-
14+
1515
# Test direct command execution
1616
print("\nTesting direct command execution...")
1717
result = await server.engine.execute(
1818
"a = 5; b = 10; c = a + b; fprintf('Sum: %d\\n', c)"
1919
)
2020
print(f"Output: {result.output}")
2121
print(f"Workspace: {result.workspace}")
22-
22+
2323
# Test script file execution
2424
print("\nTesting script file execution...")
2525
script_path = Path("examples/matlab_scripts/test_plot.m")
2626
if not script_path.exists():
2727
print(f"Error: Script not found at {script_path}")
2828
return
29-
29+
3030
result = await server.engine.execute(
3131
str(script_path),
3232
is_file=True
3333
)
3434
print(f"Output: {result.output}")
3535
print(f"Workspace: {result.workspace}")
3636
print(f"Number of figures captured: {len(result.figures)}")
37-
37+
3838
# Save captured figures
3939
output_dir = Path("test_output")
4040
output_dir.mkdir(exist_ok=True)
41-
41+
4242
for i, fig_data in enumerate(result.figures):
4343
output_path = output_dir / f"figure_{i}.png"
4444
output_path.write_bytes(fig_data)
4545
print(f"Saved figure to: {output_path}")
46-
46+
4747
# Clean up
4848
server.engine.cleanup()
4949
print("\nTest completed successfully!")

0 commit comments

Comments
 (0)