|
1 | 1 | # Test methods with long descriptive names can omit docstrings |
2 | 2 | # pylint: disable=missing-docstring |
3 | | -import numpy |
| 3 | +import numpy as np |
4 | 4 | import Orange.misc |
| 5 | +from Orange.data import Table, Domain, ContinuousVariable, DiscreteVariable |
5 | 6 | from Orange.distance import Euclidean |
6 | 7 | from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin |
7 | 8 | from Orange.widgets.unsupervised.owhierarchicalclustering import \ |
@@ -53,16 +54,16 @@ def test_selection_box_output(self): |
53 | 54 | self.assertIsNone(self.get_output(self.widget.Outputs.annotated_data)) |
54 | 55 |
|
55 | 56 | def test_all_zero_inputs(self): |
56 | | - d = Orange.misc.DistMatrix(numpy.zeros((10, 10))) |
| 57 | + d = Orange.misc.DistMatrix(np.zeros((10, 10))) |
57 | 58 | self.widget.set_distances(d) |
58 | 59 |
|
59 | 60 | def test_annotation_settings_retrieval(self): |
60 | 61 | """Check whether widget retrieves correct settings for annotation""" |
61 | 62 | widget = self.widget |
62 | 63 |
|
63 | 64 | dist_names = Orange.misc.DistMatrix( |
64 | | - numpy.zeros((4, 4)), self.data, axis=0) |
65 | | - dist_no_names = Orange.misc.DistMatrix(numpy.zeros((10, 10)), axis=1) |
| 65 | + np.zeros((4, 4)), self.data, axis=0) |
| 66 | + dist_no_names = Orange.misc.DistMatrix(np.zeros((10, 10)), axis=1) |
66 | 67 |
|
67 | 68 | self.send_signal(self.widget.Inputs.distances, self.distances) |
68 | 69 | # Check that default is set (class variable) |
@@ -102,3 +103,23 @@ def test_domain_loses_class(self): |
102 | 103 | data = self.data[:, :4] |
103 | 104 | distances = Euclidean(data) |
104 | 105 | self.send_signal(self.widget.Inputs.distances, distances) |
| 106 | + |
| 107 | + def test_infinite_distances(self): |
| 108 | + """ |
| 109 | + Scipy does not accept infinite distances and neither does this widget. |
| 110 | + Error is shown. |
| 111 | + GH-2380 |
| 112 | + """ |
| 113 | + table = Table( |
| 114 | + Domain( |
| 115 | + [ContinuousVariable("a")], |
| 116 | + [DiscreteVariable("b", values=["y"])]), |
| 117 | + list(zip([1.79e308, -1e120], |
| 118 | + "yy")) |
| 119 | + ) |
| 120 | + distances = Euclidean(table) |
| 121 | + self.assertFalse(self.widget.Error.not_finite_distances.is_shown()) |
| 122 | + self.send_signal(self.widget.Inputs.distances, distances) |
| 123 | + self.assertTrue(self.widget.Error.not_finite_distances.is_shown()) |
| 124 | + self.send_signal(self.widget.Inputs.distances, self.distances) |
| 125 | + self.assertFalse(self.widget.Error.not_finite_distances.is_shown()) |
0 commit comments