[Python-checkins] r47254 - python/branches/hoxworth-stdlib_logging-soc/test_soc_httplib.py

jackilyn.hoxworth python-checkins at python.org
Thu Jul 6 07:26:29 CEST 2006


Author: jackilyn.hoxworth
Date: Thu Jul  6 07:26:29 2006
New Revision: 47254

Added:
   python/branches/hoxworth-stdlib_logging-soc/test_soc_httplib.py
Log:
Added items remotely

test_soc_httplib.py
httplib.py


Added: python/branches/hoxworth-stdlib_logging-soc/test_soc_httplib.py
==============================================================================
--- (empty file)
+++ python/branches/hoxworth-stdlib_logging-soc/test_soc_httplib.py	Thu Jul  6 07:26:29 2006
@@ -0,0 +1,33 @@
+# !/usr/bin/env python
+
+""""
+Test harness for the standard library logging module.
+
+"""
+
+import logging
+import httplib
+from cStringIO import StringIO
+
+log=logging.getLogger("py.httplib")
+stringLog = StringIO()
+
+# define the handler and level
+handler = logging.StreamHandler(stringLog)
+log.setLevel(logging.INFO)
+
+# set a format for the output
+formatter = logging.Formatter('%(name)s:  %(levelname)s %(message)s')
+handler.setFormatter(formatter)
+
+# add the handler to the logger
+log.addHandler(handler)
+
+httplib.HTTPResponse(sock).log("message 1")
+httplib.HTTPConnection().log("message 2")
+print stringLog.getvalue()  # For testing purposes
+
+if stringLog.getvalue() != "Error:  It worked":
+    print "it worked"
+else:
+    print "it didn't work"


More information about the Python-checkins mailing list