update for smoke tests

This commit is contained in:
Miroslav Stampar 2010-08-20 21:01:51 +00:00
parent 8aa12db425
commit 4edf6ebe00
2 changed files with 37 additions and 15 deletions

View File

@ -18,13 +18,13 @@
"""An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive. """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
>>> import urllib2 import urllib2
>>> from keepalive import HTTPHandler from keepalive import HTTPHandler
>>> keepalive_handler = HTTPHandler() keepalive_handler = HTTPHandler()
>>> opener = urllib2.build_opener(keepalive_handler) opener = urllib2.build_opener(keepalive_handler)
>>> urllib2.install_opener(opener) urllib2.install_opener(opener)
>>>
>>> fo = urllib2.urlopen('http://www.python.org') fo = urllib2.urlopen('http://www.python.org')
To remove the handler, simply re-run build_opener with no arguments, and To remove the handler, simply re-run build_opener with no arguments, and
install that opener. install that opener.
@ -37,7 +37,9 @@ use the handler methods:
close_all() close_all()
open_connections() open_connections()
>>> keepalive_handler.close_all() Example:
keepalive_handler.close_all()
EXTRA ATTRIBUTES AND METHODS EXTRA ATTRIBUTES AND METHODS
@ -53,8 +55,8 @@ EXTRA ATTRIBUTES AND METHODS
If you want the best of both worlds, use this inside an If you want the best of both worlds, use this inside an
AttributeError-catching try: AttributeError-catching try:
>>> try: status = fo.status try: status = fo.status
>>> except AttributeError: status = None except AttributeError: status = None
Unfortunately, these are ONLY there if status == 200, so it's not Unfortunately, these are ONLY there if status == 200, so it's not
easy to distinguish between non-200 responses. The reason is that easy to distinguish between non-200 responses. The reason is that

View File

@ -1356,6 +1356,16 @@ def getPartRun():
return commonPartsDict[retVal][1] if retVal in commonPartsDict else retVal return commonPartsDict[retVal][1] if retVal in commonPartsDict else retVal
def getUnicode(value): def getUnicode(value):
"""
Return the unicode representation of the supplied value:
>>> getUnicode(u'test')
u'test'
>>> getUnicode('test')
u'test'
>>> getUnicode(1)
u'1'
"""
if isinstance(value, basestring): if isinstance(value, basestring):
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding if 'dataEncoding' in conf else "utf-8", errors='replace') return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding if 'dataEncoding' in conf else "utf-8", errors='replace')
else: else:
@ -1416,6 +1426,7 @@ def commonFinderOnly(initial, sequence):
return longestCommonPrefix(*filter(lambda x: x.startswith(initial), sequence)) return longestCommonPrefix(*filter(lambda x: x.startswith(initial), sequence))
def smokeTest(): def smokeTest():
import doctest
retVal = True retVal = True
for root, _, files in os.walk(paths.SQLMAP_ROOT_PATH): for root, _, files in os.walk(paths.SQLMAP_ROOT_PATH):
for file in files: for file in files:
@ -1424,15 +1435,24 @@ def smokeTest():
path = path.replace(paths.SQLMAP_ROOT_PATH, '.') path = path.replace(paths.SQLMAP_ROOT_PATH, '.')
path = path.replace(os.sep, '.').lstrip('.') path = path.replace(os.sep, '.').lstrip('.')
try: try:
module = __import__(path) __import__(path)
module = sys.modules[path]
except Exception, msg: except Exception, msg:
retVal = False retVal = False
errMsg = "smoke test failed at importing module '%s' (%s):\n%s\n" % (path, os.path.join(paths.SQLMAP_ROOT_PATH, file), msg) errMsg = "smoke test failed at importing module '%s' (%s):\n%s\n" % (path, os.path.join(paths.SQLMAP_ROOT_PATH, file), msg)
logger.error(errMsg) logger.error(errMsg)
else:
# Run doc tests
# Reference: http://docs.python.org/library/doctest.html
results = doctest.testmod(module)
if results.failed > 0:
retVal = False
infoMsg = "smoke test "
if retVal: if retVal:
infoMsg = "smoke test PASSED" infoMsg += "PASSED"
logger.info(infoMsg) logger.info(infoMsg)
else: else:
errMsg = "smoke test FAILED" infoMsg += "FAILED"
logger.error(errMsg) logger.error(infoMsg)
return retVal return retVal