Merge pull request #4 from VH-Lab/claude/add-symmetry-tests-U0CE9 #4
This file contains hidden or 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
| name: Test Cross-Language Symmetry | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| symmetry: | |
| name: MATLAB <-> Python symmetry tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| # -- Checkout both repos ---------------------------------------------- | |
| - name: Check out NDR-python | |
| uses: actions/checkout@v4 | |
| with: | |
| path: NDR-python | |
| # Check out NDR-matlab at the same branch name as this workflow run | |
| # (e.g. the PR's head branch or the branch being pushed to main). | |
| # Developers are expected to keep matching branch names across the | |
| # two repos when making cross-language changes, the same way the | |
| # symmetry branches work. Falls back to main via the default so | |
| # `main` pushes also work. | |
| - name: Check out NDR-matlab (matching branch) | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: VH-Lab/NDR-matlab | |
| path: NDR-matlab | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| # -- Runtime setup ---------------------------------------------------- | |
| - name: Start virtual display server | |
| run: | | |
| sudo apt-get install -y xvfb | |
| Xvfb :99 & | |
| echo "DISPLAY=:99" >> $GITHUB_ENV | |
| - name: Set up MATLAB | |
| uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: latest | |
| cache: true | |
| products: | | |
| Signal_Processing_Toolbox | |
| Statistics_and_Machine_Learning_Toolbox | |
| - name: Install MatBox | |
| uses: ehennestad/matbox-actions/install-matbox@v1 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install NDR-python (with dev extras) | |
| working-directory: NDR-python | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev]" | |
| # -- Stage 1: MATLAB makeArtifacts ------------------------------------ | |
| - name: "Stage 1: MATLAB makeArtifacts" | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: | | |
| % Add NDR-matlab repo root (for +ndr) and tools/tests | |
| % (for +ndr/+symmetry). Note: MATLAB namespace (+foo) | |
| % directories must NOT themselves appear on the path -- | |
| % only their parent directories should. | |
| ndrRoot = fullfile(pwd, "NDR-matlab"); | |
| addpath(ndrRoot); | |
| addpath(fullfile(ndrRoot, "tools", "tests")); | |
| % Install MATLAB dependencies declared in tools/requirements.txt | |
| % (e.g. vhlab-toolbox-matlab, which provides vlt.string.*). | |
| matbox.installRequirements(fullfile(ndrRoot, "tools")); | |
| % Skip ndr_Init -- it tries to mkdir filecache paths under | |
| % userpath which are not writable on the CI runner. | |
| % The symmetry tests only use ndr.fun.ndrpath() which is | |
| % self-contained. | |
| import matlab.unittest.TestSuite | |
| import matlab.unittest.TestRunner | |
| suite = TestSuite.fromPackage("ndr.symmetry.makeArtifacts", "IncludingSubpackages", true); | |
| fprintf("\n=== MATLAB makeArtifacts: %d test(s) ===\n", numel(suite)); | |
| assert(~isempty(suite), "No MATLAB makeArtifacts tests found.") | |
| runner = TestRunner.withTextOutput("Verbosity", "Detailed"); | |
| results = runner.run(suite); | |
| fprintf("\n=== MATLAB makeArtifacts: %d passed, %d failed ===\n", ... | |
| nnz([results.Passed]), nnz([results.Failed])); | |
| assert(all(~[results.Failed]), "MATLAB makeArtifacts failed") | |
| # -- Stage 2: Python readArtifacts (reads MATLAB artifacts) ----------- | |
| - name: "Stage 2: Python readArtifacts (reads MATLAB artifacts)" | |
| working-directory: NDR-python | |
| run: | | |
| pytest tests/symmetry/read_artifacts/ -v --tb=short | |
| # -- Stage 3: Python makeArtifacts ------------------------------------ | |
| - name: "Stage 3: Python makeArtifacts" | |
| working-directory: NDR-python | |
| run: | | |
| pytest tests/symmetry/make_artifacts/ -v --tb=short | |
| # -- Stage 4: MATLAB readArtifacts (reads Python artifacts) ----------- | |
| - name: "Stage 4: MATLAB readArtifacts (reads Python artifacts)" | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: | | |
| ndrRoot = fullfile(pwd, "NDR-matlab"); | |
| addpath(ndrRoot); | |
| addpath(fullfile(ndrRoot, "tools", "tests")); | |
| matbox.installRequirements(fullfile(ndrRoot, "tools")); | |
| import matlab.unittest.TestSuite | |
| import matlab.unittest.TestRunner | |
| suite = TestSuite.fromPackage("ndr.symmetry.readArtifacts", "IncludingSubpackages", true); | |
| fprintf("\n=== MATLAB readArtifacts: %d test(s) ===\n", numel(suite)); | |
| assert(~isempty(suite), "No MATLAB readArtifacts tests found.") | |
| runner = TestRunner.withTextOutput("Verbosity", "Detailed"); | |
| results = runner.run(suite); | |
| fprintf("\n=== MATLAB readArtifacts: %d passed, %d failed ===\n", ... | |
| nnz([results.Passed]), nnz([results.Failed])); | |
| assert(all(~[results.Failed]), "MATLAB readArtifacts failed") |