2014-04-07 16:56:29 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
import sys,os
|
2014-04-07 16:56:29 +02:00
|
|
|
|
|
|
|
def run_test(test_name,inp):
|
|
|
|
command = './'+test_name+" ${QPACKAGE_ROOT}/data/inputs/"+inp
|
|
|
|
result = subprocess.check_output(command, shell=True)
|
|
|
|
return result
|
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
if __name__ == '__main__':
|
2014-04-07 16:56:29 +02:00
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
import unittest
|
|
|
|
import subprocess
|
|
|
|
from math import *
|
|
|
|
|
|
|
|
from multiprocessing import Pool
|
|
|
|
env = os.environ
|
|
|
|
|
|
|
|
verbosity = 1
|
|
|
|
try:
|
|
|
|
nproc = int(subprocess.check_output("cat /proc/cpuinfo | grep processor | wc -l", shell=True))
|
|
|
|
except:
|
|
|
|
nproc=4
|
|
|
|
|
|
|
|
testfiles = []
|
|
|
|
for f in os.listdir(os.getcwd()):
|
|
|
|
if f.endswith('.irp.f'):
|
|
|
|
testfiles.append(f.replace('.irp.f',''))
|
|
|
|
|
|
|
|
# start worker processes
|
|
|
|
pool = Pool(processes=nproc)
|
|
|
|
|
|
|
|
template = """
|
2014-04-07 16:56:29 +02:00
|
|
|
class $test(unittest.TestCase):
|
|
|
|
|
2014-04-07 20:01:30 +02:00
|
|
|
default_precision = 1.e-10
|
|
|
|
|
2014-04-07 16:56:29 +02:00
|
|
|
execfile('$test.ref')
|
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
name = '$test'
|
|
|
|
tasks = {}
|
|
|
|
|
2014-04-07 16:56:29 +02:00
|
|
|
def setUp(self):
|
2014-04-07 21:13:24 +02:00
|
|
|
for d in self.data.keys():
|
|
|
|
if d not in self.tasks:
|
|
|
|
self.tasks[d] = pool.apply_async(run_test, [self.name, d])
|
2014-04-07 16:56:29 +02:00
|
|
|
|
|
|
|
def _test_input(self,inp):
|
2014-04-07 21:13:24 +02:00
|
|
|
output = self.tasks[inp].get()
|
2014-04-07 16:56:29 +02:00
|
|
|
for line in output.splitlines():
|
|
|
|
buffer = line.split(':')
|
|
|
|
if len(buffer) == 1:
|
|
|
|
continue
|
|
|
|
l,r = buffer
|
|
|
|
l,r = l.strip(), eval(r)
|
2014-04-07 20:01:30 +02:00
|
|
|
if 'precision' in self.__dict__:
|
|
|
|
precision = self.precision[l]
|
|
|
|
else:
|
|
|
|
precision = self.default_precision
|
2014-04-07 16:56:29 +02:00
|
|
|
if type(r) == float:
|
|
|
|
self.assertAlmostEqual(self.data[inp][l], r,
|
2014-04-07 20:01:30 +02:00
|
|
|
places=abs(int(log10(precision*max(abs(self.data[inp][l]),1.e-12)))), msg=None)
|
2014-04-07 16:56:29 +02:00
|
|
|
else:
|
|
|
|
self.assertEqual(self.data[inp][l], r, msg=None)
|
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
|
2014-04-07 16:56:29 +02:00
|
|
|
t = "def test_$k(self): self._test_input('$i')"
|
|
|
|
for i in data.keys():
|
|
|
|
k = i
|
|
|
|
k = k.replace('.ezfio','')
|
|
|
|
k = k.replace('-','_m_')
|
|
|
|
k = k.replace('+','_p_')
|
|
|
|
exec t.replace('$i',i).replace('$k',k) in locals()
|
|
|
|
"""
|
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
for test in testfiles:
|
|
|
|
exec template.replace('$test',test) in locals()
|
2014-04-07 16:56:29 +02:00
|
|
|
|
2014-04-07 21:13:24 +02:00
|
|
|
unittest.main(verbosity=verbosity)
|