Skip to content

Commit

Permalink
0.3.8 (#13)
Browse files Browse the repository at this point in the history
* fix empty disambiguation list items
  • Loading branch information
barrust committed Jan 3, 2017
1 parent 0577003 commit f1e53b6
Show file tree
Hide file tree
Showing 5 changed files with 832 additions and 773 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Current

### Version 0.3.8

* Fix empty disambiguation list items


### Version 0.3.7

* Memoize support default parameters
Expand Down
25 changes: 9 additions & 16 deletions mediawiki/mediawiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .utilities import memoize

URL = 'https://github.com/barrust/mediawiki'
VERSION = '0.3.7'
VERSION = '0.3.8'


class MediaWiki(object):
Expand Down Expand Up @@ -554,16 +554,6 @@ def categorymembers(self, category, results=10, subcategories=True):
return pages
# end categorymembers

# def categorytree(self, category, depth=5):
# ''' Generate the Category Tree data
#
# :raises `NotImplementedError`: not implemented
#
# .. todo:: implement
# '''
# raise NotImplementedError
# end categorytree

def page(self, title=None, pageid=None, auto_suggest=True, redirect=True,
preload=False):
''' Get MediaWiki page based on the provided title or pageid
Expand Down Expand Up @@ -1141,12 +1131,15 @@ def _raise_disambiguation_error(self, page, pageid):
for li in filtered_lis if li.a]
disambiguation = list()
for lis_item in filtered_lis:
item = lis_item.find_all('a')[0]
item = lis_item.find_all('a')
one_disambiguation = dict()
one_disambiguation['description'] = lis_item.text
if item:
one_disambiguation = dict()
one_disambiguation['title'] = item['title']
one_disambiguation['description'] = lis_item.text
disambiguation.append(one_disambiguation)
one_disambiguation['title'] = item[0]['title']
else:
# these are non-linked records so double up the text
one_disambiguation['title'] = lis_item.text
disambiguation.append(one_disambiguation)
raise DisambiguationError(getattr(self, 'title', page['title']),
may_refer_to,
disambiguation)
Expand Down
11 changes: 11 additions & 0 deletions tests/mediawiki_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,17 @@ def test_disambiguation_error_msg(self):
except DisambiguationError as ex:
self.assertEqual(ex.message, response['disambiguation_error_msg'])

def test_disamb_error_msg_w_empty(self):
''' Test that disambiguation error is thrown correctly and no
IndexError is thrown '''
site = MediaWikiOverloaded()
response = site.responses[site.api_url]
try:
site.page('Oasis')
except DisambiguationError as ex:
self.assertEqual(ex.message,
response['disambiguation_error_msg_with_empty'])

def test_geocoord_error(self):
''' test geocoord error thrown '''
site = MediaWikiOverloaded()
Expand Down

0 comments on commit f1e53b6

Please sign in to comment.