def itest_editor(self):
        # import default geography data
        import bauble.paths as paths
        default_path = os.path.join(paths.lib_dir(), "plugins", "plants",
                                "default")
        filenames = [os.path.join(default_path, f) for f in 'geography.txt',
                     'habit.txt']
        from bauble.plugins.imex.csv_ import CSVImporter
        importer = CSVImporter()
        importer.start(filenames, force=True)

        f = Family(family=u'family')
        g2 = Genus(genus=u'genus2', family=f)
        g = Genus(genus=u'genus', family=f)
        g2.synonyms.append(g)
        self.session.add(f)
        self.session.commit()
        sp = Species(genus=g, sp=u'sp')
        e = SpeciesEditor(model=sp)
        e.start()
        del e
        assert utils.gc_objects_by_type('SpeciesEditor') == [], \
            'SpeciesEditor not deleted'
        assert utils.gc_objects_by_type('SpeciesEditorPresenter') == [], \
            'SpeciesEditorPresenter not deleted'
        assert utils.gc_objects_by_type('SpeciesEditorView') == [], \
            'SpeciesEditorView not deleted'
    def test_location_editor(self):
        loc = self.create(Location, name=u'some site', code=u'STE')
        self.session.commit()
        editor = LocationEditor(model=loc)
        update_gui()
        widgets = editor.presenter.view.widgets

        # test that the accept buttons are NOT sensitive since nothing
        # has changed and that the text entries and model are the same
        assert widgets.loc_name_entry.get_text() == loc.name
        assert widgets.loc_code_entry.get_text() == loc.code
        assert not widgets.loc_ok_button.props.sensitive
        assert not widgets.loc_next_button.props.sensitive

        # test the accept buttons become sensitive when the name entry
        # is changed
        widgets.loc_name_entry.set_text('something')
        update_gui()
        assert widgets.loc_ok_button.props.sensitive
        assert widgets.loc_ok_and_add_button.props.sensitive
        assert widgets.loc_next_button.props.sensitive

        # test the accept buttons become NOT sensitive when the code
        # entry is empty since this is a required field
        widgets.loc_code_entry.set_text('')
        update_gui()
        assert not widgets.loc_ok_button.props.sensitive
        assert not widgets.loc_ok_and_add_button.props.sensitive
        assert not widgets.loc_next_button.props.sensitive

        # test the accept buttons aren't sensitive from setting the textview
        import gtk
        buff = gtk.TextBuffer()
        buff.set_text('saasodmadomad')
        widgets.loc_desc_textview.set_buffer(buff)
        assert not widgets.loc_ok_button.props.sensitive
        assert not widgets.loc_ok_and_add_button.props.sensitive
        assert not widgets.loc_next_button.props.sensitive

        # commit the changes and cleanup
        editor.model.name = editor.model.code = u'asda'
        editor.handle_response(gtk.RESPONSE_OK)
        editor.session.close()
        editor.presenter.cleanup()
        del editor

        assert utils.gc_objects_by_type('LocationEditor') == [], \
            'LocationEditor not deleted'
        assert utils.gc_objects_by_type('LocationEditorPresenter') == [], \
            'LocationEditorPresenter not deleted'
        assert utils.gc_objects_by_type('LocationEditorView') == [], \
            'LocationEditorView not deleted'
