1
1
import os
2
- from unittest .mock import Mock
2
+
3
+ from AnyQt .QtCore import Qt , QItemSelectionModel
3
4
4
5
from orangewidget .tests .base import WidgetTest
5
6
6
7
from Orange .data import Table , Domain , StringVariable
7
8
8
- from orangecontrib .bioinformatics .widgets .OWGeneSets import OWGeneSets
9
+ from orangecontrib .bioinformatics .geneset import GeneSets
10
+ from orangecontrib .bioinformatics .widgets .OWGeneSets import OWGeneSets , GeneSetsModel
9
11
from orangecontrib .bioinformatics .widgets .utils .data import TableAnnotation
10
12
11
13
@@ -15,33 +17,49 @@ def setUp(self) -> None:
15
17
self .widget = self .create_widget (OWGeneSets )
16
18
17
19
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
+ )
19
23
self .data .attributes [TableAnnotation .tax_id ] = '9606'
20
24
self .data .attributes [TableAnnotation .gene_as_attr_name ] = False
21
25
self .data .attributes [TableAnnotation .gene_id_column ] = 'Entrez ID'
22
26
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 ):
27
28
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 ())
29
31
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. \n 3 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 )
33
35
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 )
38
40
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 )
41
43
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 ):
42
49
self .send_signal (self .widget .Inputs .data , self .data )
43
50
self .wait_until_finished ()
44
- output_sum .assert_called_with ("0" , "0 genes on output.\n " )
45
51
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