improve coverage
This commit is contained in:
@@ -9,17 +9,23 @@ import backend.nodes # noqa: F401
|
||||
|
||||
def test_load_demo():
|
||||
from backend.nodes.image_demo import ImageDemo
|
||||
from backend.nodes.helpers import DEMO_DIR
|
||||
node = ImageDemo()
|
||||
|
||||
result = node.load(name="nanoparticles.npy")
|
||||
assert len(result) >= 1
|
||||
assert isinstance(result[0], DataField)
|
||||
assert result[0].data.ndim == 2
|
||||
# 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
|
||||
|
||||
result_ibw = node.load(name="whiskers.ibw")
|
||||
assert len(result_ibw) == 4
|
||||
for field in result_ibw:
|
||||
assert isinstance(field, DataField)
|
||||
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")
|
||||
@@ -36,21 +42,26 @@ def test_load_demo_cache():
|
||||
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")
|
||||
_, 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
|
||||
|
||||
third, = node.load(name="nanoparticles.npy")
|
||||
_, 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
|
||||
|
||||
previews = []
|
||||
prompt = {
|
||||
"1": {
|
||||
|
||||
Reference in New Issue
Block a user