示例#3
0
 def test_editor(self):
     """
     Interactively test the PlantEditor
     """
     raise SkipTest("Not Implemented")
     # loc = self.create(Family, name=u'some site')
     fam = Family(family="some family")
     editor = FamilyEditor(model=fam)
     editor.start()
     del editor
     assert utils.gc_objects_by_type("FamilyEditor") == [], "FamilyEditor not deleted"
     assert utils.gc_objects_by_type("FamilyEditorPresenter") == [], "FamilyEditorPresenter not deleted"
     assert utils.gc_objects_by_type("FamilyEditorView") == [], "FamilyEditorView not deleted"
 def itest_contact_editor(self):
     """
     Interactively test the PlantEditor
     """
     loc = self.create(Contact, name=u'some contact')
     editor = ContactEditor(model=loc)
     editor.start()
     del editor
     assert utils.gc_objects_by_type('ContactEditor') == [], \
         'ContactEditor not deleted'
     assert utils.gc_objects_by_type('ContactEditorPresenter') == [], \
         'ContactEditorPresenter not deleted'
     assert utils.gc_objects_by_type('ContactEditorView') == [], \
         'ContactEditorView not deleted'
 def tearDown(self):
     super(GardenTestCase, self).tearDown()
     if hasattr(self, 'editor') and self.editor is not None:
         editor_name = self.editor.__class__.__name__
         presenter_name = self.editor.presenter.__class__.__name__
         view_name = self.editor.presenter.view.__class__.__name__
         self.editor.presenter.cleanup()
         del self.editor
         assert utils.gc_objects_by_type(editor_name) == [], \
             '%s not deleted' % editor_name
         assert utils.gc_objects_by_type(presenter_name) == [], \
             '%s not deleted' % presenter_name
         assert utils.gc_objects_by_type(view_name) == [], \
             '%s not deleted' % view_name
 def itest_editor(self):
     """
     Interactively test the PlantEditor
     """
     loc = self.create(Location, name=u'some site', code=u'STE')
     editor = LocationEditor(model=loc)
     editor.start()
     del editor
     assert utils.gc_objects_by_type('LocationEditor') == [], \
         'LocationEditor not deleted'
     assert utils.gc_objects_by_type('LocationEditorPresenter') == [], \
         'LocationEditorPresenter not deleted'
     assert utils.gc_objects_by_type('LocationEditorView') == [], \
         'LocationEditorView not deleted'
 def itest_editor(self):
     """
     Interactively test the PlantEditor
     """
     #loc = self.create(Family, name=u'some site')
     fam = Family(family='some family')
     editor = FamilyEditor(model=fam)
     editor.start()
     del editor
     assert utils.gc_objects_by_type('FamilyEditor') == [], \
         'FamilyEditor not deleted'
     assert utils.gc_objects_by_type('FamilyEditorPresenter') == [], \
         'FamilyEditorPresenter not deleted'
     assert utils.gc_objects_by_type('FamilyEditorView') == [], \
         'FamilyEditorView not deleted'
示例#8
0
    def start(self):
        """
        Show the connection manager.
        """
        self.create_gui()
        conn_list = prefs.prefs[bauble.conn_list_pref]
        if conn_list is None or len(conn_list.keys()) == 0:
            msg = _('You don\'t have any connections in your connection '
                    'list.\nClose this message and click on "Add" to create '
                    'a new connection.')
            utils.message_dialog(msg)
        else:
            self.set_active_connection_by_name(self.default_name)
            self._dirty = False

        self._error = True
        name = None
        uri = None
        while name is None or self._error:
            response = self.dialog.run()
            if response == gtk.RESPONSE_OK:
                name = self._get_connection_name()
                uri = self._get_connection_uri()
                if name is None:
                    msg = _('You have to choose or create a new connection '
                            'before you can connect to the database.')
                    utils.message_dialog(msg)
            else:
                name = uri = None
                break

        ## now make sure the pictures dir contains a thumbs subdir
        path = os.path.sep.join(
            (prefs.prefs[prefs.picture_root_pref], 'thumbs'))
        try:
            logger.debug("checking presence of thumbs dir")
            os.makedirs(path)
        except OSError:
            if not os.path.isdir(path):
                logger.debug("something wrong in thumbs dir")
                raise

        # have to remove the cell_data_func to avoid a cyclical
        # reference which would cause the ConnectionManager to not get
        # garbage collected
        cell = self.type_combo.get_cells()[0]
        self.type_combo.set_cell_data_func(cell, None)
        self.type_combo.clear()
        self.name_combo.clear()

        # just to be sure let's destroy the dialog upfront and delete
        # the params box
        self.dialog.destroy()
        del self.params_box
        obj = utils.gc_objects_by_type(CMParamsBox)
        if obj:
            logger.info('ConnectionManager.start(): param box leaked: %s' %
                        obj)
        return name, uri
