I'm writing a Python client+server that uses gevent.socket for communication. Are there any good ways of testing the socket-level operation of the code (for example, verifying that SSL connections with an invalid certificate will be rejected)? Or is it simplest to just spawn a real server?
Edit: I don't believe that "naive" mocking will be sufficient to test the SSL components because of the complex interactions involved. Am I wrong in that? Or is there a better way to test SSL'd stuff?
Mocking and stubbing are great, but sometimes you need to take it up to the next level of integration.  Since spawning a server, even a fakeish one, can take some time, consider a separate test suite (call them integration tests) might be in order.
"Test it like you are going to use it" is my guideline, and if you mock and stub so much that your test becomes trivial it's not that useful (though almost any test is better than none).  If you are concerned about handling bad SSL certs, by all means make some bad ones and write a test fixture you can feed them to.  If that means spawning a server, so be it. Maybe if that bugs you enough it will lead to a refactoring that will make it testable another way.
Python: unit testing socket-based code?