55
66import numpy as np
77
8- from Orange .data import Table , Domain
8+ from Orange .data import Table
99from Orange .widgets .data .owtranspose import OWTranspose
1010from Orange .widgets .tests .base import WidgetTest
1111
@@ -32,18 +32,11 @@ def test_feature_type(self):
3232 widget = self .widget
3333 data = Table ("conferences.tab" )
3434 metas = data .domain .metas
35- domain = data .domain
36- # Put one non-string column to metas, so widget must skip it
37- domain2 = Domain (domain .attributes [:- 1 ],
38- domain .class_vars ,
39- (domain .attributes [0 ], ) + domain .metas )
40- data2 = Table (domain2 , data )
41-
4235 widget .feature_type = widget .GENERIC
43- self .send_signal (widget .Inputs .data , data2 )
36+ self .send_signal (widget .Inputs .data , data )
4437
45- # By default, the widget switches from GENERIC to the first string meta
46- self .assertEqual (widget .feature_type , widget .FROM_META_ATTR )
38+ # By default, the widget switches from GENERIC to the first meta
39+ self .assertEqual (widget .feature_type , widget .FROM_VAR )
4740 self .assertIs (widget .feature_names_column , metas [0 ])
4841 output = self .get_output (widget .Outputs .data )
4942 self .assertListEqual (
@@ -54,9 +47,9 @@ def test_feature_type(self):
5447 widget .feature_names_column = metas [1 ]
5548 widget .apply ()
5649 output = self .get_output (widget .Outputs .data )
57- self .assertListEqual (
58- [ a .name for a in output . domain . attributes ],
59- [ metas [ 1 ]. to_val ( m ) for m in data .metas [:, 1 ]] )
50+ self .assertTrue (
51+ all ( a .name . startswith ( metas [ 1 ]. to_val ( m ))
52+ for a , m in zip ( output . domain . attributes , data .metas [:, 1 ])) )
6053
6154 # Switch to generic
6255 self .assertEqual (widget .DEFAULT_PREFIX , "Feature" )
@@ -84,13 +77,13 @@ def test_feature_type(self):
8477
8578 def test_send_report (self ):
8679 widget = self .widget
87- widget .feature_type = widget .FROM_META_ATTR
80+ widget .feature_type = widget .FROM_VAR
8881 widget .report_button .click ()
8982 widget .feature_type = widget .GENERIC
9083 widget .report_button .click ()
9184
9285 self .send_signal (widget .Inputs .data , self .zoo )
93- widget .feature_type = widget .FROM_META_ATTR
86+ widget .feature_type = widget .FROM_VAR
9487 widget .report_button .click ()
9588 widget .feature_type = widget .GENERIC
9689 widget .report_button .click ()
@@ -110,7 +103,7 @@ def test_gui_behaviour(self):
110103 # Data with metas: default type is meta, radio enabled
111104 self .send_signal (widget .Inputs .data , self .zoo )
112105 self .assertTrue (widget .meta_button .isEnabled ())
113- self .assertEqual (widget .feature_type , widget .FROM_META_ATTR )
106+ self .assertEqual (widget .feature_type , widget .FROM_VAR )
114107 self .assertIs (widget .feature_names_column , widget .feature_model [0 ])
115108 self .assertTrue (widget .apply .called )
116109
@@ -123,7 +116,7 @@ def test_gui_behaviour(self):
123116 # Changing combo changes the radio button to meta
124117 widget .apply .reset_mock ()
125118 widget .feature_combo .activated .emit (0 )
126- self .assertEqual (widget .feature_type , widget .FROM_META_ATTR )
119+ self .assertEqual (widget .feature_type , widget .FROM_VAR )
127120 self .assertTrue (widget .apply .called )
128121
129122 def test_all_whitespace (self ):
@@ -141,5 +134,19 @@ def test_error(self):
141134 self .send_signal (widget .Inputs .data , self .zoo )
142135 self .assertFalse (widget .Error .value_error .is_shown ())
143136
137+ def test_feature_names_from_cont_vars (self ):
138+ table = Table ("iris" )
139+ self .send_signal (self .widget .Inputs .data , table )
140+ self .assertListEqual (self .widget .feature_model [:],
141+ list (table .domain .attributes ))
142+ self .widget .feature_combo .activated .emit (3 )
143+ output = self .get_output (self .widget .Outputs .data )
144+ self .assertListEqual ([f .name for f in output .domain .attributes [:10 ]],
145+ ["0.2 (1)" , "0.2 (2)" , "0.2 (3)" , "0.2 (4)" ,
146+ "0.2 (5)" , "0.4 (1)" , "0.3 (1)" , "0.2 (6)" ,
147+ "0.2 (7)" , "0.1 (1)" ])
148+ self .assertTrue (self .widget .Warning .duplicate_names .is_shown ())
149+
150+
144151if __name__ == "__main__" :
145152 unittest .main ()
0 commit comments