Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple GUI test for CI #223

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
984a7a4
Switch to pytest (previously used unittest)
GenevieveBuckley Sep 27, 2023
ed1bb00
Testing CI, remove pytest-qt for now
GenevieveBuckley Sep 27, 2023
adc161a
Is micromamba faster for CI than miniconda
GenevieveBuckley Sep 27, 2023
1cbd132
Update test.yaml (more minimal micromamba setup config)
GenevieveBuckley Sep 27, 2023
59a8c4f
Update environment_cpu.yaml (put name at top for micromamba CI install)
GenevieveBuckley Sep 27, 2023
3cfc777
Update environment_gpu.yaml (put name up top to avoid micromamba CI s…
GenevieveBuckley Sep 27, 2023
55a7813
Fix filename pointing to environment_cpu.yaml
GenevieveBuckley Sep 27, 2023
246f642
Generate code coverage report for CI tests
GenevieveBuckley Sep 27, 2023
6045f6a
Update test.yaml (install pytest-cov for code coverage reports)
GenevieveBuckley Sep 27, 2023
fee3c6f
Fix code coverage call in CI
GenevieveBuckley Sep 27, 2023
f86fcf8
Update pyproject.toml to include pytest-cov default arguments
GenevieveBuckley Sep 27, 2023
1fea5c9
Update test.yaml (pytest-cov default arguments now in pyproject.toml …
GenevieveBuckley Sep 27, 2023
b0b57e5
Update pyproject.toml (wrap pytest adopts args in quote string)
GenevieveBuckley Sep 27, 2023
dbbc441
Update pyproject.toml (rename code coverage output file)
GenevieveBuckley Sep 27, 2023
682f1e5
Update test.yaml (try experimental codecov@v4 github action)
GenevieveBuckley Sep 27, 2023
8b50d4f
Update test.yaml (explicitly specify location of coverage.xml file)
GenevieveBuckley Sep 27, 2023
0cf6803
Update test.yaml (reduce duplicate CI runs)
GenevieveBuckley Sep 27, 2023
f943015
Update pyproject.toml (fix TOML formatting)
GenevieveBuckley Sep 27, 2023
cda309f
Update test.yaml - more verbose output for debugging
GenevieveBuckley Oct 4, 2023
22d0064
Update pyproject.toml - fix pytest configuration
GenevieveBuckley Oct 4, 2023
f5d34d4
Update test.yaml - less verbose output in github actions
GenevieveBuckley Oct 4, 2023
9319bd4
Hacky testing how to make GUI integration tests
GenevieveBuckley Oct 4, 2023
5f2435e
Github actions CI, napari and pyqt are required dependencies for GUI …
GenevieveBuckley Oct 16, 2023
11f002b
Remove separate gui test CI workflow file
GenevieveBuckley Oct 16, 2023
65cee54
Codecov CI, update workflow file secret token
GenevieveBuckley Oct 16, 2023
9177464
Install napari and pyqt with pip for GUI tests in CI
GenevieveBuckley Oct 16, 2023
4dad937
Comment out all gui tests
GenevieveBuckley Oct 16, 2023
ade3195
Increase github actions timeout limit to 60 minutes
GenevieveBuckley Oct 16, 2023
cd9e5f7
Github actions CI, need headless gui action in pytest job
GenevieveBuckley Oct 16, 2023
3152239
Report slowest test durations
GenevieveBuckley Oct 16, 2023
aaa12cc
Add GUI test
GenevieveBuckley Oct 16, 2023
2feb208
Make GUI 2d annotator test have 2d image input
GenevieveBuckley Oct 16, 2023
06cacf4
Pytest marker for GUI tests
GenevieveBuckley Oct 16, 2023
c78c6f5
Trigger CI
GenevieveBuckley Oct 16, 2023
8395dac
from typing import Tuple, in visualization.py
GenevieveBuckley Oct 16, 2023
5618fc4
Merge branch 'dev' into gui-tests-plus-codecov
GenevieveBuckley Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
test:
name: ${{ matrix.os }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}

timeout-minutes: 60
constantinpape marked this conversation as resolved.
Show resolved Hide resolved
strategy:
fail-fast: false
matrix:
Expand All @@ -31,19 +31,29 @@ jobs:
with:
environment-file: environment_cpu.yaml

# Setup Qt libraries for GUI testing
- uses: tlambert03/setup-qt-libs@v1

- name: Install napari and pyqt for GUI tests
shell: bash -l {0}
run: pip install "napari[all]"

- name: Install pytest
shell: bash -l {0}
run: |
python -m pip install pytest
python -m pip install pytest-cov
python -m pip install pytest-qt

- name: Install package
shell: bash -l {0}
run: pip install --no-deps -e .

- name: Run tests
shell: bash -l {0}
run: pytest
uses: aganders3/headless-gui@v1
with:
shell: bash -l {0}
run: pytest

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
1 change: 1 addition & 0 deletions micro_sam/visualization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Functionality for visualizing image embeddings.
"""
from typing import Tuple

import numpy as np

Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ requires = ["setuptools>=42.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = "-v --cov=micro_sam --cov-report xml:coverage.xml --cov-report term"
addopts = "-v --durations=10 --cov=micro_sam --cov-report xml:coverage.xml"
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"gui: marks GUI tests (deselect with '-m \"not gui\"')",
]

[tool.black]
line-length = 79
Expand Down
48 changes: 48 additions & 0 deletions test/test_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import numpy as np
import pytest

from micro_sam.sam_annotator import annotator_2d
from micro_sam.sam_annotator.annotator_2d import _initialize_viewer


def _check_layer_initialization(viewer):
"""Utility function to check the initial layer setup is correct."""
assert len(viewer.layers) == 6
expected_layer_names = ['raw', 'auto_segmentation', 'committed_objects', 'current_object', 'point_prompts', 'prompts']
for layername in expected_layer_names:
assert layername in viewer.layers
# Check layers are empty before beginning tests
np.testing.assert_equal(viewer.layers["auto_segmentation"].data, 0)
np.testing.assert_equal(viewer.layers["current_object"].data, 0)
np.testing.assert_equal(viewer.layers["committed_objects"].data, 0)
np.testing.assert_equal(viewer.layers["point_prompts"].data, 0)
assert viewer.layers["prompts"].data == [] # shape data is list, not numpy array


@pytest.mark.gui
def test_annotator_2d(make_napari_viewer_proxy, tmp_path):
"""Integration test for annotator_2d widget with automatic mask generation.

* Creates 2D image embedding
* Opens annotator_2d widget in napari
"""
model_type = "vit_b"
embedding_path = tmp_path / "test-embedding.zarr"
# example data - a basic checkerboard pattern
image = np.zeros((16,16))
image[:8,:8] = 1
image[8:,8:] = 1

viewer = make_napari_viewer_proxy()
viewer = _initialize_viewer(image, None, None, None) # TODO: fix hacky workaround
# test generating image embedding, then adding micro-sam dock widgets to the GUI
viewer = annotator_2d(
image,
embedding_path,
show_embeddings=False,
model_type=model_type,
v=viewer,
return_viewer=True
)
_check_layer_initialization(viewer)
viewer.close() # must close the viewer at the end of tests