Skip to content

Commit

Permalink
Testing and minor updates
Browse files Browse the repository at this point in the history
- Run tests on ubuntu
- Updated tests
- Added Log test and Log init update
  • Loading branch information
C-Achard committed Mar 3, 2023
1 parent 500c37b commit 09333b0
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 65 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/preview_metadata.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#name: napari hub Preview Page # we use this name to find your preview page artifact, so don't change it!
## For more info on this action, see https://github.com/chanzuckerberg/napari-hub-preview-action/blob/main/action.yml
#
#on:
# pull_request:
# branches:
# - 'test' # '**' for all
#
#jobs:
# preview-page:
# name: Preview Page Deploy
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout repo
# uses: actions/checkout@v2
#
# - name: napari hub Preview Page Builder
# uses: chanzuckerberg/[email protected].5
# with:
# hub-ref: main
name: napari hub Preview Page # we use this name to find your preview page artifact, so don't change it!
# For more info on this action, see https://github.com/chanzuckerberg/napari-hub-preview-action/blob/main/action.yml

on:
pull_request:
branches:
- 'test' # '**' for all

jobs:
preview-page:
name: Preview Page Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: napari hub Preview Page Builder
uses: chanzuckerberg/[email protected].6
with:
hub-ref: main
4 changes: 2 additions & 2 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
strategy:
matrix:
# platform: [ubuntu-latest, windows-latest, macos-latest]
platform: [windows-latest]
python-version: [3.8, 3.9, "3.10"]
platform: [ubuntu-latest]
python-version: [3.8, 3.9, 3.10]

steps:
- uses: actions/checkout@v2
Expand Down
13 changes: 13 additions & 0 deletions napari_cellseg3d/_tests/test_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from napari_cellseg3d.interface import Log

def test_log(qtbot):
log = Log()
log.print_and_log("test")

assert log.toPlainText() == "\ntest"

log.replace_last_line("test2")

assert log.toPlainText() == "\ntest2"

qtbot.add_widget(log)
12 changes: 6 additions & 6 deletions napari_cellseg3d/_tests/test_plugin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_inference(make_napari_viewer, qtbot):

assert widget.check_ready()

# widget.start() # takes too long on Github Actions (~30min)
# assert widget.worker is not None
#
# with qtbot.waitSignal(signal=widget.worker.finished) as blocker:
# blocker.connect(widget.worker.errored)
#
widget.start() # takes too long on Github Actions (~30min)
assert widget.worker is not None

with qtbot.waitSignal(signal=widget.worker.finished, timeout=60000, raising=False) as blocker:
blocker.connect(widget.worker.errored)

# assert len(viewer.layers) == 2
11 changes: 6 additions & 5 deletions napari_cellseg3d/_tests/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ def test_training(make_napari_viewer, qtbot):

widget.images_filepaths = [im_path]
widget.labels_filepaths = [im_path]
widget.epoch_choice.setValue(1)

assert widget.check_ready()

#################
# Training is too long to test properly this way. Do not use on Github
#################

# widget.start()
# assert widget.worker is not None
#
# with qtbot.waitSignal(signal=widget.worker.finished, timeout=60000) as blocker: # wait only for 60 seconds.
# blocker.connect(widget.worker.errored)
widget.start()
assert widget.worker is not None

with qtbot.waitSignal(signal=widget.worker.finished, timeout=60000, raising=False) as blocker: # wait only for 60 seconds.
blocker.connect(widget.worker.errored)


def test_update_loss_plot(make_napari_viewer):
Expand Down
52 changes: 26 additions & 26 deletions napari_cellseg3d/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def show_utils_menu(self, widget, event):
class Log(QTextEdit):
"""Class to implement a log for important user info. Should be thread-safe."""

def __init__(self, parent):
def __init__(self, parent=None):
"""Creates a log with a lock for multithreading
Args:
Expand All @@ -223,31 +223,31 @@ def __init__(self, parent):

# def receive_log(self, text):
# self.print_and_log(text)
def write(self, message):
"""
Write message to log in a thread-safe manner
Args:
message: string to be printed
"""
self.lock.acquire()
try:
if not hasattr(self, "flag"):
self.flag = False
message = message.replace("\r", "").rstrip()
if message:
method = "replace_last_line" if self.flag else "append"
QtCore.QMetaObject.invokeMethod(
self,
method,
QtCore.Qt.QueuedConnection,
QtCore.Q_ARG(str, message),
)
self.flag = True
else:
self.flag = False

finally:
self.lock.release()
# def write(self, message):
# """
# Write message to log in a thread-safe manner
# Args:
# message: string to be printed
# """
# self.lock.acquire()
# try:
# if not hasattr(self, "flag"):
# self.flag = False
# message = message.replace("\r", "").rstrip()
# if message:
# method = "replace_last_line" if self.flag else "append"
# QtCore.QMetaObject.invokeMethod(
# self,
# method,
# QtCore.Qt.QueuedConnection,
# QtCore.Q_ARG(str, message),
# )
# self.flag = True
# else:
# self.flag = False
#
# finally:
# self.lock.release()

@QtCore.Slot(str)
def replace_last_line(self, text):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install_requires =
tifffile>=2022.2.9
imageio-ffmpeg>=0.4.5
torch>=1.11
monai[nibabel,scikit-image,itk,einops]>=0.9.0
monai[nibabel,itk,einops]>=0.9.0
tqdm
nibabel
scikit-image
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ python =

[gh-actions:env]
PLATFORM =
; ubuntu-latest: linux
ubuntu-latest: linux
; macos-latest: macos
windows-latest: windows
; windows-latest: windows

[testenv]
platform =
linux: linux
; macos: darwin
; linux: linux
windows: win32
; windows: win32
passenv =
CI
PYTHONPATH
Expand Down

0 comments on commit 09333b0

Please sign in to comment.