diff --git a/rmgpy/rmg/reactors.py b/rmgpy/rmg/reactors.py index 5964eea3d4e..bc855309f2a 100644 --- a/rmgpy/rmg/reactors.py +++ b/rmgpy/rmg/reactors.py @@ -35,7 +35,7 @@ import sys import logging import itertools - +import warnings if __debug__: try: from os.path import dirname, abspath, join, exists @@ -46,14 +46,17 @@ from diffeqpy import de from julia import Main except: - pass + raise RuntimeError("Unable to load system Julia image during debug run.") else: try: from pyrms import rms from diffeqpy import de from julia import Main except: - pass + if 'nose' not in sys.modules.keys(): + raise RuntimeError("Import of Julia dependencies failed. Ensure the environment is correctly built and Julia dependencies have been linked properly.") + else: + warnings.warn("Failed Julia imports ignored, assuming execution in nosetests", RuntimeWarning) from rmgpy.species import Species from rmgpy.reaction import Reaction diff --git a/rmgpy/rmg/reactorsTest.py b/rmgpy/rmg/reactorsTest.py new file mode 100644 index 00000000000..43cc91960fd --- /dev/null +++ b/rmgpy/rmg/reactorsTest.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +############################################################################### +# # +# RMG - Reaction Mechanism Generator # +# # +# Copyright (c) 2002-2021 Prof. William H. Green (whgreen@mit.edu), # +# Prof. Richard H. West (r.west@neu.edu) and the RMG Team (rmg_dev@mit.edu) # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the 'Software'), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, sublicense, # +# and/or sell copies of the Software, and to permit persons to whom the # +# Software is furnished to do so, subject to the following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +############################################################################### + +import unittest +import sys + +from unittest.mock import MagicMock, patch + +################################################### + + +class TestReactors(unittest.TestCase): + + def test_missing_julia_warning(self): + """ + Ensure that a missing Julia install will raise an error to the user. + """ + # make a MagicMock that replaces pyrms and makes it look like it is missing + rmsModuleMock = MagicMock() + rmsModuleMock.side_effect = ModuleNotFoundError + with patch.dict('sys.modules', pyrms=rmsModuleMock): + # RuntimeError is not raised when running test - trick it into thinking we are not in a test + del sys.modules['nose'] + # use a second context to check for the error on import + with self.assertRaises(RuntimeError): + import rmgpy.rmg.reactors + + +if __name__ == '__main__': + unittest.main()