Skip to content

Commit

Permalink
Added TestCanthermSpecies to commonTest
Browse files Browse the repository at this point in the history
  • Loading branch information
alongd committed Jul 5, 2018
1 parent bf2f00d commit b132315
Showing 1 changed file with 67 additions and 6 deletions.
73 changes: 67 additions & 6 deletions rmgpy/cantherm/commonTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
import unittest
import os

import shutil
import numpy

import rmgpy
from rmgpy.cantherm import CanTherm, input
from rmgpy.cantherm import CanTherm, CanthermSpecies, input
from rmgpy.cantherm.input import jobList
import rmgpy.constants as constants
from rmgpy.cantherm.statmech import InputError
from rmgpy.quantity import ScalarQuantity
from rmgpy.thermo import NASA

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

Expand All @@ -60,7 +63,7 @@ def test_check_conformer_energy(self):
self.assertAlmostEqual(Vdiff / 2.7805169838282797, 1, 5)


class testCanthermJob(unittest.TestCase):
class TestCanthermJob(unittest.TestCase):
"""
Contains unit tests of the Cantherm module and its interactions with other RMG modules.
"""
Expand Down Expand Up @@ -204,7 +207,7 @@ def testTunneling(self):
self.assertEqual(self.kineticsjob.reaction.transitionState.tunneling, None, msg=None)


class testCanthermInput(unittest.TestCase):
class TestCanthermInput(unittest.TestCase):
"""
Contains unit tests for loading and processing Cantherm input files.
"""
Expand Down Expand Up @@ -270,8 +273,9 @@ def testTransitionStateStatmech(self):
job.includeHinderedRotors = self.useHinderedRotors
job.applyBondEnergyCorrections = self.useBondCorrections
job.load()

class testStatmech(unittest.TestCase):


class TestStatmech(unittest.TestCase):
"""
Contains unit tests of statmech.py
"""
Expand All @@ -284,6 +288,63 @@ def testGaussianLogFileError(self):
job = jobList[-1]
self.assertTrue(isinstance(job, rmgpy.cantherm.statmech.StatMechJob))
self.assertRaises(InputError,job.load())



class TestCanthermSpecies(unittest.TestCase):
"""
Contains YAML dump and load unit tests for :class:CanthermSpecies
"""

@classmethod
def setUpClass(self):
"""
A method that is run before all unit tests in this class.
"""
self.cantherm = CanTherm()
path = os.path.join(os.path.dirname(os.path.dirname(rmgpy.__file__)),
'examples', 'cantherm', 'species', 'C2H6')
self.legacy_input_path = os.path.join(path, 'input.py')
self.yaml_input_path = os.path.join(path, 'input_load_from_YAML.py')
self.yaml_path = os.path.join(path, 'SpeciesDatabase', 'C2H6.yml')
self.output_file = os.path.join(path, 'output.py')
self.path_to_remove = os.path.join(path, 'SpeciesDatabase', '')

def test_dump_yaml(self):
"""
Test properly dumping the CanthermSpecies object and respective sub-objects
"""
jobList = self.cantherm.loadInputFile(self.legacy_input_path)
for job in jobList:
job.execute(outputFile=self.output_file)
self.assertTrue(os.path.exists(self.yaml_path))

def test_load_yaml(self):
"""
Test properly loading the CanthermSpecies object and respective sub-objects
(note: a different input file is loaded here)
"""
jobList = self.cantherm.loadInputFile(self.yaml_input_path)
for job in jobList:
job.execute(outputFile=self.output_file)
can_spc = jobList[0].cantherm_species
self.assertIsInstance(can_spc, CanthermSpecies) # checks make_object
self.assertIsInstance(can_spc.molecular_weight, ScalarQuantity) # checks make_object
self.assertIsInstance(can_spc.thermo, NASA) # checks make_object
self.assertNotEqual(can_spc.author, '')
self.assertEqual(can_spc.InChI, 'InChI=1S/C2H6/c1-2/h1-2H3')
self.assertEqual(can_spc.SMILES, 'CC')
self.assertTrue('8 H u0 p0 c0 {2,S}' in can_spc.adjacency_list)
self.assertEqual(can_spc.label, 'C2H6')
self.assertEqual(can_spc.frequency_scale_factor, 0.99) # checks float conversion
self.assertFalse(can_spc.use_bond_corrections)
self.assertAlmostEqual(can_spc.conformer.modes[2].frequencies.value_si[0], 818.91718, 4) # HarmonicOscillator

@classmethod
def tearDownClass(self):
"""
A method that is run after all unit tests in this class.
"""
shutil.rmtree(self.path_to_remove)

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

0 comments on commit b132315

Please sign in to comment.