Skip to content

Commit

Permalink
Merge pull request #649 from NEUBIAS/add-tests-python
Browse files Browse the repository at this point in the history
Added tests for python scripts in _includes
  • Loading branch information
bugraoezdemir authored Apr 26, 2024
2 parents a5bd172 + 263e6f9 commit eed2057
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 12 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/test-python-scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: test-python-scripts

on:
push:
branches:
- gh-pages
- master
pull_request: []

jobs:
test-python-scripts:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: install xvfb/deps
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -yy mesa-utils libgl1-mesa-dev xvfb curl
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
auto-activate-base: true
activate-environment: ""
channel-priority: strict
miniforge-version: latest
- name: install common conda dependencies
run: conda install -c conda-forge -c euro-bioimaging python=3.10 napari=0.4.17 pytest notebook matplotlib jupytext "scikit-image>=0.20" openijtiff -y
- name: linux test
if: matrix.os == 'ubuntu-latest'
shell: bash -l {0}
run: xvfb-run --server-args="-screen 0 1024x768x24" pytest -v test_python
- name: osx test
if: matrix.os == 'macos-latest'
shell: bash -l {0}
run: pytest -v test_python
- name: windows test
if: matrix.os == 'windows-latest'
shell: cmd /C CALL {0}
run: pytest -v test_python
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from OpenIJTIFF import open_ij_tiff

# load the image from file
image_file = "/image_data/xy_8bit__two_cells.tif"
image = io.imread(image_file)
image_file = "https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_8bit__two_cells.tif"
image, _, _, _ = open_ij_tiff(image_file)

# binarize the image, so that all values larger than the threshold are foreground
threshold_value = 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
dilated = dilation(image, footprint = disk(1))

# Add to napari
napari_viewer.add_labels(eroded, name='eroded1', colormap='magenta', opacity = 0.7)
napari_viewer.add_labels(dilated, name='dilated1', colormap = 'green', opacity = 0.7)
napari_viewer.add_image(eroded, name='eroded1', colormap='magenta', opacity = 0.7)
napari_viewer.add_image(dilated, name='dilated1', colormap='green', opacity = 0.7)

# %% [markdown]
# Appreciate that the single pixel disappeared with erosion.\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# %%
# Import python packages.
import os
from OpenIJTIFF import open_ij_tiff, save_ij_tiff
import numpy as np
from napari.viewer import Viewer
Expand Down Expand Up @@ -62,7 +63,8 @@
# %%
# Save the 3D image with the calibration metadata
save_ij_tiff(
'/Users/tischer/Desktop/image_3D_calibrated.tif',
# during trainings this Path should be replaced by the user's desktop, e.g. C:/Users/dominik/Desktop
os.path.join(os.path.expanduser("~"), "image_3D_calibrated.tif"),
image_3D,
axes_image_3D,
voxel_size_image_3D,
Expand Down
10 changes: 5 additions & 5 deletions _includes/string_concat/activities/string_concat_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#Please note that in Python, unlike imageJ macro language you cannot concatenate strings directly with numbers.


text1 = "Hello ";
text2 = "user number ";
Text3 = "50"
text1 = "Hello "
text2 = "user number "
text3 = "50"

#concatenating strings
text3 = text1 + text2 + text3;
text3 = text1 + text2 + text3

#printing the results
print(text3);
print(text3)
23 changes: 23 additions & 0 deletions test_python/test_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pathlib
import runpy

import pytest

scripts = filter(
lambda x: "jython" not in x.lower(),
map(lambda x: x.as_posix(), (pathlib.Path(__file__).parent / ".." / "_includes").resolve().glob("**/*.py")),
)


known_failures = {
"measure_intensities_act1_skimage_napari.py": "Requires manual interaction to pass.",
"spatial_calibration_act1_skimage_napari.py": "Requires manual interaction to pass.",
"volume_slicing_act1_python-napari.py": "Not supposed to be run in a script, but in the napari viewer itself.",
}


@pytest.mark.parametrize("script", scripts)
def test_script_execution(script):
if (script_name := pathlib.Path(script).name) in known_failures:
pytest.xfail(known_failures[script_name])
runpy.run_path(script)

0 comments on commit eed2057

Please sign in to comment.