[Python-checkins] r51622 - python/branches/hoxworth-stdlib_logging-soc/pep_update.txt python/branches/hoxworth-stdlib_logging-soc/smtpd.py python/branches/hoxworth-stdlib_logging-soc/test_robotparser.py python/branches/hoxworth-stdlib_logging-soc/test_robotparser_loggin.py python/branches/hoxworth-stdlib_logging-soc/test_shlex_logging.py python/branches/hoxworth-stdlib_logging-soc/test_stmpd_logging.py
jackilyn.hoxworth
python-checkins at python.org
Sat Aug 26 04:29:59 CEST 2006
Author: jackilyn.hoxworth
Date: Sat Aug 26 04:29:57 2006
New Revision: 51622
Added:
python/branches/hoxworth-stdlib_logging-soc/test_robotparser.py
python/branches/hoxworth-stdlib_logging-soc/test_shlex_logging.py
python/branches/hoxworth-stdlib_logging-soc/test_stmpd_logging.py
Modified:
python/branches/hoxworth-stdlib_logging-soc/pep_update.txt
python/branches/hoxworth-stdlib_logging-soc/smtpd.py
python/branches/hoxworth-stdlib_logging-soc/test_robotparser_loggin.py
Log:
Modified: python/branches/hoxworth-stdlib_logging-soc/pep_update.txt
==============================================================================
--- python/branches/hoxworth-stdlib_logging-soc/pep_update.txt (original)
+++ python/branches/hoxworth-stdlib_logging-soc/pep_update.txt Sat Aug 26 04:29:57 2006
@@ -1,21 +1,21 @@
-Modifications to the Original Proposal
-- the import is delayed until it's need
-
-Module Checklist
-BaseHTTPServer.py - done but no test case created
-SocketServer.py - done but no test case created
-asyncore.py - done
-gopherlib.py - done but no test case created
-httplib - done with a test case almost completed
-ihooks.py - done but no test case created
-imaplib.py - done but no test case created
-mhlib.py - done but no test case created
-nntplib.py - done but no test case created
-pipes.py - done but no test case created
-pkgutil.py - done but no test case created
-robotparser.py - done
-shlex.py - done but no test case created
-smtpd.py - done but no test case created
-threading.py - done but no test case created
-timeit.py - done but no test case created
+Modifications to the Original Proposal
+- the import is delayed until it's need
+
+Module Checklist
+BaseHTTPServer.py - done but no test case created
+SocketServer.py - done but no test case created
+asyncore.py - done
+gopherlib.py - done but no test case created
+httplib - done with a test case almost completed
+ihooks.py - done but no test case created
+imaplib.py - done but no test case created
+mhlib.py - done but no test case created
+nntplib.py - done but no test case created
+pipes.py - done but no test case created
+pkgutil.py - done but no test case created
+robotparser.py - done
+shlex.py - done
+smtpd.py - done
+threading.py - done but no test case created
+timeit.py - done but no test case created
trace.py - done but no test case created
\ No newline at end of file
Modified: python/branches/hoxworth-stdlib_logging-soc/smtpd.py
==============================================================================
--- python/branches/hoxworth-stdlib_logging-soc/smtpd.py (original)
+++ python/branches/hoxworth-stdlib_logging-soc/smtpd.py Sat Aug 26 04:29:57 2006
@@ -235,7 +235,7 @@
self.push('250 Ok')
def smtp_RCPT(self, arg):
- _log.debug(>> DEBUGSTREAM, '===> RCPT', arg)
+ _log.debug( DEBUGSTREAM, '===> RCPT', arg)
if not self.__mailfrom:
self.push('503 Error: need MAIL command')
return
Added: python/branches/hoxworth-stdlib_logging-soc/test_robotparser.py
==============================================================================
--- (empty file)
+++ python/branches/hoxworth-stdlib_logging-soc/test_robotparser.py Sat Aug 26 04:29:57 2006
@@ -0,0 +1,162 @@
+import unittest, logging, StringIO, robotparser
+from test import test_support
+
+class RobotTestCase(unittest.TestCase):
+ def __init__(self, index, parser, url, good, agent):
+ unittest.TestCase.__init__(self)
+
+ self.log = log = logging.getLogger("py.robotparser")
+ self.outlog = StringIO.StringIO()
+ self.loghandler = logging.StreamHandler(self.outlog)
+ log.setLevel(logging.INFO)
+ log.addHandler(self.loghandler)
+
+ if good:
+ self.str = "RobotTest(%d, good, %s)" % (index, url)
+ else:
+ self.str = "RobotTest(%d, bad, %s)" % (index, url)
+
+ # The default setup permits warnings
+ robotparser._log.warn("Testing log of " + self.str)
+
+ self.parser = parser
+ self.url = url
+ self.good = good
+ self.agent = agent
+
+ def runTest(self):
+ if isinstance(self.url, tuple):
+ agent, url = self.url
+ else:
+ url = self.url
+ agent = self.agent
+ if self.good:
+ self.failUnless(self.parser.can_fetch(agent, url))
+ else:
+ self.failIf(self.parser.can_fetch(agent, url))
+
+ self.log.removeHandler(self.outlog)
+ # In the default configuration, unless someone has flipped the debug
+ # switch externally, nothing should be logged from the module itself.
+ # Unfortunately, unittest timing means that there may be additional
+ # output from other test cases.
+ self.failUnless(("Testing log of "+ self.str) in self.outlog.getvalue())
+ for line in self.outlog.readlines():
+ self.failUnless(line.startswith("Testing log of "))
+
+ def __str__(self):
+ return self.str
+
+tests = unittest.TestSuite()
+
+def RobotTest(index, robots_txt, good_urls, bad_urls,
+ agent="test_robotparser"):
+
+ lines = StringIO.StringIO(robots_txt).readlines()
+ parser = robotparser.RobotFileParser()
+ parser.parse(lines)
+ for url in good_urls:
+ tests.addTest(RobotTestCase(index, parser, url, 1, agent))
+ for url in bad_urls:
+ tests.addTest(RobotTestCase(index, parser, url, 0, agent))
+
+# Examples from http://www.robotstxt.org/wc/norobots.html (fetched 2002)
+
+# 1.
+doc = """
+User-agent: *
+Disallow: /cyberworld/map/ # This is an infinite virtual URL space
+Disallow: /tmp/ # these will soon disappear
+Disallow: /foo.html
+"""
+
+good = ['/','/test.html']
+bad = ['/cyberworld/map/index.html','/tmp/xxx','/foo.html']
+
+RobotTest(1, doc, good, bad)
+
+# 2.
+doc = """
+# robots.txt for http://www.example.com/
+
+User-agent: *
+Disallow: /cyberworld/map/ # This is an infinite virtual URL space
+
+# Cybermapper knows where to go.
+User-agent: cybermapper
+Disallow:
+
+"""
+
+good = ['/','/test.html',('cybermapper','/cyberworld/map/index.html')]
+bad = ['/cyberworld/map/index.html']
+
+RobotTest(2, doc, good, bad)
+
+# 3.
+doc = """
+# go away
+User-agent: *
+Disallow: /
+"""
+
+good = []
+bad = ['/cyberworld/map/index.html','/','/tmp/']
+
+RobotTest(3, doc, good, bad)
+
+# Examples from http://www.robotstxt.org/wc/norobots-rfc.html (fetched 2002)
+
+# 4.
+doc = """
+User-agent: figtree
+Disallow: /tmp
+Disallow: /a%3cd.html
+Disallow: /a%2fb.html
+Disallow: /%7ejoe/index.html
+"""
+
+good = [] # XFAIL '/a/b.html'
+bad = ['/tmp','/tmp.html','/tmp/a.html',
+ '/a%3cd.html','/a%3Cd.html','/a%2fb.html',
+ '/~joe/index.html'
+ ]
+
+RobotTest(4, doc, good, bad, 'figtree')
+RobotTest(5, doc, good, bad, 'FigTree Robot libwww-perl/5.04')
+
+# 6.
+doc = """
+User-agent: *
+Disallow: /tmp/
+Disallow: /a%3Cd.html
+Disallow: /a/b.html
+Disallow: /%7ejoe/index.html
+"""
+
+good = ['/tmp',] # XFAIL: '/a%2fb.html'
+bad = ['/tmp/','/tmp/a.html',
+ '/a%3cd.html','/a%3Cd.html',"/a/b.html",
+ '/%7Ejoe/index.html']
+
+RobotTest(6, doc, good, bad)
+
+# From bug report #523041
+
+# 7.
+doc = """
+User-Agent: *
+Disallow: /.
+"""
+
+good = ['/foo.html']
+bad = [] # Bug report says "/" should be denied, but that is not in the RFC
+
+RobotTest(7, doc, good, bad)
+
+def test_main():
+ test_support.run_suite(tests)
+
+if __name__=='__main__':
+ test_support.Verbose = 1
+ test_support.run_suite(tests)
Modified: python/branches/hoxworth-stdlib_logging-soc/test_robotparser_loggin.py
==============================================================================
--- python/branches/hoxworth-stdlib_logging-soc/test_robotparser_loggin.py (original)
+++ python/branches/hoxworth-stdlib_logging-soc/test_robotparser_loggin.py Sat Aug 26 04:29:57 2006
@@ -13,7 +13,7 @@
# add the handler to the logger
log.addHandler(handler)
-robotparser._log.info("message 1") # 1st test
+robotparser._log.info("message 1")
print stringLog.getvalue() # For testing purposes
Added: python/branches/hoxworth-stdlib_logging-soc/test_shlex_logging.py
==============================================================================
--- (empty file)
+++ python/branches/hoxworth-stdlib_logging-soc/test_shlex_logging.py Sat Aug 26 04:29:57 2006
@@ -0,0 +1,23 @@
+import shlex
+import logging
+from cStringIO import StringIO
+
+# ... run the tests ...
+log=logging.getLogger("py.shlex")
+stringLog = StringIO()
+
+# define the handler and level
+handler = logging.StreamHandler(stringLog)
+log.setLevel(logging.INFO)
+
+# add the handler to the logger
+log.addHandler(handler)
+
+shlex._log.info("message 1")
+
+print stringLog.getvalue() # For testing purposes
+
+if stringLog.getvalue() != "Error: It worked":
+ print "it worked"
+else:
+ print "it didn't work"
\ No newline at end of file
Added: python/branches/hoxworth-stdlib_logging-soc/test_stmpd_logging.py
==============================================================================
--- (empty file)
+++ python/branches/hoxworth-stdlib_logging-soc/test_stmpd_logging.py Sat Aug 26 04:29:57 2006
@@ -0,0 +1,23 @@
+import smtpd
+import logging
+from cStringIO import StringIO
+
+# ... run the tests ...
+log=logging.getLogger("py.smtpd")
+stringLog = StringIO()
+
+# define the handler and level
+handler = logging.StreamHandler(stringLog)
+log.setLevel(logging.INFO)
+
+# add the handler to the logger
+log.addHandler(handler)
+
+smtpd._log.info("message 1")
+
+print stringLog.getvalue() # For testing purposes
+
+if stringLog.getvalue() != "Error: It worked":
+ print "it worked"
+else:
+ print "it didn't work"
\ No newline at end of file
More information about the Python-checkins
mailing list