Skip to content

Commit

Permalink
test: update serdes tests (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jan 22, 2023
1 parent 15aabfb commit d988f5d
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ repos:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
- id: pretty-format-json
args: ["--autofix"]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.226
Expand Down
31 changes: 31 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from useq import MDASequence


@pytest.fixture
def mda1() -> MDASequence:
return MDASequence(
axis_order="tpcz",
metadata={"some info": "something"},
stage_positions=[
(10, 20),
{
"x": 10,
"y": 20,
"z": 50,
"name": "test_name",
"z_plan": {"above": 10, "below": 0, "step": 1},
},
],
channels=[
{"config": "Cy5", "exposure": 50},
{"config": "FITC", "exposure": 100.0},
{"config": "DAPI", "do_stack": False, "acquire_every": 3},
],
time_plan=[
{"interval": 3, "loops": 3},
{"duration": {"minutes": 40}, "interval": 10},
],
z_plan={"range": 1.0, "step": 0.5},
)
78 changes: 78 additions & 0 deletions tests/fixtures/mda.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"axis_order": "tpcz",
"channels": [
{
"acquire_every": 1,
"camera": null,
"config": "Cy5",
"do_stack": true,
"exposure": 50.0,
"group": "Channel",
"z_offset": 0.0
},
{
"acquire_every": 1,
"camera": null,
"config": "FITC",
"do_stack": true,
"exposure": 100.0,
"group": "Channel",
"z_offset": 0.0
},
{
"acquire_every": 3,
"camera": null,
"config": "DAPI",
"do_stack": false,
"exposure": null,
"group": "Channel",
"z_offset": 0.0
}
],
"metadata": {
"some info": "something"
},
"stage_positions": [
{
"name": null,
"x": 10.0,
"y": 20.0,
"z": null,
"z_plan": {
"go_up": true
}
},
{
"name": "test_name",
"x": 10.0,
"y": 20.0,
"z": 50.0,
"z_plan": {
"above": 10.0,
"below": 0.0,
"go_up": true,
"step": 1.0
}
}
],
"time_plan": {
"phases": [
{
"interval": 3.0,
"loops": 3,
"prioritize_duration": false
},
{
"duration": 2400.0,
"interval": 10.0,
"prioritize_duration": true
}
],
"prioritize_duration": false
},
"z_plan": {
"go_up": true,
"range": 1.0,
"step": 0.5
}
}
31 changes: 31 additions & 0 deletions tests/fixtures/mda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
axis_order: tpcz
channels:
- config: Cy5
exposure: 50.0
- config: FITC
exposure: 100.0
- acquire_every: 3
config: DAPI
do_stack: false
metadata:
some info: something
stage_positions:
- x: 10.0
y: 20.0
- name: test_name
x: 10.0
y: 20.0
z: 50.0
z_plan:
above: 10.0
below: 0.0
step: 1.0
time_plan:
phases:
- interval: 0:00:03
loops: 3
- duration: 0:40:00
interval: 0:00:10
z_plan:
range: 1.0
step: 0.5
40 changes: 0 additions & 40 deletions tests/test_json.py

This file was deleted.

18 changes: 18 additions & 0 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
from pathlib import Path

import pytest

from useq import MDASequence


@pytest.mark.parametrize("ext", ["json", "yaml"])
def test_serialization(mda1: MDASequence, ext: str) -> None:
FILE = Path(__file__).parent / "fixtures" / f"mda.{ext}"
text = FILE.read_text()
mda = MDASequence.parse_file(str(FILE))
assert mda == mda1
if ext == "json":
assert json.loads(mda.json(exclude={"uid"})) == json.loads(text)
else:
assert mda.yaml() == text
72 changes: 0 additions & 72 deletions tests/test_yaml.py

This file was deleted.

0 comments on commit d988f5d

Please sign in to comment.