def __init__(self, *args, **kwargs): GtkTestCase.__init__(self, *args, **kwargs) self._test_time = 0.1 self._test_button = Gtk.Button() self._test_window = Gtk.Window() FocusStealingHelperMock.__init__(self, self._test_window, self._test_button, self._test_time)
def test_apply_model(self): new_object = Gtk.ComboBox() self.assertIsNone(new_object.get_model()) self.apply_model(new_object) self.assertIsNotNone(new_object.get_model())
def test_invalid_qube_name(self): self.apply_model(Gtk.ComboBox()) for name in [ "test-nonexistant", None, "", 1 ]: mock = MockComboEntry(name) self.assertIsNone(self._get_valid_qube_name(mock, mock, [])) self.assertIsNone(self._get_valid_qube_name(None, mock, [])) self.assertIsNone(self._get_valid_qube_name(mock, None, []))
def test_apply_icon_only_existing(self): new_object = Gtk.Entry() for name in [ "test-red1", "test-red2", "test-red3", "test-target", "test-disp6" ]: self.apply_icon(new_object, name) for name in [ "test-nonexistant", None, "", 1 ]: with self.assertRaises(ValueError): self.apply_icon(new_object, name)
def test_apply_icon(self): new_object = Gtk.Entry() self.assertIsNone( new_object.get_icon_pixbuf(Gtk.EntryIconPosition.PRIMARY)) self.apply_icon(new_object, "test-disp6") self.assertIsNotNone( new_object.get_icon_pixbuf(Gtk.EntryIconPosition.PRIMARY))
def test_valid_qube_name_exceptions(self): list_exc = ["test-disp6", "test-red2"] self.apply_model(Gtk.ComboBox(), [VMListModeler.NameBlacklistFilter([ list_exc[0], list_exc[1] ]) ]) for name in list_exc: mock = MockComboEntry(name) self.assertIsNone(self._get_valid_qube_name(mock, mock, list_exc)) self.assertIsNone(self._get_valid_qube_name(None, mock, list_exc)) self.assertIsNone(self._get_valid_qube_name(mock, None, list_exc))
def test_valid_qube_name(self): self.apply_model(Gtk.ComboBox()) for name in [ "test-red1", "test-red2", "test-red3", "test-target", "test-disp6" ]: mock = MockComboEntry(name) self.assertEquals(name, self._get_valid_qube_name(mock, mock, [])) self.assertEquals(name, self._get_valid_qube_name(None, mock, [])) self.assertEquals(name, self._get_valid_qube_name(mock, None, [])) self.assertIsNone(self._get_valid_qube_name(None, None, []))
def flush_gtk_events(self, wait_seconds = 0): start = time.time() iterations = 0 remaining_wait = wait_seconds time_length = 0 if wait_seconds < 0: raise ValueError("Only non-negative intervals are allowed.") while remaining_wait >= 0: while Gtk.events_pending(): Gtk.main_iteration_do(blocking = False) iterations += 1 time_length = time.time() - start remaining_wait = wait_seconds - time_length if (remaining_wait > 0): time.sleep(self._smallest_wait) return (iterations, time_length)
def test_apply_model_whitelist(self): combo = Gtk.ComboBox() self.apply_model(combo) self.assertEquals(7, len(combo.get_model())) self.apply_model(combo, [ VMListModeler.NameWhitelistFilter([ self._entries.keys()[0] ]) ]) self.assertEquals(1, len(combo.get_model())) self.apply_model(combo, [ VMListModeler.NameWhitelistFilter([ self._entries.keys()[0], self._entries.keys()[1] ]) ]) self.assertEquals(2, len(combo.get_model()))
def test_apply_model_multiple_filters(self): combo = Gtk.ComboBox() self.apply_model(combo) self.assertEquals(7, len(combo.get_model())) self.apply_model(combo, [ VMListModeler.NameWhitelistFilter([ self._entries.keys()[0], self._entries.keys()[1], self._entries.keys()[2], self._entries.keys()[3], self._entries.keys()[4] ]), VMListModeler.NameBlacklistFilter([ self._entries.keys()[0], self._entries.keys()[1] ]) ]) self.assertEquals(3, len(combo.get_model()))
def test_apply_icon_only_entry(self): invalid_types = [ 1, "One", u'1', {'1': "one"}, Gtk.ComboBox()] for invalid_type in invalid_types: with self.assertRaises(TypeError): self.apply_icon(invalid_type, "test-disp6")