Skip to content

Commit

Permalink
Fix. Improved test coverage
Browse files Browse the repository at this point in the history
Improved test coverage from 83% to 100% for taxa module with this commit.
  • Loading branch information
ayushanand18 committed Mar 30, 2022
1 parent 8fdec10 commit 6ec0a59
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@

# Local test files
test.py
.replit
*.replit
tests.sh
3 changes: 1 addition & 2 deletions .replit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
run="python test.py"
lanuage='python'
run="bash tests.sh"
File renamed without changes.
49 changes: 39 additions & 10 deletions pyobis/occurrences/occurrences.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
from ..obisutils import *
def search(scientificname=None, aphiaid=None, obisid=None, resourceid=None,
startdate=None, enddate=None, startdepth=None, enddepth=None,
geometry=None, year=None, qc=None, fields=None, limit=500, offset=0,
mof=False, hasextensions=None, **kwargs):


def search(scientificname=None,
aphiaid=None,
obisid=None,
resourceid=None,
startdate=None,
enddate=None,
startdepth=None,
enddepth=None,
geometry=None,
year=None,
qc=None,
fields=None,
limit=500,
offset=0,
mof=False,
hasextensions=None,
**kwargs):
'''
Search OBIS occurrences
Expand Down Expand Up @@ -54,14 +69,28 @@ def search(scientificname=None, aphiaid=None, obisid=None, resourceid=None,
'''
url = obis_baseurl + 'occurrence'
scientificname = handle_arrstr(scientificname)
out = obis_GET(url, {'aphiaid': aphiaid, 'obisid': obisid,
'resourceid': resourceid, 'scientificname': scientificname,
'startdate': startdate, 'enddate': enddate, 'startdepth': startdepth,
'enddepth': enddepth, 'geometry': geometry, 'year': year,
'fields': fields, 'qc': qc, 'limit': limit, 'offset': offset, 'mof':mof,'hasextensions':hasextensions},
'application/json; charset=utf-8', **kwargs)
out = obis_GET(
url, {
'aphiaid': aphiaid,
'obisid': obisid,
'resourceid': resourceid,
'scientificname': scientificname,
'startdate': startdate,
'enddate': enddate,
'startdepth': startdepth,
'enddepth': enddepth,
'geometry': geometry,
'year': year,
'fields': fields,
'qc': qc,
'limit': limit,
'offset': offset,
'mof': mof,
'hasextensions': hasextensions
}, 'application/json; charset=utf-8', **kwargs)
return out


def get(id, **kwargs):
'''
Get an OBIS occurrence
Expand Down
2 changes: 1 addition & 1 deletion pyobis/taxa/taxa.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def taxon_search(scientificname=None, aphiaid=None, obisid=None, **kwargs):
taxa.taxon_search(aphiaid = 127405)
taxa.taxon_search(obisid = 472375)
'''
url = obis_baseurl + 'taxon'
url = obis_baseurl + 'taxon/' + handle_arrstr(scientificname)
out = obis_GET(url, {'aphiaid': aphiaid, 'obisid': obisid,
'scientificname': scientificname}, 'application/json; charset=utf-8', **kwargs)
return out
Expand Down
6 changes: 2 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# import requests
# import pandas as pd
from pyobis import occurrences

print(occurrences.search(scientificname=["Abra","Mola"]))

from pyobis import taxa

print(taxa.taxon_search(scientificname = 'Mola'))
def getExtensions(data):
lis=[]
a = pd.json_normalize(data, "mof", ["scientificName", "eventDate","id"])
Expand Down
8 changes: 4 additions & 4 deletions tests/test_taxa.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def test_taxa_search():
"taxa.search - basic test"
res = taxa.search(scientificname = 'Mola mola')
assert 'dict' == res.__class__.__name__
assert 5 == len(res)
assert list == list(res.keys()).__class__
assert 5 == len(res)

def test_taxa_taxon():
"taxa.taxon - basic test"
Expand All @@ -17,12 +17,12 @@ def test_taxa_taxon():
assert list == list(res.keys()).__class__
assert 545439 == res['valid_id']

def test_taxa_taxon():
def test_taxa_taxon_search():
"taxa.taxon_search - basic test"
res = taxa.taxon_search(scientificname = 'Mola')
assert dict == res.__class__
assert 5 == len(res)
assert list == list(res.keys()).__class__
assert 5 == len(res)
assert 'Mola' == res['results'][0]['genus']

def test_taxa_common():
Expand All @@ -35,4 +35,4 @@ def test_taxa_common():
assert dict == res['results'][0].__class__
xx = list(res['results'][0].keys())
xx.sort()
assert ['language', 'name'] == xx
assert ['language', 'name'] == xx

0 comments on commit 6ec0a59

Please sign in to comment.