fix test missing files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import numpy as np
|
||||
@@ -6,71 +6,76 @@ from backend.data_types import DataField
|
||||
from backend.execution import ExecutionEngine
|
||||
import backend.nodes # noqa: F401
|
||||
|
||||
FIXTURES = Path(__file__).parent.parent / "output"
|
||||
|
||||
def test_load_demo():
|
||||
|
||||
def test_load_npy():
|
||||
from backend.nodes.image_demo import ImageDemo
|
||||
from backend.nodes.helpers import DEMO_DIR
|
||||
node = ImageDemo()
|
||||
|
||||
result = node.load(name="nanoparticles.npy")
|
||||
with patch("backend.nodes.image_demo.DEMO_DIR", FIXTURES):
|
||||
result = ImageDemo().load(name="nanoparticles.npy")
|
||||
|
||||
# result[0] is the FILE_PATH string, fields follow
|
||||
assert len(result) >= 2
|
||||
assert isinstance(result[0], str)
|
||||
assert isinstance(result[1], DataField)
|
||||
assert result[1].data.ndim == 2
|
||||
|
||||
ibw_path = DEMO_DIR / "whiskers.ibw"
|
||||
if ibw_path.exists():
|
||||
result_ibw = node.load(name="whiskers.ibw")
|
||||
fields = [v for v in result_ibw if isinstance(v, DataField)]
|
||||
assert len(fields) == 4
|
||||
for field in fields:
|
||||
assert isinstance(field, DataField)
|
||||
|
||||
try:
|
||||
node.load(name="nonexistent_file.png")
|
||||
assert False, "Should have raised FileNotFoundError"
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
def test_load_ibw_multi_channel():
|
||||
from backend.nodes.image_demo import ImageDemo
|
||||
|
||||
with patch("backend.nodes.image_demo.DEMO_DIR", FIXTURES):
|
||||
result = ImageDemo().load(name="Bacteria.ibw")
|
||||
|
||||
fields = [v for v in result if isinstance(v, DataField)]
|
||||
assert len(fields) == 4
|
||||
for field in fields:
|
||||
assert field.data.ndim == 2
|
||||
|
||||
|
||||
def test_load_demo_cache():
|
||||
def test_load_not_found():
|
||||
from backend.nodes.image_demo import ImageDemo
|
||||
|
||||
with patch("backend.nodes.image_demo.DEMO_DIR", FIXTURES):
|
||||
try:
|
||||
ImageDemo().load(name="nonexistent_file.png")
|
||||
assert False, "Should have raised FileNotFoundError"
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def test_load_cache():
|
||||
from backend.nodes.image import Image
|
||||
from backend.nodes.image_demo import ImageDemo
|
||||
|
||||
node = ImageDemo()
|
||||
Image._load_fields_cached.cache_clear()
|
||||
|
||||
with patch.object(Image, "_load_image_or_array", wraps=Image._load_image_or_array) as loader:
|
||||
_, first = node.load(name="nanoparticles.npy")
|
||||
_, second = node.load(name="nanoparticles.npy")
|
||||
assert loader.call_count == 1
|
||||
with patch("backend.nodes.image_demo.DEMO_DIR", FIXTURES):
|
||||
with patch.object(Image, "_load_image_or_array", wraps=Image._load_image_or_array) as loader:
|
||||
_, first = node.load(name="nanoparticles.npy")
|
||||
_, second = node.load(name="nanoparticles.npy")
|
||||
assert loader.call_count == 1
|
||||
|
||||
assert np.allclose(first.data, second.data)
|
||||
assert first is not second
|
||||
first.data[0, 0] = -999.0
|
||||
assert np.allclose(first.data, second.data)
|
||||
assert first is not second
|
||||
first.data[0, 0] = -999.0
|
||||
|
||||
_, third = node.load(name="nanoparticles.npy")
|
||||
assert third.data[0, 0] != -999.0
|
||||
_, third = node.load(name="nanoparticles.npy")
|
||||
assert third.data[0, 0] != -999.0
|
||||
|
||||
Image._load_fields_cached.cache_clear()
|
||||
|
||||
|
||||
def test_load_demo_multi_layer_preview_payload():
|
||||
from backend.nodes.helpers import DEMO_DIR
|
||||
ibw_path = DEMO_DIR / "whiskers.ibw"
|
||||
if not ibw_path.exists():
|
||||
return
|
||||
|
||||
def test_multi_layer_preview_payload():
|
||||
previews = []
|
||||
prompt = {
|
||||
"1": {
|
||||
"class_type": "ImageDemo",
|
||||
"inputs": {"name": "whiskers.ibw", "colormap": "viridis"},
|
||||
},
|
||||
}
|
||||
|
||||
ExecutionEngine().execute(prompt, on_preview=lambda node_id, payload: previews.append((node_id, payload)))
|
||||
with patch("backend.nodes.image_demo.DEMO_DIR", FIXTURES):
|
||||
ExecutionEngine().execute(
|
||||
{"1": {"class_type": "ImageDemo", "inputs": {"name": "Bacteria.ibw", "colormap": "viridis"}}},
|
||||
on_preview=lambda node_id, payload: previews.append((node_id, payload)),
|
||||
)
|
||||
|
||||
assert len(previews) == 1
|
||||
node_id, payload = previews[0]
|
||||
|
||||
BIN
tests/output/Bacteria.ibw
Normal file
BIN
tests/output/Bacteria.ibw
Normal file
Binary file not shown.
Reference in New Issue
Block a user