Skip to content

Commit

Permalink
Add unittest for the RMG SA Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
kspieks committed Apr 18, 2020
1 parent 3f7162b commit 969ae69
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/rmg_saTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python3
# encoding: utf-8

###############################################################################
# #
# RMG - Reaction Mechanism Generator #
# #
# Copyright (c) 2002-2019 Prof. William H. Green ([email protected]), #
# Prof. Richard H. West ([email protected]) and the RMG Team ([email protected]) #
# #
# 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. #
# #
###############################################################################

"""
This module contains unit tests of the :mod:`tandem.sa.rmg_sa` module.
"""

import os
import shutil
import unittest

from tandem.logger import initialize_tandem_log
from tandem.sa.rmg_sa import RMGSA

################################################################################

class RMGSATest(unittest.TestCase):
"""
Contains unit tests for the RMGSA module, used for performing sensitivity analysis using RMG.
"""
@classmethod
def setUpClass(cls):
"""
A method that is run before all unit tests in this class.
"""
# use data from the superminimal example
cls.observable_list = [{'label': 'H2O2', 'smiles': 'OO'}, {'label': 'H', 'smiles': '[H]'}]
cls.run_directory = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'rmg_sa_test', 'iteration_0')
cls.input_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'rmg_sa_test', 'input.py')
cls.threshold = 0.001
cls.verbose = False
cls.output_directory = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'rmg_sa_test')

initialize_tandem_log(output_directory=cls.output_directory, verbose=cls.verbose)

def test_run_sa(self):
RMGSA_adapter = RMGSA(observable_list=self.observable_list,
run_directory=self.run_directory,
input_file=self.input_file,
threshold=self.threshold,
verbose=self.verbose,
)

sa_success = RMGSA_adapter.run_sa()
self.assertTrue(sa_success)

@classmethod
def tearDownClass(cls):
"""
A method that is run after all unit tests in this class.
"""
log_file = os.path.join(cls.output_directory, 't3.log')
if os.path.isfile(log_file):
os.remove(log_file)

sa_dir = os.path.join(cls.run_directory, 'sa')
if os.path.isdir(sa_dir):
shutil.rmtree(sa_dir)



################################################################################


if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))

0 comments on commit 969ae69

Please sign in to comment.