Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active July 21, 2023 18:37
Show Gist options
  • Save scivision/c7e55d78c5d454e21bb014df3b89ebd6 to your computer and use it in GitHub Desktop.
Save scivision/c7e55d78c5d454e21bb014df3b89ebd6 to your computer and use it in GitHub Desktop.
Pytest with Matlab and GNU Octave
# /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)
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