[Python-Dev] Socket servers in the test suite

Giampaolo Rodolà g.rodola at gmail.com
Thu Apr 28 14:13:36 CEST 2011


2011/4/27 Vinay Sajip <vinay_sajip at yahoo.co.uk>:
> I've been recently trying to improve the test coverage for the logging package,
> and have got to a not unreasonable point:
>
> logging/__init__.py 99% (96%)
> logging/config.py 89% (85%)
> logging/handlers.py 60% (54%)
>
> where the figures in parentheses include branch coverage measurements.
>
> I'm at the point where to appreciably increase coverage, I'd need to write some
> test servers to exercise client code in SocketHandler, DatagramHandler and
> HTTPHandler.
>
> I notice there are no utility classes in test.support to help with this kind of
> thing - would there be any mileage in adding such things? Of course I could add
> test server code just to test_logging (which already contains some socket server
> code to exercise the configuration functionality), but rolling a test server
> involves boilerplate such as using a custom RequestHandler-derived class for
> each application. I had in mind a more streamlined approach where you can just
> pass a single callable to a server to handle requests, e.g. as outlined in
>
> https://gist.github.com/945157
>
> I'd be grateful for any comments about adding such functionality to e.g.
> test.support.
>
> Regards,
>
> Vinay Sajip
>

I agree having a standard server framework for tests woul be useful,
because it's something which appears quite often, (e.g. when writing
functional tests).
See for example:
http://hg.python.org/cpython/file/b452559eee71/Lib/test/test_os.py#l1316
http://hg.python.org/cpython/file/b452559eee71/Lib/test/test_ftplib.py#l211
http://hg.python.org/cpython/file/b452559eee71/Lib/test/test_ssl.py#l844
http://hg.python.org/cpython/file/b452559eee71/Lib/test/test_smtpd.py
http://hg.python.org/cpython/file/b452559eee71/Lib/test/test_poplib.py#l115

Regards

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/


More information about the Python-Dev mailing list