def test_binomial_no_match(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'Cosito inesistente' # matches nothing results = mapper_search.search(s, self.session) self.assertEqual(results, set())
def test_in_singleton(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where id in 1' results = mapper_search.search(s, self.session) self.assertEqual(results, set([self.g1]))
def test_almost_binomial(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'ixora coccinea' # matches Ixora, I.coccinea, P.coccinea results = mapper_search.search(s, self.session) self.assertEqual(results, set([self.ixora, self.ic, self.pc]))
def test_search_by_query21(self): "query with MapperSearch, joined tables, one predicate" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(epithet=u'family2') genus2 = Genus(family=family2, epithet=u'genus2') self.session.add_all([family2, genus2]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # search cls.parent.column results = mapper_search.search('genus where family.epithet=family1', self.session) self.assertEquals(len(results), 1) g0 = list(results)[0] self.assertTrue(isinstance(g0, Genus)) self.assertEquals(g0.id, self.genus.id) # search cls.children.column results = mapper_search.search('family where genera.epithet=genus1', self.session) self.assertEquals(len(results), 1) f = list(results)[0] self.assertEqual(len(results), 1) self.assertTrue(isinstance(f, Family)) self.assertEqual(f.id, self.family.id)
def test_search_by_query22like(self): "query with MapperSearch, joined tables, LIKE" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(family=u'family2') family3 = Family(family=u'afamily3') genus21 = Genus(family=family2, genus=u'genus21') genus31 = Genus(family=family3, genus=u'genus31') genus32 = Genus(family=family3, genus=u'genus32') genus33 = Genus(family=family3, genus=u'genus33') f3 = Family(family=u'fam3') g3 = Genus(family=f3, genus=u'genus31') self.session.add_all([family3, family2, genus21, genus31, genus32, genus33, f3, g3]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # test partial string matches on a query s = 'genus where family.family like family%' results = mapper_search.search(s, self.session) self.assertEquals(set(results), set([self.genus, genus21]))
def test_search_by_query22_underscore(self): """can use fields starting with an underscore""" import datetime Family = self.Family Genus = self.Genus from bauble.plugins.plants.species_model import Species from bauble.plugins.garden.accession import Accession from bauble.plugins.garden.location import Location from bauble.plugins.garden.plant import Plant family2 = Family(family=u'family2') g2 = Genus(family=family2, genus=u'genus2') f3 = Family(family=u'fam3', qualifier=u's. lat.') g3 = Genus(family=f3, genus=u'Ixora') sp = Species(sp=u"coccinea", genus=g3) ac = Accession(species=sp, code=u'1979.0001') lc = Location(name=u'loc1', code=u'loc1') pp = Plant(accession=ac, code=u'01', location=lc, quantity=1) pp._last_updated = datetime.datetime(2009, 2, 13) self.session.add_all([family2, g2, f3, g3, sp, ac, lc, pp]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'plant where _last_updated < |datetime|2000,1,1|' results = mapper_search.search(s, self.session) self.assertEqual(results, set()) s = 'plant where _last_updated > |datetime|2000,1,1|' results = mapper_search.search(s, self.session) self.assertEqual(results, set([pp]))
def test_canfindspeciesfromgenus(self): 'can find species from genus' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search('species where species.genus=genus1') print dir(results) self.assertEqual(str(results.statement), "SELECT * FROM species WHERE (species.genus = 'genus1')")
def test_search_by_query22_underscore(self): """can use fields starting with an underscore""" import datetime Family = self.Family Genus = self.Genus from bauble.plugins.plants.species_model import Species from bauble.plugins.garden.accession import Accession from bauble.plugins.garden.location import Location from bauble.plugins.garden.plant import Plant family2 = Family(epithet=u'family2') g2 = Genus(family=family2, epithet=u'genus2') f3 = Family(epithet=u'fam3', aggregate=u'agg.') g3 = Genus(family=f3, epithet=u'Ixora') sp = Species(epithet=u"coccinea", genus=g3) ac = Accession(species=sp, code=u'1979.0001') lc = Location(name=u'loc1', code=u'loc1') pp = Plant(accession=ac, code=u'01', location=lc, quantity=1) pp._last_updated = datetime.datetime(2009, 2, 13) self.session.add_all([family2, g2, f3, g3, sp, ac, lc, pp]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'plant where _last_updated < |datetime|2000,1,1|' results = mapper_search.search(s, self.session) self.assertEqual(results, set()) s = 'plant where _last_updated > |datetime|2000,1,1|' results = mapper_search.search(s, self.session) self.assertEqual(results, set([pp]))
def search(self, text, session): from genus import Genus, GenusSynonym super(SynonymSearch, self).search(text, session) if not prefs[self.return_synonyms_pref]: return mapper_search = search.get_strategy('MapperSearch') r1 = mapper_search.search(text, session) if not r1: return [] results = [] for result in r1: # iterate through the results and see if we can find some # synonyms for the returned values if isinstance(result, Species): q = session.query(SpeciesSynonym).\ filter_by(synonym_id=result.id) results.extend([syn.species for syn in q]) elif isinstance(result, Genus): q = session.query(GenusSynonym).\ filter_by(synonym_id=result.id) results.extend([syn.genus for syn in q]) elif isinstance(results, VernacularName): q = session.query(SpeciesSynonym).\ filter_by(synonym_id=result.species.id) results.extend([syn.species for syn in q]) return results
def search(self, text, session): from genus import Genus, GenusSynonym super(SynonymSearch, self).search(text, session) if not prefs[self.return_synonyms_pref]: return [] mapper_search = search.get_strategy('MapperSearch') r1 = mapper_search.search(text, session) if not r1: return [] results = [] for result in r1: # iterate through the results and for all objects considered # synonym of something else, include that something else. that # is, the accepted name. if isinstance(result, Species): q = session.query(SpeciesSynonym).\ filter_by(synonym_id=result.id) results.extend([syn.species for syn in q]) elif isinstance(result, Genus): q = session.query(GenusSynonym).\ filter_by(synonym_id=result.id) results.extend([syn.genus for syn in q]) elif isinstance(results, VernacularName): q = session.query(SpeciesSynonym).\ filter_by(synonym_id=result.species.id) results.extend([syn.species for syn in q]) return results
def test_between_evaluate(self): 'use BETWEEN value and value' Family = self.Family Genus = self.Genus from bauble.plugins.plants.species_model import Species from bauble.plugins.garden.accession import Accession #from bauble.plugins.garden.location import Location #from bauble.plugins.garden.plant import Plant family2 = Family(epithet=u'family2') g2 = Genus(family=family2, epithet=u'genus2') f3 = Family(epithet=u'fam3', aggregate=u'agg.') g3 = Genus(family=f3, epithet=u'Ixora') sp = Species(epithet=u"coccinea", genus=g3) ac = Accession(species=sp, code=u'1979.0001') self.session.add_all([family2, g2, f3, g3, sp, ac]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'accession where code between "1978" and "1980"' results = mapper_search.search(s, self.session) self.assertEqual(results, set([ac])) s = 'accession where code between "1980" and "1980"' results = mapper_search.search(s, self.session) self.assertEqual(results, set())
def test_between_evaluate(self): 'use BETWEEN value and value' Family = self.Family Genus = self.Genus from bauble.plugins.plants.species_model import Species from bauble.plugins.garden.accession import Accession #from bauble.plugins.garden.location import Location #from bauble.plugins.garden.plant import Plant family2 = Family(family=u'family2') g2 = Genus(family=family2, genus=u'genus2') f3 = Family(family=u'fam3', qualifier=u's. lat.') g3 = Genus(family=f3, genus=u'Ixora') sp = Species(sp=u"coccinea", genus=g3) ac = Accession(species=sp, code=u'1979.0001') self.session.add_all([family2, g2, f3, g3, sp, ac]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'accession where code between "1978" and "1980"' results = mapper_search.search(s, self.session) self.assertEqual(results, set([ac])) s = 'accession where code between "1980" and "1980"' results = mapper_search.search(s, self.session) self.assertEqual(results, set())
def test_binomial_incomplete(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'Ix cocc' # matches Ixora coccinea results = mapper_search.search(s, self.session) self.assertEqual(results, set([self.ic]))
def test_in_list_no_result(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where id in 5,6' results = mapper_search.search(s, self.session) self.assertEqual(results, set())
def test_in_composite_expression_excluding(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where id in 1,2,4 and id<3' results = mapper_search.search(s, self.session) self.assertEqual(results, set([self.g1, self.g2]))
def test_search_by_query13(self): "query with MapperSearch, single table, p1 AND p2" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(family=u'family2') genus2 = Genus(family=family2, genus=u'genus2') f3 = Family(family=u'fam3') g3 = Genus(family=f3, genus=u'genus2') g4 = Genus(family=f3, genus=u'genus4') self.session.add_all([family2, genus2, f3, g3, g4]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where id>1 AND id<3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 1) result = results.pop() self.assertEqual(result.id, 2) s = 'genus where id>0 AND id<3' results = list(mapper_search.search(s, self.session)) self.assertEqual(len(results), 2) self.assertEqual(set(i.id for i in results), set([1, 2]))
def test_search_by_query21(self): "query with MapperSearch, joined tables, one predicate" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(family=u'family2') genus2 = Genus(family=family2, genus=u'genus2') self.session.add_all([family2, genus2]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # search cls.parent.column results = mapper_search.search('genus where family.family=family1', self.session) self.assertEquals(len(results), 1) g0 = list(results)[0] self.assertTrue(isinstance(g0, Genus)) self.assertEquals(g0.id, self.genus.id) # search cls.children.column results = mapper_search.search('family where genera.genus=genus1', self.session) self.assertEquals(len(results), 1) f = list(results)[0] self.assertEqual(len(results), 1) self.assertTrue(isinstance(f, Family)) self.assertEqual(f.id, self.family.id)
def test_search_by_query22Symbolic(self): "query with &&, ||, !" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(family=u'family2') g2 = Genus(family=family2, genus=u'genus2') f3 = Family(family=u'fam3', qualifier=u's. lat.') g3 = Genus(family=f3, genus=u'genus3') self.session.add_all([family2, g2, f3, g3]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where genus=genus2 && family.family=fam3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 0) s = 'family where family=family1 || family=fam3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 2) s = 'family where ! family=family1' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 2)
def test_search_by_expression_genus_eq_nomatch(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # search for genus by domain results = mapper_search.search('genus=g', self.session) self.assertEquals(len(results), 0)
def test_search_by_expression_genus_like_contains_eq(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) Family = self.Family f2 = Family(family=u'family2') f3 = Family(family=u'afamily3') f4 = Family(family=u'fam4') self.session.add_all([f3, f2, f4]) self.session.commit() # search for family by domain results = mapper_search.search('family contains fam', self.session) self.assertEquals(len(results), 4) # all do results = mapper_search.search('family like f%', self.session) self.assertEquals(len(results), 3) # three start by f results = mapper_search.search('family like af%', self.session) self.assertEquals(len(results), 1) # one starts by af results = mapper_search.search('family like fam', self.session) self.assertEquals(len(results), 0) results = mapper_search.search('family = fam', self.session) self.assertEquals(len(results), 0) results = mapper_search.search('family = fam4', self.session) self.assertEquals(len(results), 1) # exact name match results = mapper_search.search('family = Fam4', self.session) self.assertEquals(len(results), 0) # = is case sensitive results = mapper_search.search('family like Fam4', self.session) self.assertEquals(len(results), 1) # like is case insensitive results = mapper_search.search('family contains FAM', self.session) self.assertEquals(len(results), 4) # they case insensitively do
def test_search_by_query22like(self): "query with MapperSearch, joined tables, LIKE" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(epithet=u'family2') family3 = Family(epithet=u'afamily3') genus21 = Genus(family=family2, epithet=u'genus21') genus31 = Genus(family=family3, epithet=u'genus31') genus32 = Genus(family=family3, epithet=u'genus32') genus33 = Genus(family=family3, epithet=u'genus33') f3 = Family(epithet=u'fam3') g3 = Genus(family=f3, epithet=u'genus31') self.session.add_all( [family3, family2, genus21, genus31, genus32, genus33, f3, g3]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # test partial string matches on a query s = 'genus where family.epithet like family%' results = mapper_search.search(s, self.session) self.assertEquals(set(results), set([self.genus, genus21]))
def test_search_by_query22Symbolic(self): "query with &&, ||, !" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(epithet=u'family2') g2 = Genus(family=family2, epithet=u'genus2') f3 = Family(epithet=u'fam3', aggregate=u'agg.') g3 = Genus(family=f3, epithet=u'genus3') self.session.add_all([family2, g2, f3, g3]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where epithet=genus2 && family.epithet=fam3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 0) s = 'family where epithet=family1 || epithet=fam3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 2) s = 'family where ! epithet=family1' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 2)
def test_search_by_query13(self): "query with MapperSearch, single table, p1 AND p2" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(epithet=u'family2') genus2 = Genus(family=family2, epithet=u'genus2') f3 = Family(epithet=u'fam3') g3 = Genus(family=f3, epithet=u'genus2') g4 = Genus(family=f3, epithet=u'genus4') self.session.add_all([family2, genus2, f3, g3, g4]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where id>1 AND id<3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 1) result = results.pop() self.assertEqual(result.id, 2) s = 'genus where id>0 AND id<3' results = list(mapper_search.search(s, self.session)) self.assertEqual(len(results), 2) self.assertEqual(set(i.id for i in results), set([1, 2]))
def test_search_by_expression_genus_like_contains_eq(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) Family = self.Family f2 = Family(epithet=u'family2') f3 = Family(epithet=u'afamily3') f4 = Family(epithet=u'fam4') self.session.add_all([f3, f2, f4]) self.session.commit() # search for family by domain results = mapper_search.search('family contains fam', self.session) self.assertEquals(len(results), 4) # all do results = mapper_search.search('family like f%', self.session) self.assertEquals(len(results), 3) # three start by f results = mapper_search.search('family like af%', self.session) self.assertEquals(len(results), 1) # one starts by af results = mapper_search.search('family like fam', self.session) self.assertEquals(len(results), 0) results = mapper_search.search('family = fam', self.session) self.assertEquals(len(results), 0) results = mapper_search.search('family = fam4', self.session) self.assertEquals(len(results), 1) # exact name match results = mapper_search.search('family = Fam4', self.session) self.assertEquals(len(results), 0) # = is case sensitive results = mapper_search.search('family like Fam4', self.session) self.assertEquals(len(results), 1) # like is case insensitive results = mapper_search.search('family contains FAM', self.session) self.assertEquals(len(results), 4) # they case insensitively do
def init(cls): from bauble.view import SearchView mapper_search = search.get_strategy('MapperSearch') mapper_search.add_meta(('tag', 'tags'), Tag, ['tag']) SearchView.view_meta[Tag].set(children=natsort_kids('objects'), context_menu=tag_context_menu) if bauble.gui is not None: _reset_tags_menu()
def test_canfindfamilyfromgenus(self): 'can find family from genus' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search('family where family.genus=genus1') self.assertEqual( str(results.statement), "SELECT * FROM family WHERE (family.genus = 'genus1')")
def test_canfindplantbyaccession(self): 'can find plant from the accession id' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search('plant where accession.species.id=113') self.assertEqual( str(results.statement), 'SELECT * FROM plant WHERE (accession.species.id = 113)')
def test_canfindspeciesfromgenus(self): 'can find species from genus' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search('species where species.genus=genus1') print dir(results) self.assertEqual( str(results.statement), "SELECT * FROM species WHERE (species.genus = 'genus1')")
def test_search_by_expression_genus_eq_1match(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # search for genus by domain results = mapper_search.search('gen=genus1', self.session) self.assertEquals(len(results), 1) g = list(results)[0] self.assertTrue(isinstance(g, self.Genus)) self.assertEqual(g.id, self.genus.id)
def test_search_by_expression_family_eq(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # search for family by domain results = mapper_search.search('fam=family1', self.session) self.assertEquals(len(results), 1) f = list(results)[0] self.assertTrue(isinstance(f, self.Family)) self.assertEquals(f.id, self.family.id)
def test_canfindgenusfromfamily(self): 'can find genus from family' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search('genus where genus.family=family2') print dir(plants) print 1, results, type(results) print 2, results.statement print 3, results.statement.query.filter.express(self.session) self.assertEqual(str(results.statement), "SELECT * FROM genus WHERE (genus.family = 'family2')")
def test_canuselogicaloperators(self): 'can use logical operators' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search( 'species where species.genus=genus1 or species.sp=name and species.genus.family.family=name' ) self.assertEqual( str(results.statement), "SELECT * FROM species WHERE ((species.genus = 'genus1') OR ((species.sp = 'name') AND (species.genus.family.family = 'name')))" )
def test_canfindgenusfromfamily(self): 'can find genus from family' mapper_search = search.get_strategy('MapperSearch') results = mapper_search.search('genus where genus.family=family2') print dir(plants) print 1, results, type(results) print 2, results.statement print 3, results.statement.query.filter.express(self.session) self.assertEqual( str(results.statement), "SELECT * FROM genus WHERE (genus.family = 'family2')")
def test_search_by_query22(self): "query with MapperSearch, joined tables, multiple predicates" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(family=u"family2") g2 = Genus(family=family2, genus=u"genus2") f3 = Family(family=u"fam3", qualifier=u"s. lat.") g3 = Genus(family=f3, genus=u"genus3") self.session.add_all([family2, g2, f3, g3]) self.session.commit() mapper_search = search.get_strategy("MapperSearch") self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = "genus where genus=genus2 AND family.family=fam3" results = mapper_search.search(s, self.session) self.assertEqual(len(results), 0) s = "genus where genus=genus3 AND family.family=fam3" results = mapper_search.search(s, self.session) self.assertEqual(len(results), 1) g0 = list(results)[0] self.assertTrue(isinstance(g0, Genus)) self.assertEqual(g0.id, g3.id) s = 'genus where family.family="Orchidaceae" AND family.qualifier=""' results = mapper_search.search(s, self.session) r = list(results) self.assertEqual(r, []) s = 'genus where family.family=fam3 AND family.qualifier=""' results = mapper_search.search(s, self.session) self.assertEqual(results, set([])) # sqlite3 stores None as the empty string. s = 'genus where family.qualifier=""' results = mapper_search.search(s, self.session) self.assertEqual(results, set([g2])) # test where the column is ambiguous so make sure we choose # the right one, in this case we want to make sure we get the # qualifier on the family and not the genus s = ( 'plant where accession.species.genus.family.family="Orchidaceae" ' 'AND accession.species.genus.family.qualifier=""' ) results = mapper_search.search(s, self.session) self.assertEqual(results, set([]))
def test_cultivar_also_matched(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) from bauble.plugins.plants.species import Species from bauble.plugins.plants.genus import Genus g3 = self.session.query(Genus).filter(Genus.epithet == u'Ixora').one() sp5 = Species(epithet=u"coccinea", genus=g3, infrasp1_rank=u'cv.', infrasp1=u'Nora Grant') self.session.add_all([sp5]) self.session.commit() s = 'Ixora coccinea' # matches I.coccinea and Nora Grant results = mapper_search.search(s, self.session) self.assertEqual(results, set([self.ic, sp5]))
def init(cls): if 'GardenPlugin' in pluginmgr.plugins: species_context_menu.insert(1, add_accession_action) vernname_context_menu.insert(1, add_accession_action) mapper_search = search.get_strategy('MapperSearch') mapper_search.add_meta(('family', 'fam'), Family, ['family']) SearchView.row_meta[Family].set(children="genera", infobox=FamilyInfoBox, context_menu=family_context_menu) mapper_search.add_meta(('genus', 'gen'), Genus, ['genus']) SearchView.row_meta[Genus].set(children="species", infobox=GenusInfoBox, context_menu=genus_context_menu) from functools import partial search.add_strategy(SynonymSearch) mapper_search.add_meta(('species', 'sp'), Species, ['sp', 'sp2', 'infrasp1', 'infrasp2', 'infrasp3', 'infrasp4']) SearchView.row_meta[Species].set( children=partial(db.natsort, 'accessions'), infobox=SpeciesInfoBox, context_menu=species_context_menu) mapper_search.add_meta(('vernacular', 'vern', 'common'), VernacularName, ['name']) SearchView.row_meta[VernacularName].set( children=partial(db.natsort, 'species.accessions'), infobox=VernacularNameInfoBox, context_menu=vernname_context_menu) mapper_search.add_meta(('geography', 'geo'), Geography, ['name']) SearchView.row_meta[Geography].set(children=get_species_in_geography) ## now it's the turn of the DefaultView logger.debug('PlantsPlugin::init, registering splash info box') DefaultView.infoboxclass = SplashInfoBox if bauble.gui is not None: bauble.gui.add_to_insert_menu(FamilyEditor, _('Family')) bauble.gui.add_to_insert_menu(GenusEditor, _('Genus')) bauble.gui.add_to_insert_menu(SpeciesEditorMenuItem, _('Species')) if sys.platform == 'win32': # TODO: for some reason using the cross as the hybrid # character doesn't work on windows Species.hybrid_char = 'x'
def init(cls): if 'GardenPlugin' in pluginmgr.plugins: species_context_menu.insert(1, add_accession_action) vernname_context_menu.insert(1, add_accession_action) mapper_search = search.get_strategy('MapperSearch') mapper_search.add_meta(('family', 'fam'), Family, ['family']) SearchView.row_meta[Family].set(children="genera", infobox=FamilyInfoBox, context_menu=family_context_menu) mapper_search.add_meta(('genus', 'gen'), Genus, ['genus']) SearchView.row_meta[Genus].set(children="species", infobox=GenusInfoBox, context_menu=genus_context_menu) from functools import partial search.add_strategy(SynonymSearch) mapper_search.add_meta( ('species', 'sp'), Species, ['sp', 'sp2', 'infrasp1', 'infrasp2', 'infrasp3', 'infrasp4']) SearchView.row_meta[Species].set(children=partial( db.natsort, 'accessions'), infobox=SpeciesInfoBox, context_menu=species_context_menu) mapper_search.add_meta(('vernacular', 'vern', 'common'), VernacularName, ['name']) SearchView.row_meta[VernacularName].set( children=partial(db.natsort, 'species.accessions'), infobox=VernacularNameInfoBox, context_menu=vernname_context_menu) mapper_search.add_meta(('geography', 'geo'), Geography, ['name']) SearchView.row_meta[Geography].set(children=get_species_in_geography) ## now it's the turn of the DefaultView logger.debug('PlantsPlugin::init, registering splash info box') DefaultView.infoboxclass = SplashInfoBox if bauble.gui is not None: bauble.gui.add_to_insert_menu(FamilyEditor, _('Family')) bauble.gui.add_to_insert_menu(GenusEditor, _('Genus')) bauble.gui.add_to_insert_menu(SpeciesEditorMenuItem, _('Species')) if sys.platform == 'win32': # TODO: for some reason using the cross as the hybrid # character doesn't work on windows Species.hybrid_char = 'x'
def test_search_by_query22(self): "query with MapperSearch, joined tables, multiple predicates" # test does not depend on plugin functionality Family = self.Family Genus = self.Genus family2 = Family(epithet=u'family2') g2 = Genus(family=family2, epithet=u'genus2') f3 = Family(epithet=u'fam3', aggregate=u'agg.') g3 = Genus(family=f3, epithet=u'genus3') self.session.add_all([family2, g2, f3, g3]) self.session.commit() mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where epithet=genus2 AND family.epithet=fam3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 0) s = 'genus where epithet=genus3 AND family.epithet=fam3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 1) g0 = list(results)[0] self.assertTrue(isinstance(g0, Genus)) self.assertEqual(g0.id, g3.id) s = 'genus where family.epithet="Orchidaceae" AND family.aggregate=""' results = mapper_search.search(s, self.session) r = list(results) self.assertEqual(r, []) s = 'genus where family.epithet=fam3 AND family.aggregate=""' results = mapper_search.search(s, self.session) self.assertEqual(results, set([])) # sqlite3 stores None as the empty string. s = 'genus where family.aggregate=""' results = mapper_search.search(s, self.session) self.assertEqual(results, set([g2])) # test where the column is ambiguous so make sure we choose # the right one, in this case we want to make sure we get the # aggregate on the family and not the genus s = 'plant where accession.species.genus.family.epithet="Orchidaceae" '\ 'AND accession.species.genus.family.aggregate=""' results = mapper_search.search(s, self.session) self.assertEqual(results, set([]))
def init(cls): if 'GardenPlugin' in pluginmgr.plugins: species_context_menu.insert(1, add_accession_action) vernname_context_menu.insert(1, add_accession_action) mapper_search = search.get_strategy('MapperSearch') mapper_search.add_meta(('family', 'fam'), Family, ['family']) SearchView.view_meta[Family].set(children="genera", infobox=FamilyInfoBox, context_menu=family_context_menu, markup_func=family_markup_func) mapper_search.add_meta(('genus', 'gen'), Genus, ['genus']) SearchView.view_meta[Genus].set(children="species", infobox=GenusInfoBox, context_menu=genus_context_menu, markup_func=genus_markup_func) search.add_strategy(SynonymSearch) mapper_search.add_meta( ('species', 'sp'), Species, ['sp', 'sp2', 'infrasp1', 'infrasp2', 'infrasp3', 'infrasp4']) SearchView.view_meta[Species].set(children=species_get_kids, infobox=SpeciesInfoBox, context_menu=species_context_menu, markup_func=species_markup_func) mapper_search.add_meta(('vernacular', 'vern', 'common'), VernacularName, ['name']) SearchView.view_meta[VernacularName].set( children=vernname_get_kids, infobox=VernacularNameInfoBox, context_menu=vernname_context_menu, markup_func=vernname_markup_func) mapper_search.add_meta(('geography', 'geo'), Geography, ['name']) SearchView.view_meta[Geography].set(children=get_species_in_geography) if bauble.gui is not None: bauble.gui.add_to_insert_menu(FamilyEditor, _('Family')) bauble.gui.add_to_insert_menu(GenusEditor, _('Genus')) bauble.gui.add_to_insert_menu(SpeciesEditorMenuItem, _('Species')) if sys.platform == 'win32': # TODO: for some reason using the cross as the hybrid # character doesn't work on windows Species.hybrid_char = 'x'
def init(cls): if 'GardenPlugin' in pluginmgr.plugins: species_context_menu.insert(1, add_accession_action) vernname_context_menu.insert(1, add_accession_action) mapper_search = search.get_strategy('MapperSearch') mapper_search.add_meta(('family', 'fam'), Family, ['family']) SearchView.view_meta[Family].set(children="genera", infobox=FamilyInfoBox, context_menu=family_context_menu, markup_func=family_markup_func) mapper_search.add_meta(('genus', 'gen'), Genus, ['genus']) SearchView.view_meta[Genus].set(children="species", infobox=GenusInfoBox, context_menu=genus_context_menu, markup_func=genus_markup_func) search.add_strategy(SynonymSearch) mapper_search.add_meta(('species', 'sp'), Species, ['sp', 'sp2', 'infrasp1', 'infrasp2', 'infrasp3', 'infrasp4']) SearchView.view_meta[Species].set(children=species_get_kids, infobox=SpeciesInfoBox, context_menu=species_context_menu, markup_func=species_markup_func) mapper_search.add_meta(('vernacular', 'vern', 'common'), VernacularName, ['name']) SearchView.view_meta[VernacularName].set( children=vernname_get_kids, infobox=VernacularNameInfoBox, context_menu=vernname_context_menu, markup_func=vernname_markup_func) mapper_search.add_meta(('geography', 'geo'), Geography, ['name']) SearchView.view_meta[Geography].set(children=get_species_in_geography) if bauble.gui is not None: bauble.gui.add_to_insert_menu(FamilyEditor, _('Family')) bauble.gui.add_to_insert_menu(GenusEditor, _('Genus')) bauble.gui.add_to_insert_menu(SpeciesEditorMenuItem, _('Species')) if sys.platform == 'win32': # TODO: for some reason using the cross as the hybrid # character doesn't work on windows Species.hybrid_char = 'x'
def test_search_by_values(self): "search by values" mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) # search for family by family name results = mapper_search.search('family1', self.session) self.assertEquals(len(results), 1) f = list(results)[0] self.assertEqual(f.id, self.family.id) # search for genus by genus name results = mapper_search.search('genus1', self.session) self.assertEquals(len(results), 1) g = list(results)[0] self.assertEqual(g.id, self.genus.id)
def init(cls): from bauble.view import SearchView from functools import partial mapper_search = search.get_strategy('MapperSearch') mapper_search.add_meta(('tag', 'tags'), Tag, ['tag']) SearchView.row_meta[Tag].set(children=partial(db.natsort, 'objects'), context_menu=tag_context_menu) SearchView.bottom_info[Tag] = { 'page_widget': 'taginfo_scrolledwindow', 'fields_used': ['tag', 'description'], 'glade_name': os.path.join(paths.lib_dir(), 'plugins/tag/tag.glade'), 'name': _('Tags'), } if bauble.gui is not None: _reset_tags_menu() else: pass
def test_search_by_query_synonyms(self): """SynonymSearch strategy gives all synonyms of given taxon.""" Family = self.Family Genus = self.Genus family2 = Family(family=u'family2') g2 = Genus(family=family2, genus=u'genus2') f3 = Family(family=u'fam3', qualifier=u's. lat.') g3 = Genus(family=f3, genus=u'Ixora') g4 = Genus(family=f3, genus=u'Schetti') self.session.add_all([family2, g2, f3, g3, g4]) g4.accepted = g3 self.session.commit() mapper_search = search.get_strategy('SynonymSearch') s = 'Schetti' results = mapper_search.search(s, self.session) self.assertEqual(results, [g3])
def test_search_by_query_synonyms_disabled(self): """SynonymSearch strategy gives all synonyms of given taxon.""" Family = self.Family Genus = self.Genus family2 = Family(epithet=u'family2') g2 = Genus(family=family2, epithet=u'genus2') f3 = Family(epithet=u'fam3', aggregate=u'agg.') g3 = Genus(family=f3, epithet=u'Ixora') g4 = Genus(family=f3, epithet=u'Schetti') self.session.add_all([family2, g2, f3, g3, g4]) g4.accepted = g3 self.session.commit() prefs.prefs['bauble.search.return_synonyms'] = False mapper_search = search.get_strategy('SynonymSearch') s = 'Schetti' results = mapper_search.search(s, self.session) self.assertEqual(results, [])
def test_count(self): mapper_search = search.get_strategy('MapperSearch') self.assertTrue(isinstance(mapper_search, search.MapperSearch)) s = 'genus where count(species.id) > 3' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 0) s = 'genus where count(species.id) > 2' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 1) result = results.pop() self.assertEqual(result.id, 1) s = 'genus where count(species.id) == 2' results = mapper_search.search(s, self.session) self.assertEqual(len(results), 1) result = results.pop() self.assertEqual(result.id, 2)