Skip to content

Commit 5be0bd9

Browse files
alexj0sealexjose
andauthored
Tests for matlab engine installer (#22)
* Add tests * Add action for running tests * Fix typo and add comments to indicate expected MATLABVersion and MATLABRelease * Clarify how MATLAB Release is extracted --------- Co-authored-by: alexjose <alexjose@MATHWORKS-ITQ2V.local>
1 parent 23d6d32 commit 5be0bd9

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Run tInstall on Ubuntu against python versions 3.10, 3.9 and 3.8
2+
3+
name: Test R2022b and R2023a
4+
5+
on:
6+
push:
7+
branches:
8+
- R2022b
9+
- R2023a
10+
- main
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
16+
17+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
18+
jobs:
19+
test-python-engine:
20+
strategy:
21+
matrix:
22+
python: ["3.10", "3.9", "3.8"]
23+
matlab: [R2022b, R2023a]
24+
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Set up Python
29+
uses: actions/setup-python@v3.1.3
30+
with:
31+
python-version: ${{ matrix.python }}
32+
33+
- name: Set up MATLAB
34+
uses: matlab-actions/setup-matlab@v1
35+
with:
36+
release: ${{ matrix.matlab }}
37+
38+
- uses: actions/checkout@v3
39+
40+
- name: Run tests
41+
uses: matlab-actions/run-tests@v1

test/tInstall.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
classdef tInstall < matlab.unittest.TestCase
2+
% Verify installation of matlab engine
3+
4+
% Copyright 2023 Mathworks, Inc.
5+
6+
properties (Constant)
7+
MATLABVersion = string(ver('MATLAB').Version) % Example: 9.14
8+
MATLABRelease = erase(ver('MATLAB').Release,{'(',')'}) % Example: (R2023a) -> R2023a
9+
end
10+
11+
methods (Test)
12+
function installNoVersionSpecified(testCase)
13+
assumeEqual(testCase, testCase.MATLABRelease, 'R2023a')
14+
[status, out] = system("pip install matlabengine");
15+
verifyEqual(testCase, status, 0, out)
16+
verifyInstallation(testCase)
17+
end
18+
19+
function installMatchingEngine(testCase)
20+
[status, out] = system("pip install matlabengine==" + testCase.MATLABVersion + ".*");
21+
verifyEqual(testCase, status, 0, out)
22+
verifyInstallation(testCase)
23+
end
24+
end
25+
26+
methods
27+
function verifyInstallation(testCase)
28+
% Verify installation by calling functions in matlab engine
29+
% Share this session and see if find_matlab can find it.
30+
sharedEngineName = string(matlab.engine.engineName);
31+
if (sharedEngineName == "")
32+
sharedEngineName = "MATLAB_tInstall";
33+
matlab.engine.shareEngine(sharedEngineName)
34+
end
35+
pySharedEngineName = string(py.matlab.engine.find_matlab());
36+
verifyEqual(testCase, pySharedEngineName, sharedEngineName)
37+
system("pip uninstall -y matlabengine")
38+
end
39+
end
40+
end
41+

0 commit comments

Comments
 (0)