diff options
author | Pauli Virtanen <pav@iki.fi> | 2013-02-16 16:28:58 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2013-02-16 17:48:32 +0200 |
commit | 1b2e585133c555d1b5f72c5598473a7568587645 (patch) | |
tree | 1000bdd2e91c5b5e4109a128c61cd42c44cfa065 | |
parent | fd9064f5ee734ffb1dd1f16e7b0f6ce9cfa25df5 (diff) | |
download | numpy-1b2e585133c555d1b5f72c5598473a7568587645.tar.gz |
TST: numpydoc: more class tests
-rw-r--r-- | doc/sphinxext/numpydoc/tests/test_docscrape.py | 116 |
1 files changed, 114 insertions, 2 deletions
diff --git a/doc/sphinxext/numpydoc/tests/test_docscrape.py b/doc/sphinxext/numpydoc/tests/test_docscrape.py index 7514419ca..aed57fb26 100644 --- a/doc/sphinxext/numpydoc/tests/test_docscrape.py +++ b/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 test_class_members(): 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() |