Skip to content

Commit 58de12e

Browse files
committed
Test IsoColor
Signed-off-by: martinRenou <[email protected]>
1 parent 891ff51 commit 58de12e

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

ipygany/ipygany.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def input_dim(self):
436436
@default('input')
437437
def _default_input(self):
438438
if not len(self.data):
439-
if not self.input_dim:
439+
if self.input_dim == 0 or self.input_dim == 1:
440440
return 0
441441
return tuple(0 for _ in range(self.input_dim))
442442

@@ -531,12 +531,15 @@ class Alpha(Effect):
531531

532532
_model_name = Unicode('AlphaModel').tag(sync=True)
533533

534-
input = Union((Tuple(trait=Unicode, minlen=2, maxlen=2), Unicode(), CFloat(0.))).tag(sync=True)
535-
536534
@default('input')
537535
def _default_input(self):
538536
return 0.7
539537

538+
@property
539+
def input_dim(self):
540+
"""Input dimension."""
541+
return 1
542+
540543

541544
class RGB(Effect):
542545
"""A color effect to another block."""
@@ -551,14 +554,13 @@ class IsoColor(Effect):
551554

552555
_model_name = Unicode('IsoColorModel').tag(sync=True)
553556

554-
input = Union((Tuple(trait=Unicode, minlen=2, maxlen=2), Unicode(), CFloat(0.))).tag(sync=True)
555-
556557
min = CFloat(0.).tag(sync=True)
557558
max = CFloat(0.).tag(sync=True)
558559

559-
@default('input')
560-
def _default_input(self):
561-
return self.parent.data[0].name
560+
@property
561+
def input_dim(self):
562+
"""Input dimension."""
563+
return 1
562564

563565

564566
class IsoSurface(Effect):

tests/test_isocolor.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pytest
2+
3+
from traitlets import TraitError
4+
5+
from ipygany import PolyMesh, IsoColor
6+
7+
from .utils import get_test_assets
8+
9+
10+
def test_default_input():
11+
vertices, triangles, data_1d, data_3d = get_test_assets()
12+
13+
poly = PolyMesh(vertices=vertices, triangle_indices=triangles, data=[data_1d, data_3d])
14+
15+
colored_mesh = IsoColor(poly)
16+
17+
assert colored_mesh.input == '1d'
18+
19+
poly = PolyMesh(vertices=vertices, triangle_indices=triangles, data=[data_3d])
20+
21+
colored_mesh = IsoColor(poly)
22+
23+
assert colored_mesh.input == (('3d', 'x'), )
24+
25+
26+
def test_input():
27+
vertices, triangles, data_1d, data_3d = get_test_assets()
28+
29+
poly = PolyMesh(vertices=vertices, triangle_indices=triangles, data=[data_1d, data_3d])
30+
31+
colored_mesh = IsoColor(poly)
32+
33+
with pytest.raises(TraitError):
34+
colored_mesh.input = ('1d', 0)
35+
36+
colored_mesh.input = ('1d', )
37+
assert colored_mesh.input == (('1d', 'x'), )
38+
39+
colored_mesh.input = (3.2, )
40+
assert colored_mesh.input == (3.2, )
41+
42+
colored_mesh.input = 3.2
43+
assert colored_mesh.input == 3.2

0 commit comments

Comments
 (0)