[Python-checkins] r51104 - python/branches/hoxworth-stdlib_logging-soc/fakesocket.py python/branches/hoxworth-stdlib_logging-soc/new_soc_logging_test.py
jackilyn.hoxworth
python-checkins at python.org
Fri Aug 4 16:54:56 CEST 2006
Author: jackilyn.hoxworth
Date: Fri Aug 4 16:54:56 2006
New Revision: 51104
Modified:
python/branches/hoxworth-stdlib_logging-soc/fakesocket.py
python/branches/hoxworth-stdlib_logging-soc/new_soc_logging_test.py
Log:
Modified: python/branches/hoxworth-stdlib_logging-soc/fakesocket.py
==============================================================================
--- python/branches/hoxworth-stdlib_logging-soc/fakesocket.py (original)
+++ python/branches/hoxworth-stdlib_logging-soc/fakesocket.py Fri Aug 4 16:54:56 2006
@@ -1,11 +1,16 @@
import socket
+from socket import *
+import fakesocket as self
+import socket as origsocket
-def getaddrinfo(host,port, *args):
+def getaddrinfo(host, port, *args):
"""no real addr info -- but the test data is copied from 'port' to 'sa'
for a bit of control over the resulting mock socket.
- >>> getaddrinfo("MOCK", "Raise: connection prohibited")
- ("af", "socktype", "proto", "cannonname", "Raise: connection prohibited")
- """
+
+ getaddrinfo("MOCK", "Raise: connection prohibited")
+ ("af", "socktype", "proto", "cannonname", "Raise: connection prohibited")"""
+
+ host = "MOCK"
if host != "MOCK":
raise ValueError("Faked Socket Module for testing only")
@@ -17,7 +22,9 @@
class socket(object):
"""Mock socket object"""
+
def __init__(self, af, socktype, proto): pass
+
def connect(self, sa):
"""Raise if the argument says raise, otherwise sa is treated as the response.
Wouldn't hurt to put doctests in here, too...
@@ -26,8 +33,12 @@
raise error(sa)
else:
self.incoming_msg = sa
+
def close(self): pass
+
def sendall(self, msg):
self.gotsent = msg
+
def makefile(self, mode, bufsize):
- return cStringIO(self.incoming_msg)
\ No newline at end of file
+ return cStringIO(self.incoming_msg)
+
\ No newline at end of file
Modified: python/branches/hoxworth-stdlib_logging-soc/new_soc_logging_test.py
==============================================================================
--- python/branches/hoxworth-stdlib_logging-soc/new_soc_logging_test.py (original)
+++ python/branches/hoxworth-stdlib_logging-soc/new_soc_logging_test.py Fri Aug 4 16:54:56 2006
@@ -1,4 +1,5 @@
import httplib
+reload(httplib)
import fakesocket
import logging
from cStringIO import StringIO
@@ -26,7 +27,7 @@
print "Debug level is > 0"
myconn.connect()
-myconn.putrequest("GET", "/search?q=Jackilyn+Hoxworth")
+myconn.putrequest("GET", "/search?q=python")
myconn.getresponse()
print stringLog.getvalue() # For testing purposes
More information about the Python-checkins
mailing list