Skip to content

Commit

Permalink
update test launch
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypinkard committed Jul 26, 2024
1 parent 2f758e3 commit cce35ce
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 49 deletions.
22 changes: 6 additions & 16 deletions src/exengine/backends/micromanager/test/test_mm_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@
from exengine.events.detector_events import (StartCapture, ReadoutData,
StartContinuousCapture, StopCapture)

@pytest.fixture(scope="module")
def setup_micromanager():
mm_install_dir = get_default_install_location()
config_file = os.path.join(mm_install_dir, 'MMConfig_demo.cfg')
create_core_instance(mm_install_dir, config_file,
buffer_size_mb=1024, max_memory_mb=1024, # set these low for github actions
python_backend=True,
debug=False)
yield
terminate_core_instances()

@pytest.fixture(scope="module")
def executor():
executor = ExecutionEngine()
yield executor
executor.shutdown()

@pytest.fixture
def camera():
def camera(launch_micromanager):
return MicroManagerCamera()

def capture_images(num_images, executor, camera):
# TODO: Replace this with a mock storage class
storage = NDRAMStorage()
data_handler = DataHandler(storage=storage)

Expand All @@ -48,24 +38,24 @@ def capture_images(num_images, executor, camera):

data_handler.finish()

@pytest.mark.usefixtures("setup_micromanager")
@pytest.mark.usefixtures("launch_micromanager")
def test_finite_sequence(executor, camera):
capture_images(100, executor, camera)
print('Finished first one')

@pytest.mark.usefixtures("setup_micromanager")
@pytest.mark.usefixtures("launch_micromanager")
def test_single_image(executor, camera):
capture_images(1, executor, camera)
print('Finished single image')

@pytest.mark.usefixtures("setup_micromanager")
@pytest.mark.usefixtures("launch_micromanager")
def test_multiple_single_image_captures(executor, camera):
for _ in range(5):
capture_images(1, executor, camera)
print('Finished multiple single image captures')


@pytest.mark.usefixtures("setup_micromanager")
@pytest.mark.usefixtures("launch_micromanager")
def test_continuous_capture(executor, camera):
storage = NDRAMStorage()
data_handler = DataHandler(storage=storage)
Expand Down
19 changes: 2 additions & 17 deletions src/exengine/backends/micromanager/test/test_mm_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
from exengine.backends.micromanager.mm_device_implementations import MicroManagerDevice


@pytest.fixture(scope="module")
def setup_micromanager():
mm_install_dir = get_default_install_location()
config_file = os.path.join(mm_install_dir, 'MMConfig_demo.cfg')
create_core_instance(mm_install_dir, config_file,
buffer_size_mb=1024, max_memory_mb=1024, # set these low for github actions
python_backend=True,
debug=False)
yield
terminate_core_instances()

@pytest.fixture(scope="module")
def executor():
Expand All @@ -27,12 +17,7 @@ def executor():
executor.shutdown()

@pytest.fixture(scope="module")
def core(setup_micromanager):
return Core()


@pytest.fixture(scope="module")
def device(core, executor):
def device(launch_micromanager, executor):
return MicroManagerDevice("Camera")


Expand Down Expand Up @@ -123,7 +108,7 @@ def test_stop_triggerable_sequence(device):

# Additional test for a sequenceable property (using the Objective device)
@pytest.fixture(scope="module")
def objective_device(core, executor):
def objective_device(launch_micromanager, executor):
return MicroManagerDevice("Objective")

def test_is_property_hardware_triggerable(objective_device):
Expand Down
45 changes: 45 additions & 0 deletions src/exengine/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import sys
import shutil
import warnings

import pytest
import re
import glob

import socket
from mmpycorex import (download_and_install_mm, find_existing_mm_install, create_core_instance,
terminate_core_instances, get_default_install_location)

@pytest.fixture(scope="session")
def install_mm():
if find_existing_mm_install():
print('Micro-Manager is already installed, skipping installation')
yield find_existing_mm_install()
else:
# Download an install latest nightly build
mm_install_dir = download_and_install_mm(destination='auto')

#### Replace with newer versions of Java libraries ####
# find pycro-manager/java path
if os.path.isdir('java'):
java_path = os.path.abspath('java')
# in case cwd is '/pycromanager/test'
elif os.path.isdir('../../java'):
java_path = os.path.abspath('../../java')
else:
raise RuntimeError('Could not find pycro-manager/java path')

yield mm_install_dir


@pytest.fixture(scope="session")
def launch_micromanager(install_mm):
mm_install_dir = get_default_install_location()
config_file = os.path.join(mm_install_dir, 'MMConfig_demo.cfg')
create_core_instance(mm_install_dir, config_file,
buffer_size_mb=1024, max_memory_mb=1024, # set these low for github actions
python_backend=True,
debug=False)
yield
terminate_core_instances()
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,20 @@
from exengine.events.detector_events import StartCapture, ReadoutData


@pytest.fixture(scope="module")
def setup_micromanager():
mm_install_dir = get_default_install_location()
config_file = os.path.join(mm_install_dir, 'MMConfig_demo.cfg')
create_core_instance(mm_install_dir, config_file,
buffer_size_mb=1024, max_memory_mb=1024,
python_backend=True,
debug=False)
yield
terminate_core_instances()


@pytest.fixture(scope="module")
def execution_engine():
return ExecutionEngine()


@pytest.fixture(scope="module")
def devices():
def devices(launch_micromanager):
z_device = MicroManagerSingleAxisStage('Z')
camera_device = MicroManagerCamera()
xy_device = MicroManagerXYStage()
return z_device, camera_device, xy_device


def test_non_sequenced_z_stack(setup_micromanager, execution_engine, devices):
def test_non_sequenced_z_stack(execution_engine, devices):
z_device, camera_device, _ = devices
storage = NDRAMStorage()
data_handler = DataHandler(storage)
Expand All @@ -68,7 +56,7 @@ def test_non_sequenced_z_stack(setup_micromanager, execution_engine, devices):
data_handler.finish()


def test_sequenced_z_stack(setup_micromanager, execution_engine, devices):
def test_sequenced_z_stack(execution_engine, devices):
z_device, camera_device, _ = devices
storage = NDRAMStorage()
data_handler = DataHandler(storage)
Expand All @@ -94,7 +82,7 @@ def test_sequenced_z_stack(setup_micromanager, execution_engine, devices):
assert all(means)


def test_sequence_over_channels(setup_micromanager, execution_engine, devices):
def test_sequence_over_channels(execution_engine, devices):
_, camera_device, _ = devices
storage = NDRAMStorage()
data_handler = DataHandler(storage)
Expand Down

0 comments on commit cce35ce

Please sign in to comment.