Skip to content

BUG: Make docscrape ParseError Python 3 compatible. #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def is_empty(self):

class ParseError(Exception):
def __str__(self):
message = self.message
message = self.args[0]
if hasattr(self, 'docstring'):
message = "%s in %r" % (message, self.docstring)
return message
Expand Down
24 changes: 23 additions & 1 deletion numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

import jinja2

from numpydoc.docscrape import NumpyDocString, FunctionDoc, ClassDoc
from numpydoc.docscrape import (
NumpyDocString,
FunctionDoc,
ClassDoc,
ParseError
)
from numpydoc.docscrape_sphinx import SphinxDocString, SphinxClassDoc
from nose.tools import *

Expand Down Expand Up @@ -635,6 +640,23 @@ def test_see_also():
elif func == 'class_j':
assert desc == ['fubar', 'foobar']


def test_see_also_parse_error():
text = (
"""
z(x,theta)
See Also
--------
:func:`~foo`
""")
with assert_raises(ParseError) as err:
NumpyDocString(text)
assert_equal(
str(r":func:`~foo` is not a item name in '\n z(x,theta)\n\n See Also\n --------\n :func:`~foo`\n '"),
str(err.exception)
)

def test_see_also_print():
class Dummy(object):
"""
Expand Down