Skip to content
Browse files

TST: numpydoc: more class tests

  • Loading branch information...
1 parent fd9064f commit 1b2e585133c555d1b5f72c5598473a7568587645 @pv pv committed Feb 16, 2013
Showing with 114 additions and 2 deletions.
  1. +114 −2 doc/sphinxext/numpydoc/tests/test_docscrape.py
View
116 doc/sphinxext/numpydoc/tests/test_docscrape.py
@@ -1,6 +1,6 @@
# -*- encoding:utf-8 -*-
-import sys, os
+import sys, textwrap
from numpydoc.docscrape import NumpyDocString, FunctionDoc, ClassDoc
from numpydoc.docscrape_sphinx import SphinxDocString, SphinxClassDoc
@@ -164,11 +164,12 @@ def test_examples():
def test_index():
assert_equal(doc['index']['default'], 'random')
- print(doc['index'])
assert_equal(len(doc['index']), 2)
assert_equal(len(doc['index']['refguide']), 2)
def non_blank_line_by_line_compare(a,b):
+ a = textwrap.dedent(a)
+ b = textwrap.dedent(b)
a = [l for l in a.split('\n') if l.strip()]
b = [l for l in b.split('\n') if l.strip()]
for n,line in enumerate(a):
@@ -597,20 +598,29 @@ def spam(self, a, b):
def ham(self, c, d):
"""Cheese\n\nNo cheese."""
pass
+ @property
+ def spammity(self):
+ """Spammity index"""
+ return 0.95
for cls in (ClassDoc, SphinxClassDoc):
doc = cls(Dummy, config=dict(show_class_members=False))
assert 'Methods' not in str(doc), (cls, str(doc))
assert 'spam' not in str(doc), (cls, str(doc))
assert 'ham' not in str(doc), (cls, str(doc))
+ assert 'spammity' not in str(doc), (cls, str(doc))
+ assert 'Spammity index' not in str(doc), (cls, str(doc))
doc = cls(Dummy, config=dict(show_class_members=True))
assert 'Methods' in str(doc), (cls, str(doc))
assert 'spam' in str(doc), (cls, str(doc))
assert 'ham' in str(doc), (cls, str(doc))
+ assert 'spammity' in str(doc), (cls, str(doc))
if cls is SphinxClassDoc:
assert '.. autosummary::' in str(doc), str(doc)
+ else:
+ assert 'Spammity index' in str(doc), str(doc)
def test_duplicate_signature():
# Duplicate function signatures occur e.g. in ufuncs, when the
@@ -626,6 +636,108 @@ def test_duplicate_signature():
assert doc['Signature'].strip() == 'z(a, theta)'
+
+class_doc_txt = """
+ Foo
+
+ Parameters
+ ----------
+ f : callable ``f(t, y, *f_args)``
+ Aaa.
+ jac : callable ``jac(t, y, *jac_args)``
+ Bbb.
+
+ Attributes
+ ----------
+ t : float
+ Current time.
+ y : ndarray
+ Current variable values.
+
+ Methods
+ -------
+ a
+ b
+ c
+
+ Examples
+ --------
+ For usage examples, see `ode`.
+"""
+
+def test_class_members_doc():
+ doc = ClassDoc(None, class_doc_txt)
+ non_blank_line_by_line_compare(str(doc),
+ """
+ Foo
+
+ Parameters
+ ----------
+ f : callable ``f(t, y, *f_args)``
+ Aaa.
+ jac : callable ``jac(t, y, *jac_args)``
+ Bbb.
+
+ Examples
+ --------
+ For usage examples, see `ode`.
+
+ Attributes
+ ----------
+ t : float
+ Current time.
+ y : ndarray
+ Current variable values.
+
+ Methods
+ -------
+ a :
+
+ b :
+
+ c :
+
+ .. index::
+
+ """)
+
+def test_class_members_doc_sphinx():
+ doc = SphinxClassDoc(None, class_doc_txt)
+ non_blank_line_by_line_compare(str(doc),
+ """
+ Foo
+
+ :Parameters:
+
+ **f** : callable ``f(t, y, *f_args)``
+
+ Aaa.
+
+ **jac** : callable ``jac(t, y, *jac_args)``
+
+ Bbb.
+
+ .. rubric:: Examples
+
+ For usage examples, see `ode`.
+
+ .. rubric:: Attributes
+
+ === ==========
+ t (float) Current time.
+ y (ndarray) Current variable values.
+ === ==========
+
+ .. rubric:: Methods
+
+ === ==========
+ a
+ b
+ c
+ === ==========
+
+ """)
+
if __name__ == "__main__":
import nose
nose.run()

0 comments on commit 1b2e585

Please sign in to comment.
Something went wrong with that request. Please try again.