Skip to content

Commit

Permalink
Test OWCorrelations: sleep replaced with wait_until_finished
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed May 18, 2020
1 parent 47f4cd9 commit b8dc322
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions Orange/widgets/data/tests/test_owcorrelations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring, protected-access, unsubscriptable-object
import time
import unittest
from unittest.mock import patch, Mock

Expand Down Expand Up @@ -37,7 +36,7 @@ def setUp(self):
def test_input_data_cont(self):
"""Check correlation table for dataset with continuous attributes"""
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
n_attrs = len(self.data_cont.domain.attributes)
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.columnCount(), 3)
Expand All @@ -60,7 +59,7 @@ def test_input_data_mixed(self):
self.send_signal(self.widget.Inputs.data, self.data_mixed)
domain = self.data_mixed.domain
n_attrs = len([a for a in domain.attributes if a.is_continuous])
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.columnCount(), 3)
self.assertEqual(self.widget.vizrank.rank_model.rowCount(),
Expand All @@ -69,7 +68,7 @@ def test_input_data_mixed(self):
def test_input_data_one_feature(self):
"""Check correlation table for dataset with one attribute"""
self.send_signal(self.widget.Inputs.data, self.data_cont[:, [0, 4]])
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.columnCount(), 0)
self.assertTrue(self.widget.Warning.not_enough_vars.is_shown())
Expand All @@ -79,7 +78,7 @@ def test_input_data_one_feature(self):
def test_input_data_one_instance(self):
"""Check correlation table for dataset with one instance"""
self.send_signal(self.widget.Inputs.data, self.data_cont[:1])
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.columnCount(), 0)
self.assertFalse(self.widget.Information.removed_cons_feat.is_shown())
Expand All @@ -97,21 +96,21 @@ def test_input_data_with_constant_features(self):
domain = Domain([ContinuousVariable("c1"), ContinuousVariable("c2"),
DiscreteVariable("d1")])
self.send_signal(self.widget.Inputs.data, Table(domain, X))
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 1)
self.assertFalse(self.widget.Information.removed_cons_feat.is_shown())

domain = Domain([ContinuousVariable(str(i)) for i in range(3)])
self.send_signal(self.widget.Inputs.data, Table(domain, X))
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 1)
self.assertTrue(self.widget.Information.removed_cons_feat.is_shown())

X = np.ones((4, 3), dtype=float)
self.send_signal(self.widget.Inputs.data, Table(domain, X))
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.columnCount(), 0)
self.assertTrue(self.widget.Warning.not_enough_vars.is_shown())
Expand All @@ -124,7 +123,7 @@ def test_input_data_cont_target(self):
"""Check correlation table for dataset with continuous class variable"""
data = self.housing[:5, 11:]
self.send_signal(self.widget.Inputs.data, data)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 2)
self.assertEqual(self.widget.controls.feature.count(), 4)
Expand All @@ -137,15 +136,15 @@ def test_input_data_cont_target(self):
def test_output_data(self):
"""Check dataset on output"""
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
output = self.get_output(self.widget.Outputs.data)
self.assertEqual(self.data_cont, output)

def test_output_features(self):
"""Check features on output"""
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
features = self.get_output(self.widget.Outputs.features)
self.assertIsInstance(features, AttributeList)
Expand All @@ -154,7 +153,7 @@ def test_output_features(self):
def test_output_correlations(self):
"""Check correlation table on on output"""
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
correlations = self.get_output(self.widget.Outputs.correlations)
self.assertIsInstance(correlations, Table)
Expand All @@ -170,27 +169,28 @@ def test_input_changed(self):
"""Check whether changing input emits commit"""
self.widget.commit = Mock()
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.widget.commit.assert_called_once()

self.widget.commit.reset_mock()
self.send_signal(self.widget.Inputs.data, self.data_mixed)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.widget.commit.assert_called_once()

def test_saved_selection(self):
"""Select row from settings"""
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
attrs = self.widget.cont_data.domain.attributes
self.widget._vizrank_selection_changed(attrs[3], attrs[1])
settings = self.widget.settingsHandler.pack_data(self.widget)

w = self.create_widget(OWCorrelations, stored_settings=settings)
self.send_signal(self.widget.Inputs.data, self.data_cont, widget=w)
import time
time.sleep(0.1)
self.process_events()
sel_row = w.vizrank.rank_table.selectionModel().selectedRows()[0].row()
Expand Down Expand Up @@ -227,12 +227,12 @@ def test_heuristic_get_states(self):
def test_correlation_type(self):
c_type = self.widget.controls.correlation_type
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
pearson_corr = self.get_output(self.widget.Outputs.correlations)

simulate.combobox_activate_item(c_type, "Spearman correlation")
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
sperman_corr = self.get_output(self.widget.Outputs.correlations)
self.assertFalse((pearson_corr.X == sperman_corr.X).all())
Expand All @@ -253,23 +253,23 @@ def test_select_feature(self):
"""Test feature selection"""
feature_combo = self.widget.controls.feature
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 6)
self.assertListEqual(["petal length", "petal width"],
[a.name for a in self.get_output(
self.widget.Outputs.features)])

simulate.combobox_activate_index(feature_combo, 1)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 3)
self.assertListEqual(["petal length", "sepal length"],
[a.name for a in self.get_output(
self.widget.Outputs.features)])

simulate.combobox_activate_index(feature_combo, 0)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 6)
self.assertListEqual(["petal length", "sepal length"],
Expand All @@ -279,7 +279,7 @@ def test_select_feature(self):
@patch("Orange.widgets.data.owcorrelations.SIZE_LIMIT", 2000)
def test_vizrank_use_heuristic(self):
self.send_signal(self.widget.Inputs.data, self.data_cont)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertTrue(self.widget.vizrank.use_heuristic)
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 6)
Expand All @@ -290,7 +290,7 @@ def test_select_feature_against_heuristic(self):
feature_combo = self.widget.controls.feature
self.send_signal(self.widget.Inputs.data, self.data_cont)
simulate.combobox_activate_index(feature_combo, 2)
time.sleep(0.1)
self.wait_until_finished()
self.process_events()
self.assertEqual(self.widget.vizrank.rank_model.rowCount(), 3)

Expand Down

0 comments on commit b8dc322

Please sign in to comment.