@@ -1356,6 +1356,16 @@ def getPartRun():
13561356 return commonPartsDict [retVal ][1 ] if retVal in commonPartsDict else retVal
13571357
13581358def 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
14181428def 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