~ubuntu-branches/ubuntu/natty/python3.2/natty-security

« back to all changes in this revision

Viewing changes to Lib/test/test_pydoc.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-02-14 16:12:14 UTC
  • mfrom: (10.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20110214161214-f5vwa226kebccmt9
Tags: 3.2~rc3-1
Python 3.2 release candidate 3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
244
244
    return title
245
245
 
246
246
 
247
 
class PyDocDocTest(unittest.TestCase):
 
247
class PydocDocTest(unittest.TestCase):
248
248
 
249
249
    @unittest.skipIf(sys.flags.optimize >= 2,
250
250
                     "Docstrings are omitted with -O2 and above")
392
392
        self.assertIn(expected, pydoc.render_doc(c))
393
393
 
394
394
 
395
 
class PyDocServerTest(unittest.TestCase):
 
395
class PydocServerTest(unittest.TestCase):
396
396
    """Tests for pydoc._start_server"""
397
397
 
398
398
    def test_server(self):
415
415
        self.assertEqual(serverthread.error, None)
416
416
 
417
417
 
418
 
class PyDocUrlHandlerTest(unittest.TestCase):
 
418
class PydocUrlHandlerTest(unittest.TestCase):
419
419
    """Tests for pydoc._url_handler"""
420
420
 
421
421
    def test_content_type_err(self):
422
 
        err = 'Error: unknown content type '
423
422
        f = pydoc._url_handler
424
 
        result = f("", "")
425
 
        self.assertEqual(result, err + "''")
426
 
        result = f("", "foobar")
427
 
        self.assertEqual(result, err + "'foobar'")
 
423
        self.assertRaises(TypeError, f, 'A', '')
 
424
        self.assertRaises(TypeError, f, 'B', 'foobar')
428
425
 
429
426
    def test_url_requests(self):
430
427
        # Test for the correct title in the html pages returned.
431
428
        # This tests the different parts of the URL handler without
432
429
        # getting too picky about the exact html.
433
430
        requests = [
434
 
            ("", "Python: Index of Modules"),
435
 
            ("get?key=", "Python: Index of Modules"),
436
 
            ("index", "Python: Index of Modules"),
437
 
            ("topics", "Python: Topics"),
438
 
            ("keywords", "Python: Keywords"),
439
 
            ("pydoc", "Python: module pydoc"),
440
 
            ("get?key=pydoc", "Python: module pydoc"),
441
 
            ("search?key=pydoc", "Python: Search Results"),
442
 
            ("def", "Python: KEYWORD def"),
443
 
            ("STRINGS", "Python: TOPIC STRINGS"),
444
 
            ("foobar", "Python: Error"),
445
 
            ("getfile?key=foobar", "Python: Read Error"),
 
431
            ("", "Pydoc: Index of Modules"),
 
432
            ("get?key=", "Pydoc: Index of Modules"),
 
433
            ("index", "Pydoc: Index of Modules"),
 
434
            ("topics", "Pydoc: Topics"),
 
435
            ("keywords", "Pydoc: Keywords"),
 
436
            ("pydoc", "Pydoc: module pydoc"),
 
437
            ("get?key=pydoc", "Pydoc: module pydoc"),
 
438
            ("search?key=pydoc", "Pydoc: Search Results"),
 
439
            ("topic?key=def", "Pydoc: KEYWORD def"),
 
440
            ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
 
441
            ("foobar", "Pydoc: Error - foobar"),
 
442
            ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
446
443
            ]
447
444
 
448
445
        for url, title in requests:
451
448
            self.assertEqual(result, title)
452
449
 
453
450
        path = string.__file__
454
 
        title = "Python: getfile " + path
 
451
        title = "Pydoc: getfile " + path
455
452
        url = "getfile?key=" + path
456
453
        text = pydoc._url_handler(url, "text/html")
457
454
        result = get_html_title(text)
459
456
 
460
457
 
461
458
def test_main():
462
 
    test.support.run_unittest(PyDocDocTest,
 
459
    test.support.run_unittest(PydocDocTest,
463
460
                              TestDescriptions,
464
 
                              PyDocServerTest,
465
 
                              PyDocUrlHandlerTest,
 
461
                              PydocServerTest,
 
462
                              PydocUrlHandlerTest,
466
463
                              )
467
464
 
468
465
if __name__ == "__main__":