Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
2b5f167e
Commit
2b5f167e
authored
Jan 06, 2016
by
Robert McGibbon
Browse files
Fix testInstallation, and simplify the error handling
parent
8ae798b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
33 deletions
+21
-33
wrappers/python/simtk/testInstallation.py
wrappers/python/simtk/testInstallation.py
+21
-33
No files found.
wrappers/python/simtk/testInstallation.py
View file @
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\n
Error 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\n
Error 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\n
Error 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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment