def my_call(q, expected_error=''): # Print the query string. print q # Choose between Java or C++ version of iquery. cmd_list = [os.environ['SCIDB_INSTALL_PATH'] + "/bin/iquery", "-aq", q] if using_java_iquery: cmd_list = [ find_java8.find(), "-ea", "-cp", os.environ['SCIDB_INSTALL_PATH'] + "/jdbc/scidb4j.jar", "org.scidb.iquery.Iquery", "-aq", q ] # Execute the query. p = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, stdout=subprocess.PIPE) out, err = p.communicate() # collect stdout,stderr, wait # Print the result. if expected_error == '' and err != '': raise Exception(err) elif expected_error != '' and err == '': raise Exception("Expected error " + expected_error + ", but the query succeeded.") elif expected_error != '' and err != '': if expected_error in err: print 'Expecting error ' + expected_error + ', and the query failed with that error. Good!' print else: raise Exception('The expected error, ' + expected_error + ', did not match the actual error\n' + err) else: # expected_error=='' and err=='' print out
def main(test_name, expected_result): """Given a test in example.jar, run it. @param test_name the name of a Java file in example.jar, e.g. JDBCExample. @param expected_result the name of a file that stores the expected result. """ print 'SCIDB_INSTALL_PATH', os.environ['SCIDB_INSTALL_PATH'] iquery_host = 'localhost' iquery_port = '1239' if 'IQUERY_HOST' in os.environ: iquery_host = os.environ['IQUERY_HOST'] if 'IQUERY_PORT' in os.environ: iquery_port = os.environ['IQUERY_PORT'] cmd = [ find_java8.find(), '-classpath', ':'.join( ('${SCIDB_INSTALL_PATH}/jdbc/example.jar', '${SCIDB_INSTALL_PATH}/jdbc/scidb4j.jar')), 'org.scidb.%s' % test_name, iquery_host, iquery_port ] env_scidb_config_user = os.environ["SCIDB_CONFIG_USER"] if len(env_scidb_config_user) > 0: cmd.extend([env_scidb_config_user]) proc = runSubProcess(cmd, useShell=True) exitCode = proc.poll() while (exitCode is None): time.sleep(0.1) exitCode = proc.poll() sOut = proc.stdout.read().strip() sErr = proc.stderr.read().strip() if (exitCode != 0): print 'Bad exit code!' print sErr sys.exit(1) print sOut generated_lines = sOut.split('\n') # Verify the result expected_lines = open(expected_result).readlines() len_expected = len(expected_lines) len_generated = len(generated_lines) if len_generated != len_expected: print "Expected %s lines but received %s lines" % (len_expected, len_generated) sys.exit(1) for i in range(len_expected): if expected_lines[i].rstrip() != generated_lines[i]: print "Line {0} mismatch!".format(i + 1) print "Expected: %s" % expected_lines[i] print "Generated: %s" % generated_lines[i] sys.exit(1) print "Java code produced expected result."
def main(): print 'SCIDB_INSTALL_PATH',os.environ['SCIDB_INSTALL_PATH'] iquery_host = 'localhost' iquery_port = '1239' if (os.environ.has_key('IQUERY_HOST')): iquery_host = os.environ['IQUERY_HOST'] if (os.environ.has_key('IQUERY_PORT')): iquery_port = os.environ['IQUERY_PORT'] cmd = [ find_java8.find(), '-classpath', '${SCIDB_INSTALL_PATH}/jdbc/example.jar:${SCIDB_INSTALL_PATH}/jdbc/scidb4j.jar', 'org.scidb.JDBCExample', iquery_host, iquery_port ] proc = runSubProcess(cmd,useShell=True) exitCode = proc.poll() while (exitCode is None): time.sleep(0.1) exitCode = proc.poll() sOut = proc.stdout.read().strip() sErr = proc.stderr.read().strip() sOut = sOut.split('\n') if (exitCode != 0): print 'Bad exit code!' print sErr sys.exit(1) expectedData = [ '0 0 a', '0 1 b', '0 2 c', '1 0 d', '1 1 e', '1 2 f', '2 0 123', '2 1 456', '2 2 789' ] compData = sOut[8:] if (set(expectedData) != set(compData)): print 'Error: data mismatch!' print 'Expected:' print '\n'.join(expectedData) print 'Received:' print '\n'.join(compData) sys.exit(1) print 'PASS'
def my_call(using_java_iquery, q, ignore_output=False, expected_error=''): """Call either the java version of the c++ version of iquery. @param using_java_iquery whether to use the Java version. @param q the query string. @param ignore_output whether to use the '-n' switch. @param expected_error the expected error if any. """ # Print the query string. print q env_scidb_config_user = os.environ["SCIDB_CONFIG_USER"] # Choose between Java or C++ version of iquery. cmd_list = [os.environ['SCIDB_INSTALL_PATH'] + "/bin/iquery"] if using_java_iquery: cmd_list = [ find_java8.find(), "-ea", "-cp", os.environ['SCIDB_INSTALL_PATH'] + "/jdbc/scidb4j.jar", "org.scidb.iquery.Iquery" ] if len(env_scidb_config_user) > 0: cmd_list.extend(["--auth-file", env_scidb_config_user]) if ignore_output: cmd_list.extend(['-n']) cmd_list.extend(["-aq", q]) # Execute the query. p = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, stdout=subprocess.PIPE) out, err = p.communicate() # collect stdout,stderr, wait # Print the result. if expected_error == '' and err != '': raise Exception(err) elif expected_error != '' and err == '': raise Exception("Expected error " + expected_error + ", but the query succeeded.") elif expected_error != '' and err != '': if expected_error in err: print 'Expecting error ' + expected_error + ', and the query failed with that error. Good!' print else: raise Exception('The expected error, ' + expected_error + ', did not match the actual error\n' + err) else: # expected_error=='' and err=='' print out
def main(): print 'SCIDB_INSTALL_PATH',os.environ['SCIDB_INSTALL_PATH'] iquery_host = 'localhost' iquery_port = '1239' if (os.environ.has_key('IQUERY_HOST')): iquery_host = os.environ['IQUERY_HOST'] if (os.environ.has_key('IQUERY_PORT')): iquery_port = os.environ['IQUERY_PORT'] cmd = [ find_java8.find(), '-classpath', ':'.join(('${SCIDB_INSTALL_PATH}/jdbc/scidb4j.jar', '${SCIDB_INSTALL_PATH}/jdbc/jdbctest.jar', '/usr/share/java/junit.jar')), 'org.scidb.JDBCTest', iquery_host, iquery_port ] env_scidb_config_user = os.environ["SCIDB_CONFIG_USER"] if len(env_scidb_config_user) > 0: cmd.extend([env_scidb_config_user]) proc = subprocess.Popen( # Run the command. ' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True ) exitCode = proc.poll() while (exitCode is None): time.sleep(0.1) exitCode = proc.poll() sOut = proc.stdout.read().strip() sErr = proc.stderr.read().strip() if (exitCode != 0): print 'Bad exit code!' print sErr sys.exit(1) if (('FAILURES!!!' in sOut) or ('FAILURES!!!' in sErr)): print sOut print sErr print 'FAIL' sys.exit(1) print 'PASS'
def main(): print 'SCIDB_INSTALL_PATH',os.environ['SCIDB_INSTALL_PATH'] iquery_host = 'localhost' iquery_port = '1239' if (os.environ.has_key('IQUERY_HOST')): iquery_host = os.environ['IQUERY_HOST'] if (os.environ.has_key('IQUERY_PORT')): iquery_port = os.environ['IQUERY_PORT'] cmd = [ find_java8.find(), '-classpath', ':'.join(('${SCIDB_INSTALL_PATH}/jdbc/scidb4j.jar', '${SCIDB_INSTALL_PATH}/jdbc/jdbctest.jar', '/usr/share/java/junit.jar')), 'org.scidb.JDBCTest', iquery_host, iquery_port ] proc = subprocess.Popen( # Run the command. ' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True ) exitCode = proc.poll() while (exitCode is None): time.sleep(0.1) exitCode = proc.poll() sOut = proc.stdout.read().strip() sErr = proc.stderr.read().strip() if (exitCode != 0): print 'Bad exit code!' print sErr sys.exit(1) if (('FAILURES!!!' in sOut) or ('FAILURES!!!' in sErr)): print sOut print sErr print 'FAIL' sys.exit(1) print 'PASS'
def my_call(q, expected_error=''): # Print the query string. print q env_scidb_config_user = os.environ["SCIDB_CONFIG_USER"] # Choose between Java or C++ version of iquery. cmd_list = [ os.environ['SCIDB_INSTALL_PATH']+"/bin/iquery" ] if using_java_iquery: cmd_list = [ find_java8.find(), "-ea", "-cp", os.environ['SCIDB_INSTALL_PATH']+"/jdbc/scidb4j.jar", "org.scidb.iquery.Iquery" ] if len(env_scidb_config_user) > 0: cmd_list.extend(["--auth-file", env_scidb_config_user]) cmd_list.extend(["-aq", q]) # Execute the query. p = subprocess.Popen(cmd_list, stderr=subprocess.PIPE, stdout=subprocess.PIPE) out, err = p.communicate() # collect stdout,stderr, wait # Print the result. if expected_error=='' and err!='': raise Exception(err) elif expected_error!='' and err=='': raise Exception("Expected error " + expected_error + ", but the query succeeded.") elif expected_error!='' and err!='': if expected_error in err: print 'Expecting error ' + expected_error + ', and the query failed with that error. Good!' print else: raise Exception('The expected error, ' + expected_error + ', did not match the actual error\n' + err) else: # expected_error=='' and err=='' print out