MCPcopy Index your code
hub / github.com/python/cpython / test_server

Method test_server

Lib/test/test_pydoc/test_pydoc.py:2080–2112  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2078 self.assertIs(sys.modules['pydoc'], pydoc)
2079
2080 def test_server(self):
2081 # Minimal test that starts the server, checks that it works, then stops
2082 # it and checks its cleanup.
2083 def my_url_handler(url, content_type):
2084 text = 'the URL sent was: (%s, %s)' % (url, content_type)
2085 return text
2086
2087 serverthread = pydoc._start_server(
2088 my_url_handler,
2089 hostname='localhost',
2090 port=0,
2091 )
2092 self.assertEqual(serverthread.error, None)
2093 self.assertTrue(serverthread.serving)
2094 self.addCleanup(
2095 lambda: serverthread.stop() if serverthread.serving else None
2096 )
2097 self.assertIn('localhost', serverthread.url)
2098
2099 self.addCleanup(urlcleanup)
2100 self.assertEqual(
2101 b'the URL sent was: (/test, text/html)',
2102 urlopen(urllib.parse.urljoin(serverthread.url, '/test')).read(),
2103 )
2104 self.assertEqual(
2105 b'the URL sent was: (/test.css, text/css)',
2106 urlopen(urllib.parse.urljoin(serverthread.url, '/test.css')).read(),
2107 )
2108
2109 serverthread.stop()
2110 self.assertFalse(serverthread.serving)
2111 self.assertIsNone(serverthread.docserver)
2112 self.assertIsNone(serverthread.url)
2113
2114
2115class PydocUrlHandlerTest(PydocBaseTest):

Callers

nothing calls this directly

Calls 9

urlopenFunction · 0.90
assertTrueMethod · 0.80
addCleanupMethod · 0.80
assertInMethod · 0.80
assertFalseMethod · 0.80
assertIsNoneMethod · 0.80
assertEqualMethod · 0.45
stopMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected