Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helpful error message for failed julia dependency imports #2359

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions rmgpy/rmg/reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import sys
import logging
import itertools

import warnings
if __debug__:
try:
from os.path import dirname, abspath, join, exists
Expand All @@ -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
Expand Down
56 changes: 56 additions & 0 deletions rmgpy/rmg/reactorsTest.py
Original file line number Diff line number Diff line change
@@ -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()