示例#9
0
    def start(self):
        """
        Show the connection manager.
        """
        self.create_gui()
        conn_list = prefs.prefs[bauble.conn_list_pref]
        if conn_list is None or len(conn_list.keys()) == 0:
            msg = _('You don\'t have any connections in your connection '
                    'list.\nClose this message and click on "Add" to create '
                    'a new connection.')
            utils.message_dialog(msg)
        else:
            self.set_active_connection_by_name(self.default_name)
            self._dirty = False

        self._error = True
        name = None
        uri = None
        while name is None or self._error:
            response = self.dialog.run()
            if response == gtk.RESPONSE_OK:
                name = self._get_connection_name()
                uri = self._get_connection_uri()
                if name is None:
                    msg = _('You have to choose or create a new connection '
                            'before you can connect to the database.')
                    utils.message_dialog(msg)
            else:
                name = uri = None
                break

        ## now make sure the pictures dir contains a thumbs subdir
        path = os.path.sep.join(
            (prefs.prefs[prefs.picture_root_pref], 'thumbs'))
        try:
            logger.debug("checking presence of thumbs dir")
            os.makedirs(path)
        except OSError:
            if not os.path.isdir(path):
                logger.debug("something wrong in thumbs dir")
                raise

        # have to remove the cell_data_func to avoid a cyclical
        # reference which would cause the ConnectionManager to not get
        # garbage collected
        cell = self.type_combo.get_cells()[0]
        self.type_combo.set_cell_data_func(cell, None)
        self.type_combo.clear()
        self.name_combo.clear()

        # just to be sure let's destroy the dialog upfront and delete
        # the params box
        self.dialog.destroy()
        del self.params_box
        obj = utils.gc_objects_by_type(CMParamsBox)
        if obj:
            logger.info('ConnectionManager.start(): param box leaked: %s'
                        % obj)
        return name, uri
示例#10
0
 def test_editor(self):
     """
     Interactively test the PlantEditor
     """
     raise SkipTest("Not Implemented")
     # loc = self.create(Genus, name=u'some site')
     fam = Family(family=u"family")
     fam2 = Family(family=u"family2")
     fam2.synonyms.append(fam)
     self.session.add_all([fam, fam2])
     self.session.commit()
     gen = Genus(genus="some genus")
     editor = GenusEditor(model=gen)
     editor.start()
     del editor
     assert utils.gc_objects_by_type("GenusEditor") == [], "GenusEditor not deleted"
     assert utils.gc_objects_by_type("GenusEditorPresenter") == [], "GenusEditorPresenter not deleted"
     assert utils.gc_objects_by_type("GenusEditorView") == [], "GenusEditorView not deleted"
示例#11
0
 def itest_editor(self):
     """
     Interactively test the PlantEditor
     """
     #loc = self.create(Genus, name=u'some site')
     fam = Family(family=u'family')
     fam2 = Family(family=u'family2')
     fam2.synonyms.append(fam)
     self.session.add_all([fam, fam2])
     self.session.commit()
     gen = Genus(genus='some genus')
     editor = GenusEditor(model=gen)
     editor.start()
     del editor
     assert utils.gc_objects_by_type('GenusEditor') == [], \
         'GenusEditor not deleted'
     assert utils.gc_objects_by_type('GenusEditorPresenter') == [], \
         'GenusEditorPresenter not deleted'
     assert utils.gc_objects_by_type('GenusEditorView') == [], \
         'GenusEditorView not deleted'
