Last active
July 21, 2023 18:37
-
-
Save scivision/c7e55d78c5d454e21bb014df3b89ebd6 to your computer and use it in GitHub Desktop.
Pytest with Matlab and GNU Octave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/bin/env python3 | |
from pathlib import Path | |
import subprocess | |
import pytest | |
import shutil | |
import functools | |
R = Path(__file__).parent | |
@functools.cache | |
def octave() -> str | None: | |
return shutil.which("octave") | |
@functools.cache | |
def matlab() -> str | None: | |
return shutil.which("matlab") | |
@pytest.mark.skipif(not matlab(), reason="Matlab not available") | |
def test_matlab_api(): | |
subprocess.check_call( | |
[ | |
matlab(), | |
"-batch", | |
f"r=runtests('{R}'), assert(~isempty(r)), assertSuccess(r)", | |
], | |
timeout=60, | |
) | |
@pytest.mark.skipif(not octave(), reason="octave not found") | |
def test_octave_api(): | |
subprocess.check_call([octave(), f"oruntests('{R}')"], timeout=60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classdef TestExample < matlab.unittest.TestCase | |
methods (Test) | |
function testExample(testCase) | |
testCase.verifyEqual(1, 1); | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment