MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_server

Method test_server

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

Source from the content-addressed store, hash-verified

2153 self.assertIs(sys.modules['pydoc'], pydoc)
2154
2155 def test_server(self):
2156 # Minimal test that starts the server, checks that it works, then stops
2157 # it and checks its cleanup.
2158 def my_url_handler(url, content_type):
2159 text = 'the URL sent was: (%s, %s)' % (url, content_type)
2160 return text
2161
2162 serverthread = pydoc._start_server(
2163 my_url_handler,
2164 hostname='localhost',
2165 port=0,
2166 )
2167 self.assertEqual(serverthread.error, None)
2168 self.assertTrue(serverthread.serving)
2169 self.addCleanup(
2170 lambda: serverthread.stop() if serverthread.serving else None
2171 )
2172 self.assertIn('localhost', serverthread.url)
2173
2174 self.addCleanup(urlcleanup)
2175 self.assertEqual(
2176 b'the URL sent was: (/test, text/html)',
2177 urlopen(urllib.parse.urljoin(serverthread.url, '/test')).read(),
2178 )
2179 self.assertEqual(
2180 b'the URL sent was: (/test.css, text/css)',
2181 urlopen(urllib.parse.urljoin(serverthread.url, '/test.css')).read(),
2182 )
2183
2184 serverthread.stop()
2185 self.assertFalse(serverthread.serving)
2186 self.assertIsNone(serverthread.docserver)
2187 self.assertIsNone(serverthread.url)
2188
2189
2190class 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