class TruthFileTester(object): def __init__(self, testing=False): if testing: return self.mysqlDb = MySQLDB(user='******') scriptDir = os.path.dirname(os.path.abspath(__file__)) print scriptDir #**** truthFilesDir = os.path.join(scriptDir, '../json_to_relation/test/data') print truthFilesDir #**** for filename in os.listdir(truthFilesDir): if filename.endswith('Truth.sql'): print('Testing truth file %s' % filename) for sqlStatement in self.getSQLStatement(os.path.join(truthFilesDir, filename)): try: for res in self.mysqlDb.query(sqlStatement): print res except (pymysql.err.InternalError, pymysql.err.IntegrityError, pymysql.err.Error) as e: print >>sys.stderr, 'Failed in filename %s: %s' % (filename, `e`) print 'Done.' def getSQLStatement(self, fileName): fullLine = '' for line in open(fileName, 'r'): line = line.strip() fullLine += line if fullLine.endswith(';'): yield fullLine fullLine = ''