"devtools/packaging/scripts/vscode:/vscode.git/clone" did not exist on "02e7a5d642637f16eaeb64b1af4e9c2d24350dcb"
Commit 59e45c58 authored by peastman's avatar peastman
Browse files

Merge pull request #1326 from rmcgibbo/fix-testInstallation

Fix testInstallation, and simplify the error handling
parents 8ae798b0 2b5f167e
from __future__ import print_function from __future__ import print_function
from __future__ import absolute_import from __future__ import absolute_import
from functools import wraps
import os import os
import sys import sys
# First make sure OpenMM is installed. # First make sure OpenMM is installed.
class TestingError(Exception):
"""
An error is encountered when
"""
pass
try: try:
from simtk.openmm.app import * from simtk.openmm.app import *
from simtk.openmm import * from simtk.openmm import *
...@@ -21,24 +14,7 @@ except ImportError as err: ...@@ -21,24 +14,7 @@ except ImportError as err:
else: else:
simtk_import_failed = False simtk_import_failed = False
def error_converter(error_type):
""" Converts all exceptions to the given Exception type """
def wrapper(func):
@wraps(func)
def new_func(*args, **kwargs):
try:
func(*args, **kwargs)
except error_type:
# Pass the existing error through
raise
except BaseException as err:
raise TestingError('Problem with OpenMM installation '
'encountered. OpenMM will not work until the problem '
'has been fixed.\n\nError message: %s' % err.message)
return new_func
return wrapper
@error_converter(TestingError)
def run_tests(): def run_tests():
""" """
Runs a set of tests to determine which platforms are available and tests the Runs a set of tests to determine which platforms are available and tests the
...@@ -51,10 +27,7 @@ def run_tests(): ...@@ -51,10 +27,7 @@ def run_tests():
between them for a test system. If a problem is detected, TestingError is between them for a test system. If a problem is detected, TestingError is
raised. raised.
""" """
if simtk_import_failed:
raise TestingError('Failed to import OpenMM packages; OpenMM will not work.\n'
'Make sure OpenMM is installed and the library path is set correctly.'
'\n\nError message: %s' % simtk_import_error)
# Create a System for the tests. # Create a System for the tests.
data_dir = os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'openmm', 'app', 'data') data_dir = os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'openmm', 'app', 'data')
pdb = PDBFile(os.path.join(data_dir, 'test.pdb')) pdb = PDBFile(os.path.join(data_dir, 'test.pdb'))
...@@ -66,7 +39,7 @@ def run_tests(): ...@@ -66,7 +39,7 @@ def run_tests():
numPlatforms = Platform.getNumPlatforms() numPlatforms = Platform.getNumPlatforms()
print("There are", numPlatforms, "Platforms available:") print("There are", numPlatforms, "Platforms available:")
print() print()
forces = [None]*numPlatforms forces = [None] * numPlatforms
platformErrors = {} platformErrors = {}
for i in range(numPlatforms): for i in range(numPlatforms):
platform = Platform.getPlatform(i) platform = Platform.getPlatform(i)
...@@ -106,10 +79,25 @@ def run_tests(): ...@@ -106,10 +79,25 @@ def run_tests():
Platform.getPlatform(i).getName(), Platform.getPlatform(i).getName(),
sorted(errors)[len(errors)//2])) sorted(errors)[len(errors)//2]))
if __name__ == '__main__':
def main():
if simtk_import_failed:
print('Failed to import OpenMM packages; OpenMM will not work.\n'
'Make sure OpenMM is installed and the library path is set correctly.'
'\n\nError message: %s' % simtk_import_error,
file=sys.stderr)
sys.exit(1)
try: try:
run_tests() run_tests()
except TestingError as err: except Exception as err:
print(err.message) print('Problem with OpenMM installation '
'encountered. OpenMM will not work until the problem '
'has been fixed.\n\n',
file=sys.stderr)
print('Error message: %s' % str(err), file=sys.stderr)
sys.exit(1) sys.exit(1)
if __name__ == '__main__':
main()
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