Skip to content

Commit febbff3

Browse files
committed
test_OWGeneSets: update tests
1 parent 8fae52c commit febbff3

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import os
2-
from unittest.mock import Mock
2+
3+
from AnyQt.QtCore import Qt, QItemSelectionModel
34

45
from orangewidget.tests.base import WidgetTest
56

67
from Orange.data import Table, Domain, StringVariable
78

8-
from orangecontrib.bioinformatics.widgets.OWGeneSets import OWGeneSets
9+
from orangecontrib.bioinformatics.geneset import GeneSets
10+
from orangecontrib.bioinformatics.widgets.OWGeneSets import OWGeneSets, GeneSetsModel
911
from orangecontrib.bioinformatics.widgets.utils.data import TableAnnotation
1012

1113

@@ -15,33 +17,49 @@ def setUp(self) -> None:
1517
self.widget = self.create_widget(OWGeneSets)
1618

1719
domain = Domain([], metas=[StringVariable('name'), StringVariable('Entrez ID')])
18-
self.data = Table.from_list(domain, [['CA1', '759'], ['CA2', '760'], ['CA3', '761']])
20+
self.data = Table.from_list(
21+
domain, [['CA1', '759'], ['CA2', '760'], ['CA3', '761']]
22+
)
1923
self.data.attributes[TableAnnotation.tax_id] = '9606'
2024
self.data.attributes[TableAnnotation.gene_as_attr_name] = False
2125
self.data.attributes[TableAnnotation.gene_id_column] = 'Entrez ID'
2226

23-
def test_input_info(self):
24-
input_sum = self.widget.info.set_input_summary = Mock()
25-
26-
self.send_signal(self.widget.Inputs.data, self.data)
27+
def test_gene_sets_loaded(self):
2728
self.wait_until_finished()
28-
input_sum.assert_called_with("3", "3 unique gene names on input.\n")
29+
self.assertTrue(self.widget.filter_proxy_model.sourceModel().rowCount())
30+
self.assertTrue(self.widget.filter_proxy_model.sourceModel().columnCount())
2931

30-
self.send_signal(self.widget.Inputs.custom_gene_sets, self.data)
31-
self.wait_until_finished()
32-
input_sum.assert_called_with("3|3", "3 unique gene names on input.\n3 marker genes in 3 sets\n")
32+
def test_gene_set_selection(self):
33+
first_row = self.widget.view.model().index(0, 0)
34+
second_row = self.widget.view.model().index(1, 0)
3335

34-
self.send_signal(self.widget.Inputs.data, None)
35-
self.send_signal(self.widget.Inputs.custom_gene_sets, None)
36-
self.wait_until_finished()
37-
input_sum.assert_called_with(self.widget.info.NoInput)
36+
selection_model = self.widget.view.selectionModel()
37+
selection_flags = QItemSelectionModel.Select | QItemSelectionModel.Rows
38+
selection_model.select(first_row, selection_flags)
39+
selection_model.select(second_row, selection_flags)
3840

39-
def test_output_info(self):
40-
output_sum = self.widget.info.set_output_summary = Mock()
41+
selection = selection_model.selectedRows(column=GeneSetsModel.genes_in_set)
42+
self.assertTrue(len(selection) == 2)
4143

44+
output = self.get_output(self.widget.Outputs.gene_sets)
45+
self.assertIsInstance(output, GeneSets)
46+
self.assertTrue(len(output) == 2)
47+
48+
def test_input_data(self):
4249
self.send_signal(self.widget.Inputs.data, self.data)
4350
self.wait_until_finished()
44-
output_sum.assert_called_with("0", "0 genes on output.\n")
4551

46-
self.send_signal(self.widget.Inputs.data, None)
47-
output_sum.assert_called_with(self.widget.info.NoOutput)
52+
first_row = self.widget.view.model().index(0, 0)
53+
tenth_row = self.widget.view.model().index(10, 0)
54+
55+
selection_model = self.widget.view.selectionModel()
56+
selection_flags = QItemSelectionModel.Select | QItemSelectionModel.Rows
57+
selection_model.select(first_row, selection_flags)
58+
selection_model.select(tenth_row, selection_flags)
59+
60+
selection = selection_model.selectedRows(column=GeneSetsModel.mapped_genes)
61+
62+
# all genes from the data are found in first gene set
63+
self.assertTrue(selection[0].data(Qt.DisplayRole))
64+
# non genes map to 10th gene set
65+
self.assertFalse(selection[1].data(Qt.DisplayRole))

0 commit comments

Comments
 (0)