Commit 97aded3d authored by Matthias Rüster's avatar Matthias Rüster
Browse files

Tests: Fix pycodestyle linting issues

parent bf70fe74
......@@ -3,42 +3,41 @@
import sys
import struct
fileA = open( sys.argv[1], 'r' )
fileB = open( sys.argv[2], 'r' )
numDiff = 0
maxDiff = 0.0
bufSize = 1024
fileA.read(56)
fileB.read(56)
while True:
strfA = fileA.read(bufSize)
if strfA == "":
break
strfB = fileB.read(bufSize)
if len(strfA) != len(strfB):
print 'The files have different sizes!'
sys.exit(1)
count = len(strfA) / 4
bufA = struct.unpack( '%uf' % count, strfA )
bufB = struct.unpack( '%uf' % count, strfB )
for valA, valB in zip(bufA, bufB):
if valA != valB:
numDiff += 1
maxDiff = max( maxDiff, abs( valA - valB ) )
if fileB.read(1) != "":
print 'File A is shorter than file B!'
print 'Differences: %u' % numDiff
print 'Max difference: %f' % maxDiff
fileA.close()
fileB.close()
if __name__ == '__main__':
fileA = open(sys.argv[1], 'r')
fileB = open(sys.argv[2], 'r')
numDiff = 0
maxDiff = 0.0
bufSize = 1024
fileA.read(56)
fileB.read(56)
while True:
strfA = fileA.read(bufSize)
if strfA == '':
break
strfB = fileB.read(bufSize)
if len(strfA) != len(strfB):
print('The files have different sizes!')
sys.exit(1)
count = len(strfA) / 4
bufA = struct.unpack('%uf' % count, strfA)
bufB = struct.unpack('%uf' % count, strfB)
for valA, valB in zip(bufA, bufB):
if valA != valB:
numDiff += 1
maxDiff = max(maxDiff, abs(valA - valB))
if fileB.read(1) != '':
print('File A is shorter than file B!')
print('Differences: %u' % numDiff)
print('Max difference: %f' % maxDiff)
fileA.close()
fileB.close()
......@@ -5,45 +5,61 @@ import os
import subprocess
import re
sdir = os.path.dirname( os.path.abspath( sys.argv[0] ) )
grids = sdir + "/grids"
faults = sdir + "/faults"
pois = sdir + "/pois"
if os.access( grids, os.R_OK ) or os.access( faults, os.R_OK ) or os.access( pois, os.R_OK ):
print 'The directories grids/, faults/ and pois/ are already present. Abort.'
sys.exit(1)
p = subprocess.Popen('svn info --xml', shell=True, stdout=subprocess.PIPE)
ret = p.wait()
lines = ""
for line in p.stdout.readlines():
lines += line
matchBase = re.search( "<root>(.*)</root>", lines )
matchPath = re.search( "<wcroot-abspath>(.*)</wcroot-abspath>", lines )
if matchBase and matchPath:
svnbase = matchBase.group(1)
svnpath = matchPath.group(1)
if svnbase == "http://svnext.gfz-potsdam.de/easywave":
# data directory should be present, so just create symbolic links
os.symlink( svnpath + "/data/grids", grids )
os.symlink( svnpath + "/data/faults", faults )
os.symlink( svnpath + "/data/pois", pois )
sys.exit(0)
# directories not present and no suitable svn root was found --> download contents
link = "http://svnext.gfz-potsdam.de/easywave/data"
ret = 0
ret += subprocess.Popen('svn export ' + link + '/grids', shell=True).wait()
ret += subprocess.Popen('svn export ' + link + '/faults', shell=True).wait()
ret += subprocess.Popen('svn export ' + link + '/pois', shell=True).wait()
if ret > 0:
print 'Error: Could not download data.'
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':
sdir = os.path.dirname(os.path.abspath(sys.argv[0]))
grids = sdir + '/grids'
faults = sdir + '/faults'
pois = sdir + '/pois'
if (
os.access(grids, os.R_OK) or
os.access(faults, os.R_OK) or
os.access(pois, os.R_OK)
):
print(
'The directories grids/, faults/ and pois/ are already present. ' +
'Abort.'
)
sys.exit(1)
p = subprocess.Popen('svn info --xml', shell=True, stdout=subprocess.PIPE)
ret = p.wait()
lines = ''
for line in p.stdout.readlines():
lines += line
matchBase = re.search('<root>(.*)</root>', lines)
matchPath = re.search('<wcroot-abspath>(.*)</wcroot-abspath>', lines)
if matchBase and matchPath:
svnbase = matchBase.group(1)
svnpath = matchPath.group(1)
if svnbase == 'http://svnext.gfz-potsdam.de/easywave':
# data directory should be present, so just create symbolic links
os.symlink(svnpath + '/data/grids', grids)
os.symlink(svnpath + '/data/faults', faults)
os.symlink(svnpath + '/data/pois', pois)
sys.exit(0)
# directories not present and no suitable svn root was found
# --> download contents
link = 'http://svnext.gfz-potsdam.de/easywave/data'
ret = 0
ret += subprocess.Popen(
'svn export ' + link + '/grids', shell=True
).wait()
ret += subprocess.Popen(
'svn export ' + link + '/faults', shell=True
).wait()
ret += subprocess.Popen(
'svn export ' + link + '/pois', shell=True
).wait()
if ret > 0:
print('Error: Could not download data.')
sys.exit(1)
sys.exit(0)
......@@ -8,106 +8,117 @@ import subprocess
import glob
import re
sdir = os.path.dirname( os.path.abspath( sys.argv[0] ) )
def start( cmd ):
tmp_path = tempfile.mkdtemp()
os.chdir( tmp_path )
print tmp_path
print cmd
# starts easywave and counts time differential between start and end
t0 = datetime.datetime.now()
ewrun = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
ewrun.wait()
delta_t = ( datetime.datetime.now() - t0 )
print 'Runtime: %u.%u sec' % (delta_t.seconds, delta_t.microseconds)
cmds[ cmd ] = tmp_path
def compareCmds( cmd ):
path = []
files = []
maxDiff = 0.0
for i in range( 0, 2 ):
path.append( cmds[ cmd[i] ] )
files.append( glob.glob( path[i] + "/*.ssh" ) )
files[i] += glob.glob( path[i] + "/*.sshmax" )
#files[i] += glob.glob( path[i] + "/*.time" )
for f in files[0]:
basef = os.path.basename( f )
fnext = path[1] + '/' + basef
if fnext in files[1]:
#compare.py
compare = subprocess.Popen( sdir + '/compare.py %s %s' % (f, fnext), shell=True, stdout=subprocess.PIPE )
compare.wait()
diff = float( re.search( 'Max difference: (.*)\n', compare.stdout.read() ).group(1) )
maxDiff = max( maxDiff, diff )
if verbose:
print basef + ": %f" % diff
files[1].remove( fnext )
sdir = os.path.dirname(os.path.abspath(sys.argv[0]))
def start(cmd):
tmp_path = tempfile.mkdtemp()
os.chdir(tmp_path)
print(tmp_path)
print(cmd)
# starts easywave and counts time differential between start and end
t0 = datetime.datetime.now()
ewrun = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
ewrun.wait()
delta_t = (datetime.datetime.now() - t0)
print('Runtime: %u.%u sec' % (delta_t.seconds, delta_t.microseconds))
cmds[cmd] = tmp_path
def compareCmds(cmd):
path = []
files = []
maxDiff = 0.0
for i in range(0, 2):
path.append(cmds[cmd[i]])
files.append(glob.glob(path[i] + '/*.ssh'))
files[i] += glob.glob(path[i] + '/*.sshmax')
# files[i] += glob.glob( path[i] + '/*.time' )
for f in files[0]:
basef = os.path.basename(f)
fnext = path[1] + '/' + basef
if fnext in files[1]:
# compare.py
compare = subprocess.Popen(
sdir + '/compare.py %s %s' % (f, fnext),
shell=True,
stdout=subprocess.PIPE
)
compare.wait()
diff = float(
re.search(
'Max difference: (.*)\n',
compare.stdout.read()
).group(1)
)
maxDiff = max(maxDiff, diff)
if verbose:
print(basef + ': %f' % diff)
files[1].remove(fnext)
else:
print('File "' + basef + '" is missing in 1.')
for f in files[1]:
print('File "' + basef + '" is missing in 0.')
if maxDiff > tolerance:
print('\033[91mFailed:\033[0m')
else:
print 'File "' + basef + '" is missing in 1.'
for f in files[1]:
print 'File "' + basef + '" is missing in 0.'
if maxDiff > tolerance:
print "\033[91mFailed:\033[0m",
else:
print "\033[92mSuccessful:\033[0m",
print '%f' % maxDiff
cfg_path = sdir + "/config.cfg"
scs_path = sdir + "/scenarios.cfg"
runs = []
scenarios = []
cmds = {}
tolerance = 0.02
verbose = True
# read config file to get a list of programs to compare
f = open( cfg_path, 'r' )
for line in f:
if line.lstrip()[0] != '#':
progs = line.replace('\n','').replace('@',sdir+'/').split( ';' )
if len( progs ) > 2:
print 'Warning: Can compare only two programs at a time. Ignoring additional entries.'
del progs[2:]
runs.append( progs )
f.close()
# read scenario file to get a list of scenarios used to compare the given programs
f = open( scs_path, 'r' )
for line in f:
if line.lstrip()[0] != '#':
scenarios.append( line.replace('\n','').replace('@',sdir+'/') )
f.close()
# input was read successfully
for run in runs:
for sc in scenarios:
cmd = []
for prog in run:
cmd.append( prog + ' ' + sc )
start( cmd[-1] )
compareCmds( cmd )
\ No newline at end of file
print('\033[92mSuccessful:\033[0m')
print('%f' % maxDiff)
if __name__ == '__main__':
cfg_path = sdir + '/config.cfg'
scs_path = sdir + '/scenarios.cfg'
runs = []
scenarios = []
cmds = {}
tolerance = 0.02
verbose = True
# read config file to get a list of programs to compare
f = open(cfg_path, 'r')
for line in f:
if line.lstrip()[0] != '#':
progs = line.replace('\n', '').replace('@', sdir+'/').split(';')
if len(progs) > 2:
print(
'Warning: Can compare only two programs at a time. ' +
'Ignoring additional entries.'
)
del progs[2:]
runs.append(progs)
f.close()
# read scenario file to get a list of scenarios used to compare the given
# programs
f = open(scs_path, 'r')
for line in f:
if line.lstrip()[0] != '#':
scenarios.append(line.replace('\n', '').replace('@', sdir+'/'))
f.close()
# input was read successfully
for run in runs:
for sc in scenarios:
cmd = []
for prog in run:
cmd.append(prog + ' ' + sc)
start(cmd[-1])
compareCmds(cmd)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment