Beispiel #1
0
 def restore(view, selection):
     with signal_blocking(view.selectionModel()):
         # gymnastics for transforming variable names back to indices
         var_list = [var for var in self.data.domain.variables
                     if var.is_continuous and var is not
                     self.data.time_variable]
         indices = [var_list.index(i) for i in selection]
         select_rows(view, indices)
Beispiel #2
0
    def test_copy_to_manual(self):
        w = self.widget
        w.var_hints = {DefaultKey: VarHint(Methods.EqualFreq, (5, ))}
        self.send_signal(w.Inputs.data, self.data)
        w.button_group.button(Methods.MDL).setChecked(True)

        select_rows(w.varview, (0, 2))
        self.assertTrue(w.copy_to_custom.isEnabled())
        w.copy_to_custom.click()
        self.assertFalse(
            any(w.button_group.button(i).isChecked() for i in Methods))
        self.assertEqual(w.var_hints[("x", False)],
                         VarHint(Methods.Custom, ('2.5, 7.5, 12.5', )))
        self.assertEqual(w.var_hints[("z", False)],
                         VarHint(Methods.Custom, ('4.5, 9.5, 14.5', )))
        self.assertNotIn(("y", False), w.var_hints)

        select_rows(w.varview, (1, ))
        self.assertTrue(w.copy_to_custom.isEnabled())
        w.copy_to_custom.click()
        self.assertTrue(w.button_group.button(Methods.Custom).isChecked())
        self.assertEqual(w.var_hints[("x", False)],
                         VarHint(Methods.Custom, ('2.5, 7.5, 12.5', )))
        self.assertEqual(w.var_hints[("z", False)],
                         VarHint(Methods.Custom, ('4.5, 9.5, 14.5', )))
        self.assertEqual(w.var_hints[("y", False)],
                         VarHint(Methods.Custom, ('3.5, 8.5, 13.5', )))
        self.assertEqual(w.threshold_line.text(), '3.5, 8.5, 13.5')

        select_rows(w.varview, (1, 4))
        w.copy_to_custom.click()
        self.assertNotIn(("u", False), w.var_hints)
 def test_saved_selection(self):
     self.widget.chosen_operation = self.widget.Operation.DIFF
     self.send_signal(self.widget.Inputs.time_series, self.data)
     output = self.get_output(self.widget.Outputs.time_series)
     # first item is selected and computed
     self.assertEqual(len(output.domain.variables),
                      len(self.data.domain.variables) + 1)
     self.assertTrue("Latitude [°] (diff; order=1)" in output.domain)
     # select some items
     select_rows(self.widget.view, [2, 3, 4])
     output = self.get_output(self.widget.Outputs.time_series)
     self.assertEqual(len(output.domain.variables),
                      len(self.data.domain.variables) + 3)
     # send None
     self.send_signal(self.widget.Inputs.time_series, None)
     self.assertIsNone(self.get_output(self.widget.Outputs.time_series))
     # test if settings are properly restored
     self.send_signal(self.widget.Inputs.time_series, self.data)
     output = self.get_output(self.widget.Outputs.time_series)
     self.assertEqual(len(output.domain.variables),
                      len(self.data.domain.variables) + 3)
     self.assertEqual(len(self.widget.selected), 3)
     self.assertFalse("Latitude [°] (diff; order=1)" in output.domain)
Beispiel #4
0
 def restore(view, indices):
     with itemmodels.signal_blocking(view.selectionModel()):
         select_rows(view, indices)
Beispiel #5
0
    def test_update_hints(self):
        w = self.widget
        update_disc = w._update_discretizations
        w._update_discretizations = Mock()
        w.width_line.setText("10")
        self.send_signal(w.Inputs.data, self.data)
        w.var_hints = {
            DefaultKey: DefaultHint,
            ("x", False): VarHint(Methods.EqualFreq, (3, )),
            ("y", False): VarHint(Methods.EqualFreq, (3, )),
            ("z", False): VarHint(Methods.EqualFreq, (4, )),
            ("t", True): VarHint(Methods.Binning, (5, ))
        }
        update_disc()
        self.assertEqual(len(w.discretized_vars), 5)

        select_rows(w.varview, (0, ))
        w.button_group.button(Methods.Default).click()
        self.assertNotIn(("x", False), w.var_hints)
        # Check that "x" is invalidated
        self.assertEqual(len(w.discretized_vars), 4)
        self.assertNotIn(("x", False), w.discretized_vars)
        update_disc()
        self.assertEqual(len(w.discretized_vars), 5)
        self.assertIn(("x", False), w.discretized_vars)

        select_rows(w.varview, (0, 1))
        w.button_group.button(Methods.FixedWidth).click()
        self.assertEqual(w.var_hints[("x", False)],
                         VarHint(Methods.FixedWidth, ("10", )))
        self.assertEqual(w.var_hints[("y", False)],
                         VarHint(Methods.FixedWidth, ("10", )))
        # Check that "x" and "y" are invalidated
        self.assertEqual(len(w.discretized_vars), 3)
        self.assertNotIn(("x", False), w.discretized_vars)
        self.assertNotIn(("y", False), w.discretized_vars)
        update_disc()
        self.assertEqual(len(w.discretized_vars), 5)
        self.assertIn(("x", False), w.discretized_vars)
        self.assertIn(("y", False), w.discretized_vars)

        w.width_line.setText("5")
        self.assertEqual(w.var_hints[("x", False)],
                         VarHint(Methods.FixedWidth, ("5", )))
        self.assertEqual(w.var_hints[("y", False)],
                         VarHint(Methods.FixedWidth, ("5", )))
        # Check that "x" and "y" are invalidated
        self.assertEqual(len(w.discretized_vars), 3)
        self.assertNotIn(("x", False), w.discretized_vars)
        self.assertNotIn(("y", False), w.discretized_vars)
        update_disc()
        self.assertEqual(len(w.discretized_vars), 5)
        self.assertIn(("x", False), w.discretized_vars)
        self.assertIn(("y", False), w.discretized_vars)

        select_rows(w.varview.default_view, (0, ))
        w.button_group.button(Methods.FixedWidth).click()
        self.assertEqual(len(w.discretized_vars), 4)
        self.assertNotIn(("u", True), w.discretized_vars)
        update_disc()
        self.assertEqual(len(w.discretized_vars), 5)
        self.assertIn(("u", True), w.discretized_vars)
