diff --git a/Lib/test/pydoc_mod.py b/Lib/test/pydoc_mod.py new file mode 100644 index 000000000000..8601e3f7abb3 --- /dev/null +++ b/Lib/test/pydoc_mod.py @@ -0,0 +1,54 @@ +"""This is a test module for test_pydoc""" + +__author__ = "Benjamin Peterson" +__credits__ = "Nobody" +__version__ = "1.2.3.4" + + +class A: + """Hello and goodbye""" + def __init__(): + """Wow, I have no function!""" + pass + +class B(object): + NO_MEANING = "eggs" + pass + +def doc_func(): + """ + This function solves all of the world's problems: + hunger + lack of Python + war + """ + +def nodoc_func(): + pass +"""This is a test module for test_pydoc""" + +__author__ = "Benjamin Peterson" +__credits__ = "Nobody" +__version__ = "1.2.3.4" + + +class A: + """Hello and goodbye""" + def __init__(): + """Wow, I have no function!""" + pass + +class B(object): + NO_MEANING = "eggs" + pass + +def doc_func(): + """ + This function solves all of the world's problems: + hunger + lack of Python + war + """ + +def nodoc_func(): + pass diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index d9670fbbe8ec..a99fa24864bf 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -1,33 +1,263 @@ -from test import test_support -import unittest -import pydoc - -class TestDescriptions(unittest.TestCase): - def test_module(self): - # Check that pydocfodder module can be described - from test import pydocfodder - doc = pydoc.render_doc(pydocfodder) - assert "pydocfodder" in doc - - def test_classic_class(self): - class C: "Classic class" - c = C() - self.failUnlessEqual(pydoc.describe(C), 'class C') - self.failUnlessEqual(pydoc.describe(c), 'instance of C') - self.failUnless('instance of C in module test.test_pydoc' - in pydoc.render_doc(c)) - - def test_class(self): - class C(object): "New-style class" - c = C() - - self.failUnlessEqual(pydoc.describe(C), 'class C') - self.failUnlessEqual(pydoc.describe(c), 'C') - self.failUnless('C in module test.test_pydoc object' - in pydoc.render_doc(c)) - -def test_main(): - test_support.run_unittest(TestDescriptions) - -if __name__ == "__main__": - unittest.main() +import sys +import difflib +import subprocess +import re +import pydoc +import unittest +import test.test_support +from test import pydoc_mod + +expected_text_pattern = \ +""" +NAME + test.pydoc_mod - This is a test module for test_pydoc + +FILE + %s + +CLASSES + __builtin__.object + B + A +\x20\x20\x20\x20 + class A + | Hello and goodbye + |\x20\x20 + | Methods defined here: + |\x20\x20 + | __init__() + | Wow, I have no function! +\x20\x20\x20\x20 + class B(__builtin__.object) + | Data descriptors defined here: + |\x20\x20 + | __dict__ + | dictionary for instance variables (if defined) + |\x20\x20 + | __weakref__ + | list of weak references to the object (if defined) + |\x20\x20 + | ---------------------------------------------------------------------- + | Data and other attributes defined here: + |\x20\x20 + | NO_MEANING = 'eggs' + +FUNCTIONS + doc_func() + This function solves all of the world's problems: + hunger + lack of Python + war +\x20\x20\x20\x20 + nodoc_func() + +DATA + __author__ = 'Benjamin Peterson' + __credits__ = 'Nobody' + __package__ = None + __version__ = '1.2.3.4' + +VERSION + 1.2.3.4 + +AUTHOR + Benjamin Peterson + +CREDITS + Nobody +""".strip() + +expected_html_pattern = \ +""" +
| + test.pydoc_mod (version 1.2.3.4) | index %s |
This is a test module for test_pydoc
++
| +Classes | ||||||||||||||||
| + |
+
+
| |||||||||||||||
+
| +Functions | ||
| + |
| |
+
| +Data | ||
| + | __author__ = 'Benjamin Peterson' +__credits__ = 'Nobody' +__package__ = None +__version__ = '1.2.3.4' | |
+
| +Author | ||
| + | Benjamin Peterson | |
+
| +Credits | ||
| + | Nobody | |