Skip to content

Commit

Permalink
misc: fix tests that secretly rely on optional dependencies (xdslproj…
Browse files Browse the repository at this point in the history
…ect#3361)

Also changes CI-Core to test only the core dev dependencies, letting
CI-MLIR check the full coverage
  • Loading branch information
superlopuh authored and EdmundGoodman committed Dec 6, 2024
1 parent e47c388 commit ebdf528
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 38 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ jobs:
- name: Install the project
run: uv sync --all-extras

- name: Test with pytest
run: uv run pytest -W error

- name: Execute lit tests
- name: Run all tests
run: |
export PYTHONPATH=$(pwd)
uv run lit -v tests/filecheck/
uv run lit -v docs/Toy/examples/
make tests-functional
4 changes: 2 additions & 2 deletions .github/workflows/ci-mlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ jobs:
export PATH=$PATH:${GITHUB_WORKSPACE}/llvm-project/build/bin/
uv run pytest --nbval docs/mlir_interoperation.ipynb --maxfail 1 -vv
- name: Test MLIR dependent marimo notebooks
- name: Test ONNX-dependent marimo notebooks
run: |
cd xdsl
# Add mlir-opt to the path
export PATH=$PATH:${GITHUB_WORKSPACE}/llvm-project/build/bin/
uv run make tests-marimo-mlir
uv run make tests-marimo-onnx
- name: Combine coverage data
run: |
Expand Down
52 changes: 35 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pytest: uv-installed
pytest-nb: uv-installed
uv run pytest -W error --nbval -vv docs \
--ignore=docs/mlir_interoperation.ipynb \
--ignore=docs/Toy \
--nbval-current-env

# run tests for Toy tutorial
Expand All @@ -64,8 +65,16 @@ filecheck-toy: uv-installed
pytest-toy: uv-installed
uv run pytest docs/Toy/toy/tests

.PHONY: pytest-toy-nb
pytest-toy-nb:
@if uv run python -c "import riscemu" > /dev/null 2>&1; then \
uv run pytest -W error --nbval -vv docs/Toy --nbval-current-env; \
else \
echo "riscemu is not installed, skipping tests."; \
fi

.PHONY: tests-toy
tests-toy: filecheck-toy pytest-toy
tests-toy: filecheck-toy pytest-toy pytest-toy-nb

.PHONY: tests-marimo
tests-marimo: uv-installed
Expand All @@ -79,26 +88,35 @@ tests-marimo: uv-installed
done
@echo "All marimo tests passed successfully."

.PHONY: tests-marimo-mlir
tests-marimo-mlir: uv-installed
@if ! command -v mlir-opt > /dev/null 2>&1; then \
echo "MLIR is not installed, skipping tests."; \
exit 0; \
.PHONY: tests-marimo-onnx
tests-marimo-onnx: uv-installed
@if uv run python -c "import onnx" > /dev/null 2>&1; then \
echo "onnx is installed, running tests."; \
if ! command -v mlir-opt > /dev/null 2>&1; then \
echo "MLIR is not installed, skipping tests."; \
exit 0; \
fi; \
for file in docs/marimo/onnx/*.py; do \
echo "Running $$file"; \
error_message=$$(uv run python3 "$$file" 2>&1) || { \
echo "Error running $$file"; \
echo "$$error_message"; \
exit 1; \
}; \
done; \
echo "All marimo onnx tests passed successfully."; \
else \
echo "onnx is not installed, skipping tests."; \
fi
@echo "MLIR is installed, running tests."
@for file in docs/marimo/mlir/*.py; do \
echo "Running $$file"; \
error_message=$$(uv run python3 "$$file" 2>&1) || { \
echo "Error running $$file"; \
echo "$$error_message"; \
exit 1; \
}; \
done
@echo "All marimo mlir tests passed successfully."

# run all tests
.PHONY: tests-functional
tests-functional: pytest tests-toy filecheck pytest-nb tests-marimo tests-marimo-onnx
@echo All functional tests done.

# run all tests
.PHONY: tests
tests: pytest tests-toy filecheck pytest-nb tests-marimo tests-marimo-mlir pyright
tests: tests-functional pyright
@echo All tests done.

# re-generate the output from all jupyter notebooks in the docs directory
Expand Down
2 changes: 1 addition & 1 deletion docs/marimo/linalg_snitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def __(

snitch_c_shaped = ShapedArray(TypedPtr.new_float64([0.0] * c_len), c_shape)

register_implementations(snitch_interpreter, ctx, include_wgpu=False)
register_implementations(snitch_interpreter, ctx, include_wgpu=False, include_onnx=False)

snitch_interpreter.call_op(
"matmul",
Expand Down
4 changes: 0 additions & 4 deletions docs/marimo/mlir/README.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/marimo/onnx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Marimo notebooks that depend on ONNX and mlir-opt

For these notebooks to run as intended, the `onnx` package needs to be installed and `mlir-opt` needs to be in the path.
Please see the [MLIR Interoperation](../../mlir_interoperation.md) document for more information.
File renamed without changes.
3 changes: 2 additions & 1 deletion tests/backend/test_jax_executable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re

import jax
import pytest

from xdsl.builder import ImplicitBuilder
Expand All @@ -11,6 +10,8 @@

pytest.importorskip("jax")

import jax # noqa: E402

from xdsl.backend.jax_executable import JaxExecutable, array # noqa: E402


Expand Down
3 changes: 1 addition & 2 deletions tests/frontend/jaxpr/test_build_jaxpr_ir.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import pytest

from xdsl.frontend.jaxpr import IRGen

try:
from jax import make_jaxpr # pyright: ignore[reportUnknownVariableType]
from jax import numpy as jnp
except ImportError as exc:
print(exc)
pytest.skip("jax is an optional dependency", allow_module_level=True)

from xdsl.frontend.jaxpr import IRGen

five_ones = jnp.ones(5, dtype=jnp.float32) # pyright: ignore[reportUnknownMemberType]

Expand Down
14 changes: 11 additions & 3 deletions tests/interactive/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
ModuleOp,
UnrealizedConversionCastOp,
)
from xdsl.interactive import _pasteboard
from xdsl.interactive.add_arguments_screen import AddArguments
from xdsl.interactive.app import InputApp
from xdsl.interactive.passes import AvailablePass, get_condensed_pass_list
from xdsl.ir import Block, Region
from xdsl.transforms import (
individual_rewrite,
)
from xdsl.transforms import individual_rewrite
from xdsl.transforms.experimental.dmp import stencil_global_to_local
from xdsl.utils.exceptions import ParseError
from xdsl.utils.parse_pipeline import PipelinePassSpec, parse_pipeline
Expand Down Expand Up @@ -198,6 +197,15 @@ async def test_buttons():
"""
)

# Test that the current pipeline command is correctly copied
def callback(x: str):
assert (
x == "xdsl-opt -p 'convert-func-to-riscv-func,convert-arith-to-riscv'"
)

_pasteboard._test_pyclip_callback = callback # pyright: ignore[reportPrivateUsage]
await pilot.click("#copy_query_button")

current_pipeline = app.pass_pipeline
# press "Remove Last Pass" button
await pilot.click("#remove_last_pass_button")
Expand Down
12 changes: 11 additions & 1 deletion xdsl/interactive/_pasteboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
annotations. We add our own mirror of the copy function here.
"""

import pyclip # pyright: ignore[reportMissingTypeStubs]
from collections.abc import Callable

_test_pyclip_callback: Callable[[str], None] | None = None
"""Used in tests."""


def pyclip_copy(text: str) -> None:
global _test_pyclip_callback
if _test_pyclip_callback is not None:
_test_pyclip_callback(text)
return

import pyclip # pyright: ignore[reportMissingTypeStubs]

pyclip.copy(text) # pyright: ignore[reportUnknownMemberType]

0 comments on commit ebdf528

Please sign in to comment.