add test framework

- add the ability to run tests from the top level directory via
  'python setup.py test'
- translate runtest.py into a test that runs under this framework
- add a __main__ section to Tests/runtest.py and change its indent to 4
  spaces; make no other changes to this script
This commit is contained in:
Mike Beachy
2014-02-22 17:33:18 -05:00
parent edd25afad3
commit 61bb875248
4 changed files with 99 additions and 34 deletions

0
Tests/__init__.py Normal file
View File

68
Tests/pkacalc_test.py Normal file
View File

@@ -0,0 +1,68 @@
import os
import re
from subprocess import call
import sys
import unittest
# Setting this up as a direct translation of the original runtest.py script
# that will be run as part of 'python setup.py test'. This takes on the
# order of 30s to run.
class SystemTest(unittest.TestCase):
"""
Run the program and compare against reference results.
"""
def test_pka_calc(self):
pdbs = ['1FTJ-Chain-A',
'1HPX',
'4DFR']
test_dir = os.path.dirname(__file__)
base_dir = os.path.dirname(test_dir)
executable = os.path.join(base_dir, "scripts", "propka31.py")
env = { "PYTHONPATH" : base_dir }
for pdb in pdbs:
input_filename = os.path.join(test_dir, "pdb", pdb + ".pdb")
output_filename = os.path.join(test_dir, pdb + ".out")
output_file = open(output_filename, "w")
call([sys.executable, executable, input_filename],
stdout=output_file, env=env)
output_file.close()
# Check pka predictions.
ref = open(os.path.join(test_dir, "results", pdb + ".dat"))
output = open(output_filename)
atpka = False
errors = []
for line in output:
if not atpka:
# Start testing pka values.
if "model-pKa" in line:
atpka = True
continue
m = re.search('([0-9]+\.[0-9]+)', line)
if not m:
break
expected_value = float(ref.readline())
value = float(m.group(0))
if(value != expected_value):
identity = line[:m.start()].strip()
errors.append("%12s %8.2f %8.2f" %
(identity, expected_value, value))
ref.close()
output.close()
if errors:
error_header = " Group Expected Calculated\n"
self.Fail("Unexpected pKa values:\n" + error_header +
"\n".join(errors))

View File

@@ -9,6 +9,7 @@ from subprocess import call
import os, re
import sys
if __name__ == "__main__":
pdbs = ['1FTJ-Chain-A',
'1HPX',
'4DFR']
@@ -44,8 +45,3 @@ for pdb in pdbs:
print(line)
print(" "+"should be: "+str(r))

View File

@@ -48,4 +48,5 @@ using the tutorial http://propka.ki.ku.dk/~luca/wiki/index.php/PROPKA_3.1_Tutori
],
},
zip_safe=True,
test_suite="Tests",
)