Skip to content

Commit e3540c3

Browse files
committed
made specific tests for every layer type
1 parent 206f71f commit e3540c3

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

src/napari_matplotlib/tests/test_histogram.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ def test_histogram_3D(make_napari_viewer, brain_data):
3636

3737

3838
def test_feature_histogram(make_napari_viewer):
39+
3940
n_points = 1000
4041
random_points = np.random.random((n_points, 3)) * 10
42+
random_directions = np.random.random((n_points, 3)) * 10
43+
random_vectors = np.stack([random_points, random_directions], axis=1)
4144
feature1 = np.random.random(n_points)
4245
feature2 = np.random.normal(size=n_points)
4346

@@ -47,10 +50,10 @@ def test_feature_histogram(make_napari_viewer):
4750
properties={"feature1": feature1, "feature2": feature2},
4851
name="points1",
4952
)
50-
viewer.add_points(
51-
random_points,
53+
viewer.add_vectors(
54+
random_vectors,
5255
properties={"feature1": feature1, "feature2": feature2},
53-
name="points2",
56+
name="vectors1",
5457
)
5558

5659
widget = FeaturesHistogramWidget(viewer)
@@ -70,26 +73,44 @@ def test_feature_histogram(make_napari_viewer):
7073

7174

7275
@pytest.mark.mpl_image_compare
73-
def test_feature_histogram2(make_napari_viewer):
74-
import numpy as np
76+
def test_feature_histogram_vectors(make_napari_viewer):
77+
78+
n_points = 1000
79+
np.random.seed(42)
80+
random_points = np.random.random((n_points, 3)) * 10
81+
random_directions = np.random.random((n_points, 3)) * 10
82+
random_vectors = np.stack([random_points, random_directions], axis=1)
83+
feature1 = np.random.random(n_points)
84+
85+
viewer = make_napari_viewer()
86+
viewer.add_vectors(
87+
random_vectors,
88+
properties={"feature1": feature1},
89+
name="vectors1",
90+
)
91+
92+
widget = FeaturesHistogramWidget(viewer)
93+
viewer.window.add_dock_widget(widget)
94+
widget._set_axis_keys("feature1")
95+
96+
fig = FeaturesHistogramWidget(viewer).figure
97+
return deepcopy(fig)
98+
99+
100+
@pytest.mark.mpl_image_compare
101+
def test_feature_histogram_points(make_napari_viewer):
75102

76103
np.random.seed(0)
77104
n_points = 1000
78105
random_points = np.random.random((n_points, 3)) * 10
79106
feature1 = np.random.random(n_points)
80-
feature2 = np.random.normal(size=n_points)
81107

82108
viewer = make_napari_viewer()
83109
viewer.add_points(
84110
random_points,
85-
properties={"feature1": feature1, "feature2": feature2},
111+
properties={"feature1": feature1},
86112
name="points1",
87113
)
88-
viewer.add_points(
89-
random_points,
90-
properties={"feature1": feature1, "feature2": feature2},
91-
name="points2",
92-
)
93114

94115
widget = FeaturesHistogramWidget(viewer)
95116
viewer.window.add_dock_widget(widget)
@@ -120,3 +141,8 @@ def test_change_layer(make_napari_viewer, brain_data, astronaut_data):
120141
viewer.layers.selection.clear()
121142
viewer.layers.selection.add(viewer.layers[1])
122143
assert_figures_not_equal(widget.figure, fig1)
144+
145+
146+
if __name__ == '__main__':
147+
import napari
148+
test_feature_histogram_points(napari.Viewer)

0 commit comments

Comments
 (0)