示例#12
0
    def test_editor(self):
        raise SkipTest("Not Implemented")
        # import default geography data
        import bauble.paths as paths

        default_path = os.path.join(paths.lib_dir(), "plugins", "plants", "default")
        filenames = [os.path.join(default_path, f) for f in "geography.txt", "habit.txt"]
        from bauble.plugins.imex.csv_ import CSVImporter

        importer = CSVImporter()
        importer.start(filenames, force=True)

        f = Family(family=u"family")
        g2 = Genus(genus=u"genus2", family=f)
        g = Genus(genus=u"genus", family=f)
        g2.synonyms.append(g)
        self.session.add(f)
        self.session.commit()
        sp = Species(genus=g, sp=u"sp")
        edit_species(model=sp)
        assert utils.gc_objects_by_type("SpeciesEditorMenuItem") == [], "SpeciesEditor not deleted"
        assert utils.gc_objects_by_type("SpeciesEditorPresenter") == [], "SpeciesEditorPresenter not deleted"
        assert utils.gc_objects_by_type("SpeciesEditorView") == [], "SpeciesEditorView not deleted"
    def start(self):
        """
        Show the connection manager.
        """
        self.create_gui()
        self.dialog.connect('response', self.on_dialog_response)
        self.dialog.connect('close', self.on_dialog_close_or_delete)
        self.dialog.connect('delete-event', self.on_dialog_close_or_delete)
        conn_list = prefs[bauble.conn_list_pref]
        if conn_list is None or len(conn_list.keys()) == 0:
            msg = _('You don\'t have any connections in your connection '\
                    'list.\nClose this message and click on "Add" to create '\
                    'a new connection.')
            utils.message_dialog(msg)
        else:
            self.set_active_connection_by_name(self.default_name)
            self._dirty = False

        self._error = True
        name = None
        uri = None
        while name is None or self._error:
            response = self.dialog.run()
            if response == gtk.RESPONSE_OK:
                name = self._get_connection_name()
                uri = self._get_connection_uri()
                if name is None:
                    msg = _('You have to choose or create a new connection ' \
                            'before you can connect to the database.')
                    utils.message_dialog(msg)
            else:
                name = uri = None
                break

        # have to remove the cell_data_func to avoid a cyclical
        # reference which would cause the ConnectionManager to not get
        # garbage collected
        cell = self.type_combo.get_cells()[0]
        self.type_combo.set_cell_data_func(cell, None)
        self.type_combo.clear()
        self.name_combo.clear()

        # just to be sure let's destroy the dialog upfront and delete
        # the params box
        self.dialog.destroy()
        del self.params_box
        obj = utils.gc_objects_by_type(CMParamsBox)
        if obj:
            warning('ConnectionManager.start(): param box leaked: %s' % obj)
        return name, uri
示例#14
0
                                         traceback.format_exc(),
                                         gtk.MESSAGE_ERROR)
            logger.error('bauble.gui.on_insert_menu_item_activate():\n %s'
                         % traceback.format_exc())
            return

        presenter_cls = view_cls = None
        if hasattr(editor, 'presenter'):
            presenter_cls = type(editor.presenter)
            view_cls = type(editor.presenter.view)

        # delete the editor
        del editor

        # check for leaks
        obj = utils.gc_objects_by_type(editor_cls)
        if obj != []:
            logger.warning('%s leaked: %s' % (editor_cls.__name__, obj))

        if presenter_cls:
            obj = utils.gc_objects_by_type(presenter_cls)
            if obj != []:
                logger.warning('%s leaked: %s' % (presenter_cls.__name__, obj))
            obj = utils.gc_objects_by_type(view_cls)
            if obj != []:
                logger.warning('%s leaked: %s' % (view_cls.__name__, obj))

    def on_edit_menu_cut(self, widget, data=None):
        self.widgets.main_comboentry.child.cut_clipboard()

    def on_edit_menu_copy(self, widget, data=None):
示例#15
0
                                         traceback.format_exc(),
                                         gtk.MESSAGE_ERROR)
            logger.error('bauble.gui.on_insert_menu_item_activate():\n %s' %
                         traceback.format_exc())
            return

        presenter_cls = view_cls = None
        if hasattr(editor, 'presenter'):
            presenter_cls = type(editor.presenter)
            view_cls = type(editor.presenter.view)

        # delete the editor
        del editor

        # check for leaks
        obj = utils.gc_objects_by_type(editor_cls)
        if obj != []:
            logger.warning('%s leaked: %s' % (editor_cls.__name__, obj))

        if presenter_cls:
            obj = utils.gc_objects_by_type(presenter_cls)
            if obj != []:
                logger.warning('%s leaked: %s' % (presenter_cls.__name__, obj))
            obj = utils.gc_objects_by_type(view_cls)
            if obj != []:
                logger.warning('%s leaked: %s' % (view_cls.__name__, obj))

    def on_edit_menu_cut(self, widget, data=None):
        self.widgets.main_comboentry.child.cut_clipboard()

    def on_edit_menu_copy(self, widget, data=None):