Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4edf6eb

Browse files
committed
update for smoke tests
1 parent 8aa12db commit 4edf6eb

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

extra/keepalive/keepalive.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
"""An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
2020
21-
>>> import urllib2
22-
>>> from keepalive import HTTPHandler
23-
>>> keepalive_handler = HTTPHandler()
24-
>>> opener = urllib2.build_opener(keepalive_handler)
25-
>>> urllib2.install_opener(opener)
26-
>>>
27-
>>> fo = urllib2.urlopen('http://www.python.org')
21+
import urllib2
22+
from keepalive import HTTPHandler
23+
keepalive_handler = HTTPHandler()
24+
opener = urllib2.build_opener(keepalive_handler)
25+
urllib2.install_opener(opener)
26+
27+
fo = urllib2.urlopen('http://www.python.org')
2828
2929
To remove the handler, simply re-run build_opener with no arguments, and
3030
install that opener.
@@ -37,7 +37,9 @@
3737
close_all()
3838
open_connections()
3939
40-
>>> keepalive_handler.close_all()
40+
Example:
41+
42+
keepalive_handler.close_all()
4143
4244
EXTRA ATTRIBUTES AND METHODS
4345
@@ -53,8 +55,8 @@
5355
If you want the best of both worlds, use this inside an
5456
AttributeError-catching try:
5557
56-
>>> try: status = fo.status
57-
>>> except AttributeError: status = None
58+
try: status = fo.status
59+
except AttributeError: status = None
5860
5961
Unfortunately, these are ONLY there if status == 200, so it's not
6062
easy to distinguish between non-200 responses. The reason is that

lib/core/common.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,16 @@ def getPartRun():
13561356
return commonPartsDict[retVal][1] if retVal in commonPartsDict else retVal
13571357

13581358
def getUnicode(value):
1359+
"""
1360+
Return the unicode representation of the supplied value:
1361+
1362+
>>> getUnicode(u'test')
1363+
u'test'
1364+
>>> getUnicode('test')
1365+
u'test'
1366+
>>> getUnicode(1)
1367+
u'1'
1368+
"""
13591369
if isinstance(value, basestring):
13601370
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding if 'dataEncoding' in conf else "utf-8", errors='replace')
13611371
else:
@@ -1416,6 +1426,7 @@ def commonFinderOnly(initial, sequence):
14161426
return longestCommonPrefix(*filter(lambda x: x.startswith(initial), sequence))
14171427

14181428
def smokeTest():
1429+
import doctest
14191430
retVal = True
14201431
for root, _, files in os.walk(paths.SQLMAP_ROOT_PATH):
14211432
for file in files:
@@ -1424,15 +1435,24 @@ def smokeTest():
14241435
path = path.replace(paths.SQLMAP_ROOT_PATH, '.')
14251436
path = path.replace(os.sep, '.').lstrip('.')
14261437
try:
1427-
module = __import__(path)
1438+
__import__(path)
1439+
module = sys.modules[path]
14281440
except Exception, msg:
14291441
retVal = False
14301442
errMsg = "smoke test failed at importing module '%s' (%s):\n%s\n" % (path, os.path.join(paths.SQLMAP_ROOT_PATH, file), msg)
14311443
logger.error(errMsg)
1444+
else:
1445+
# Run doc tests
1446+
# Reference: http://docs.python.org/library/doctest.html
1447+
results = doctest.testmod(module)
1448+
if results.failed > 0:
1449+
retVal = False
1450+
1451+
infoMsg = "smoke test "
14321452
if retVal:
1433-
infoMsg = "smoke test PASSED"
1453+
infoMsg += "PASSED"
14341454
logger.info(infoMsg)
14351455
else:
1436-
errMsg = "smoke test FAILED"
1437-
logger.error(errMsg)
1438-
return retVal
1456+
infoMsg += "FAILED"
1457+
logger.error(infoMsg)
1458+
return retVal

0 commit comments

Comments
 (0)