Beispiel #6
0
    def test_change_selection_update_interface(self):
        w = self.widget
        self.send_signal(w.Inputs.data, self.data)
        w.var_hints = {
            DefaultKey: DefaultHint,
            ("x", False): VarHint(Methods.FixedWidth, ("10", )),
            ("y", False): VarHint(Methods.FixedWidth, ("10", )),
            ("z", False): VarHint(Methods.FixedWidth, ("5", )),
            ("t", False): VarHint(Methods.Binning, (5, ))
        }

        select_rows(w.varview, (0, 1))
        self.assertTrue(w.button_group.button(Methods.FixedWidth).isChecked())
        self.assertTrue(w.button_group.button(Methods.FixedWidth).isEnabled())
        self.assertFalse(
            w.button_group.button(Methods.FixedWidthTime).isEnabled())
        self.assertTrue(w.button_group.button(Methods.Custom).isEnabled())
        self.assertTrue(w.copy_to_custom.isEnabled())
        self.assertEqual(w.width_line.text(), "10")

        select_rows(w.varview, (1, 2))
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isChecked())
        self.assertTrue(w.button_group.button(Methods.FixedWidth).isEnabled())
        self.assertFalse(
            w.button_group.button(Methods.FixedWidthTime).isEnabled())
        self.assertTrue(w.button_group.button(Methods.Custom).isEnabled())
        self.assertTrue(w.copy_to_custom.isEnabled())

        select_rows(w.varview, (2, 4))
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isChecked())
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isEnabled())
        self.assertFalse(
            w.button_group.button(Methods.FixedWidthTime).isEnabled())
        self.assertFalse(w.button_group.button(Methods.Custom).isEnabled())

        select_rows(w.varview, (3, 4))
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isChecked())
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isEnabled())
        self.assertTrue(
            w.button_group.button(Methods.FixedWidthTime).isEnabled())
        self.assertFalse(w.button_group.button(Methods.Custom).isEnabled())
        self.assertFalse(w.copy_to_custom.isEnabled())

        select_rows(w.varview.default_view, (0, ))
        self.assertEqual(len(w.varview.selectionModel().selectedIndexes()), 0)
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isChecked())
        self.assertTrue(w.button_group.button(Methods.FixedWidth).isEnabled())
        self.assertTrue(
            w.button_group.button(Methods.FixedWidthTime).isEnabled())
        self.assertTrue(w.button_group.button(Methods.Custom).isEnabled())
        self.assertFalse(w.copy_to_custom.isEnabled())
        self.assertFalse(w.button_group.button(Methods.Default).isEnabled())
        w._check_button(Methods.FixedWidth, True)
        self.assertTrue(w.button_group.button(Methods.FixedWidth).isChecked())

        select_rows(w.varview, (3, ))
        self.assertEqual(
            len(w.varview.default_view.selectionModel().selectedIndexes()), 0)
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isChecked())
        self.assertFalse(w.button_group.button(Methods.FixedWidth).isEnabled())
        self.assertTrue(
            w.button_group.button(Methods.FixedWidthTime).isEnabled())
        self.assertFalse(w.button_group.button(Methods.Custom).isEnabled())
        self.assertTrue(w.button_group.button(Methods.Default).isEnabled())
Beispiel #7
0
 def test_varkeys_for_selection(self):
     w = self.widget
     self.send_signal(w.Inputs.data, self.data)
     select_rows(w.varview, (0, 4))
     self.assertEqual(w.varkeys_for_selection(), [("x", False),
                                                  ("u", True)])
Beispiel #8
0
 def select_default_variable(self):
     self.selected = [0]
     select_rows(self.view, self.selected)