Skip to content

Commit

Permalink
Return '' instead of None
Browse files Browse the repository at this point in the history
  • Loading branch information
gdower committed Mar 28, 2024
1 parent e5db257 commit a713b04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions pygnparser/utils/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def _key(self, key, dict=None):
if dict is None:
dict = self.parsed_result
try:
key = dict[key]
value = dict[key]
except KeyError:
key = None
return key
value = ''
return value


def parsed(self):
Expand Down Expand Up @@ -56,7 +56,7 @@ def page(self):
if ':' in verbatim_authorship:
page = verbatim_authorship.split(':')[-1].strip()
else:
page = None
page = ''
return page


Expand All @@ -82,7 +82,7 @@ def _format_authorship(self, authorship_details):

def authorship(self):
authorship_details = self.authorship_details()
authorship = None
authorship = ''
if authorship_details is not None:
if 'originalAuth' in authorship_details:
authorship = self._format_authorship(authorship_details['originalAuth'])
Expand Down Expand Up @@ -166,15 +166,15 @@ def infraspecies_details(self):

def infraspecies(self):
infraspecies_details = self.infraspecies_details()
if infraspecies_details is not None:
if infraspecies_details != '':
return self._key('value', dict=infraspecies_details[0])
else:
return None
return ''


def infraspecies_rank(self):
if self._details_rank() == 'infraspecies':
rank = None
rank = ''
if self._key('rank', dict=self.details()[self._details_rank()]['infraspecies'][0]) is not None:
rank = self._key('rank', dict=self.details()[self._details_rank()]['infraspecies'][0])
return rank
Expand Down
12 changes: 6 additions & 6 deletions test/test-parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_parse_infraspecies():
@vcr.use_cassette("test/vcr_cassettes/test_parse_Aus_cus_dus.yaml")
def test_parse_infraspecies_rank():
res = gnparser('Aus (Bus) cus dus (Smith, 1980)')
assert res.infraspecies_rank() is None
assert res.infraspecies_rank() == ''


@vcr.use_cassette("test/vcr_cassettes/test_parse_Aus_cus_var_dus.yaml")
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_parse_Ablepharus_pannonicus():
res = gnparser('Ablepharus pannonicus Fitzinger in Eversmann, 1823: 145 (Nom. Nud., In Error)')
assert res.genus() == 'Ablepharus'
assert res.species() == 'pannonicus'
assert res.infraspecies() is None
assert res.infraspecies() == ''
assert res.authorship() == 'Fitzinger in Eversmann, 1823'
assert res.page() == '145'
assert res.quality_warnings() == [{'quality': 4, 'warning': 'Unparsed tail'}, {'quality': 2, 'warning': 'Ex authors are not required (ICZN only)'}, {'quality': 2, 'warning': 'Year with page info'}]
Expand All @@ -271,9 +271,9 @@ def test_parse_Aspidoscelis_neavesi():
res = gnparser('Aspidoscelis neavesi Cole, Taylor, Baumann & Baumann, 2014 (Part)')
assert res.genus() == 'Aspidoscelis'
assert res.species() == 'neavesi'
assert res.infraspecies() is None
assert res.infraspecies() == ''
assert res.authorship() == 'Cole, Taylor, Baumann & Baumann, 2014'
assert res.page() is None
assert res.page() == ''
assert res.tail().strip() == '(Part)'


Expand All @@ -282,7 +282,7 @@ def test_parse_Atuechosaurus_travancoricus():
res = gnparser('Atuechosaurus travancoricus Beddome, 1870: 33 (Part.)')
assert res.genus() == 'Atuechosaurus'
assert res.species() == 'travancoricus'
assert res.infraspecies() is None
assert res.infraspecies() == ''
assert res.authorship() == 'Beddome, 1870'
assert res.page() == '33'
assert res.tail().strip() == '(Part.)'
Expand All @@ -293,7 +293,7 @@ def test_parse_Calyptoprymnus_verecundus():
res = gnparser('Calyptoprymnus verecundus De Vis, 1905: 46 (Fide Moody, 1977)')
assert res.genus() == 'Calyptoprymnus'
assert res.species() == 'verecundus'
assert res.infraspecies() is None
assert res.infraspecies() == ''
assert res.authorship() == 'De Vis, 1905'
assert res.page() == '46'
assert res.tail().strip() == '(Fide Moody, 1977)'
Expand Down

0 comments on commit a713b04

Please sign in to comment.