Skip to content
This repository
Browse code

TST: numpydoc: more class tests

  • Loading branch information...
commit 1b2e585133c555d1b5f72c5598473a7568587645 1 parent fd9064f
Pauli Virtanen pv authored

Showing 1 changed file with 114 additions and 2 deletions. Show diff stats Hide diff stats

  1. +114 2 doc/sphinxext/numpydoc/tests/test_docscrape.py
116 doc/sphinxext/numpydoc/tests/test_docscrape.py
... ... @@ -1,6 +1,6 @@
1 1 # -*- encoding:utf-8 -*-
2 2
3   -import sys, os
  3 +import sys, textwrap
4 4
5 5 from numpydoc.docscrape import NumpyDocString, FunctionDoc, ClassDoc
6 6 from numpydoc.docscrape_sphinx import SphinxDocString, SphinxClassDoc
@@ -164,11 +164,12 @@ def test_examples():
164 164
165 165 def test_index():
166 166 assert_equal(doc['index']['default'], 'random')
167   - print(doc['index'])
168 167 assert_equal(len(doc['index']), 2)
169 168 assert_equal(len(doc['index']['refguide']), 2)
170 169
171 170 def non_blank_line_by_line_compare(a,b):
  171 + a = textwrap.dedent(a)
  172 + b = textwrap.dedent(b)
172 173 a = [l for l in a.split('\n') if l.strip()]
173 174 b = [l for l in b.split('\n') if l.strip()]
174 175 for n,line in enumerate(a):
@@ -597,20 +598,29 @@ def spam(self, a, b):
597 598 def ham(self, c, d):
598 599 """Cheese\n\nNo cheese."""
599 600 pass
  601 + @property
  602 + def spammity(self):
  603 + """Spammity index"""
  604 + return 0.95
600 605
601 606 for cls in (ClassDoc, SphinxClassDoc):
602 607 doc = cls(Dummy, config=dict(show_class_members=False))
603 608 assert 'Methods' not in str(doc), (cls, str(doc))
604 609 assert 'spam' not in str(doc), (cls, str(doc))
605 610 assert 'ham' not in str(doc), (cls, str(doc))
  611 + assert 'spammity' not in str(doc), (cls, str(doc))
  612 + assert 'Spammity index' not in str(doc), (cls, str(doc))
606 613
607 614 doc = cls(Dummy, config=dict(show_class_members=True))
608 615 assert 'Methods' in str(doc), (cls, str(doc))
609 616 assert 'spam' in str(doc), (cls, str(doc))
610 617 assert 'ham' in str(doc), (cls, str(doc))
  618 + assert 'spammity' in str(doc), (cls, str(doc))
611 619
612 620 if cls is SphinxClassDoc:
613 621 assert '.. autosummary::' in str(doc), str(doc)
  622 + else:
  623 + assert 'Spammity index' in str(doc), str(doc)
614 624
615 625 def test_duplicate_signature():
616 626 # Duplicate function signatures occur e.g. in ufuncs, when the
@@ -626,6 +636,108 @@ def test_duplicate_signature():
626 636
627 637 assert doc['Signature'].strip() == 'z(a, theta)'
628 638
  639 +
  640 +class_doc_txt = """
  641 + Foo
  642 +
  643 + Parameters
  644 + ----------
  645 + f : callable ``f(t, y, *f_args)``
  646 + Aaa.
  647 + jac : callable ``jac(t, y, *jac_args)``
  648 + Bbb.
  649 +
  650 + Attributes
  651 + ----------
  652 + t : float
  653 + Current time.
  654 + y : ndarray
  655 + Current variable values.
  656 +
  657 + Methods
  658 + -------
  659 + a
  660 + b
  661 + c
  662 +
  663 + Examples
  664 + --------
  665 + For usage examples, see `ode`.
  666 +"""
  667 +
  668 +def test_class_members_doc():
  669 + doc = ClassDoc(None, class_doc_txt)
  670 + non_blank_line_by_line_compare(str(doc),
  671 + """
  672 + Foo
  673 +
  674 + Parameters
  675 + ----------
  676 + f : callable ``f(t, y, *f_args)``
  677 + Aaa.
  678 + jac : callable ``jac(t, y, *jac_args)``
  679 + Bbb.
  680 +
  681 + Examples
  682 + --------
  683 + For usage examples, see `ode`.
  684 +
  685 + Attributes
  686 + ----------
  687 + t : float
  688 + Current time.
  689 + y : ndarray
  690 + Current variable values.
  691 +
  692 + Methods
  693 + -------
  694 + a :
  695 +
  696 + b :
  697 +
  698 + c :
  699 +
  700 + .. index::
  701 +
  702 + """)
  703 +
  704 +def test_class_members_doc_sphinx():
  705 + doc = SphinxClassDoc(None, class_doc_txt)
  706 + non_blank_line_by_line_compare(str(doc),
  707 + """
  708 + Foo
  709 +
  710 + :Parameters:
  711 +
  712 + **f** : callable ``f(t, y, *f_args)``
  713 +
  714 + Aaa.
  715 +
  716 + **jac** : callable ``jac(t, y, *jac_args)``
  717 +
  718 + Bbb.
  719 +
  720 + .. rubric:: Examples
  721 +
  722 + For usage examples, see `ode`.
  723 +
  724 + .. rubric:: Attributes
  725 +
  726 + === ==========
  727 + t (float) Current time.
  728 + y (ndarray) Current variable values.
  729 + === ==========
  730 +
  731 + .. rubric:: Methods
  732 +
  733 + === ==========
  734 + a
  735 + b
  736 + c
  737 + === ==========
  738 +
  739 + """)
  740 +
629 741 if __name__ == "__main__":
630 742 import nose
631 743 nose.run()

0 comments on commit 1b2e585

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