Skip to content

Commit f7a6527

Browse files
pranaverma92krisctl
authored andcommitted
Enables MATLAB unit testing to improve coverage.
1 parent 1e2c844 commit f7a6527

File tree

4 files changed

+119
-4
lines changed

4 files changed

+119
-4
lines changed

.github/workflows/run-integration-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ jobs:
1818

1919
# The minimum matlab-release is set to 21b as 20b and 21a are not supported by matlab-actions/setup-matlab.
2020
# See https://github.com/matlab-actions/setup-matlab/issues/76
21-
matlab-release: [R2021b, R2023a]
21+
matlab-release: [R2021b, latest]
2222

2323
runs-on: ${{ matrix.os }}
2424
steps:
2525
- name: Checkout
26-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2727

2828
- name: Set up MATLAB ${{ matrix.matlab-release }}
2929
# Use MATLAB Actions to get running MATLAB in GitHub Actions
30-
uses: matlab-actions/setup-matlab@v2-beta
30+
uses: matlab-actions/setup-matlab@v2
3131
with:
3232
release: ${{ matrix.matlab-release }}
3333
products: MATLAB Symbolic_Math_Toolbox

.github/workflows/run-unit-tests.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020-2023 The MathWorks, Inc.
1+
# Copyright 2020-2024 The MathWorks, Inc.
22

33
# Workflow that contains jobs to test MATLAB Jupyter Integration
44
name: Unit Testing MATLAB Jupyter Integration
@@ -9,6 +9,29 @@ on:
99
workflow_call:
1010

1111
jobs:
12+
matlab_unit_tests:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest, windows-latest]
17+
matlab-release: [R2021b, latest]
18+
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up MATLAB ${{ matrix.matlab-release }}
25+
# Use MATLAB Actions to get running MATLAB in GitHub Actions
26+
uses: matlab-actions/setup-matlab@v2
27+
with:
28+
release: ${{ matrix.matlab-release }}
29+
30+
- name: Run tests
31+
uses: matlab-actions/run-tests@v2
32+
with:
33+
select-by-folder: tests/matlab-tests
34+
1235
python_unit_tests:
1336
env:
1437
code-cov-py: "3.11"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
% Copyright 2024 The MathWorks, Inc.
2+
3+
classdef TestCompleteFunction < matlab.unittest.TestCase
4+
% TestCompleteFunction contains unit tests for the complete function
5+
6+
properties
7+
TestPaths
8+
end
9+
10+
methods (TestClassSetup)
11+
function addFunctionPath(testCase)
12+
testCase.TestPaths = cellfun(@(relative_path)(fullfile(pwd, relative_path)), {"../../src/jupyter_matlab_kernel/matlab", "../../tests/matlab-tests/"}, 'UniformOutput', false);
13+
cellfun(@addpath, testCase.TestPaths)
14+
end
15+
end
16+
17+
methods (TestClassTeardown)
18+
function removeFunctionPath(testCase)
19+
cellfun(@rmpath, testCase.TestPaths)
20+
end
21+
end
22+
23+
methods (Test)
24+
function testBasicCompletion(testCase)
25+
% Test basic completion functionality
26+
code = 'plo';
27+
cursorPosition = 2;
28+
result = jupyter.complete(code, cursorPosition);
29+
expectedMatches = 'plot';
30+
testCase.verifyTrue(ismember(expectedMatches, result.matches), "Completion 'plot' was not found in the result");
31+
end
32+
33+
function testEmptyCode(testCase)
34+
% Test behavior with empty code string
35+
code = '';
36+
cursorPosition = 0;
37+
result = jupyter.complete(code, cursorPosition);
38+
testCase.verifyTrue(isempty(result.matches));
39+
end
40+
41+
function testInvalidCursorPosition(testCase)
42+
% Test behavior with an invalid cursor position
43+
code = 'plot';
44+
cursorPosition = -1; % Invalid cursor position
45+
result = jupyter.complete(code, cursorPosition);
46+
testCase.verifyTrue(isempty(result.matches));
47+
end
48+
end
49+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
% Copyright 2024 The MathWorks, Inc.
2+
3+
classdef TestGetOrStashExceptionsFunction < matlab.unittest.TestCase
4+
% TestCompleteFunction contains unit tests for the getOrStashExceptions function
5+
properties
6+
TestPaths
7+
end
8+
9+
methods (TestClassSetup)
10+
function addFunctionPath(testCase)
11+
testCase.TestPaths = cellfun(@(relative_path)(fullfile(pwd, relative_path)), {"../../src/jupyter_matlab_kernel/matlab", "../../tests/matlab-tests/"}, 'UniformOutput', false);
12+
cellfun(@addpath, testCase.TestPaths)
13+
end
14+
end
15+
16+
methods (TestClassTeardown)
17+
function removeFunctionPath(testCase)
18+
cellfun(@rmpath, testCase.TestPaths)
19+
end
20+
end
21+
22+
methods (Test)
23+
function testReturnExceptionOnReset(testCase)
24+
% Test that an exception can be returned and reset
25+
testMessage = 'Test Exception';
26+
jupyter.getOrStashExceptions(testMessage, false); % Stash the exception without the intention to reset
27+
result = jupyter.getOrStashExceptions([], true); % Retrieve and reset
28+
testCase.assertEqual(result, testMessage, ...
29+
'The function should return the Test Exception when resetFlag is true.');
30+
resultAfterReset = jupyter.getOrStashExceptions();
31+
testCase.assertEmpty(resultAfterReset, ...
32+
'The stashed exception should be cleared after being reset.');
33+
end
34+
35+
function testReturnStashedExceptionWithoutReset(testCase)
36+
% Test that the stashed exception is returned without resetting
37+
testMessage = 'Test Exception';
38+
jupyter.getOrStashExceptions(testMessage); % Stash the exception
39+
result = jupyter.getOrStashExceptions(); % Retrieve without resetting
40+
testCase.assertEqual(result, testMessage);
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)