FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 4d42c4b5 authored by M.D. Driver's avatar M.D. Driver
Browse files

created test suite, and created script for the reading in of information to a...

created test suite, and created script for the reading in of information to a Datapoints object, with the arrays initialised.
parent 37f66576
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script for the reading in of solvation energies for a given solvent.
@author: mark
"""
import logging
import resultsanalysis.fileparsing.xmlparsing.solvationreader as solvationreader
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
def parse_free_energy_from_file_with_data_arrays(filename):
"""This reads in the information form file to a Dapoints object, and
creates the data arrays.
"""
datapoints = parse_free_energy_from_file(filename)
datapoints.createDataArrays()
return datapoints
def parse_free_energy_from_file(filename):
"""This parses the file and returns a datapoints representation of it.
"""
solvation_energy_dict = parse_free_energy_info(filename)
return create_datapoints_with_values(solvation_energy_dict)
def create_datapoints_with_values(solvation_energy_dict):
"""
"""
return solvationreader.create_datapoints_with_values(solvation_energy_dict)
def parse_free_energy_info(filename):
"""This extracts the slvation information to a dictionary.
"""
return solvationreader.parse_free_energy_info(filename)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script containing tests for the solvationenergyreader module.
@author: mark
"""
import logging
import unittest
import numpy as np
import solventmapcreator.io.solvationenergyreader as solvationenergyreader
from resultsanalysis.dataclasses.datapoints import Datapoints
from resultsanalysis.dataclasses.datapoint import Datapoint
from resultsanalysis.dataclasses.units import Units
from resultsanalysis.dataclasses.value import Value
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
class SolvationEnergyReaderTestCase(unittest.TestCase):
"""Test Case for the solvationenergyreader module.
"""
def setUp(self):
"""Set up for tests
"""
self.solvation_info_dict = solvationenergyreader.parse_free_energy_info("resources/energyvaluestest.xml")
self.expected_datapoints = Datapoints(("ssip",""), (Units.dimensionless, Units.kj_per_mol))
self.expected_datapoints.addDatapoint(Datapoint(Value(-14.100, "ssip",
Units.dimensionless),
Value(-34.8195308084233,
"", Units.kj_per_mol),
"-14.100solute"))
def tearDown(self):
"""Tear down after tests.
"""
del self.solvation_info_dict
del self.expected_datapoints
def test_parse_free_energy_from_file_with_data_arrays(self):
"""Test to see if
"""
actual_datapoints = solvationenergyreader.parse_free_energy_from_file_with_data_arrays("resources/energyvaluestest.xml")
self.assertEqual(self.expected_datapoints, actual_datapoints)
np.testing.assert_array_almost_equal(np.array([[-14.100]]),
actual_datapoints.x_values)
np.testing.assert_array_almost_equal(np.array([[-34.8195308084233]]),
actual_datapoints.y_values)
def test_parse_free_energy_from_file(self):
"""Test to see if expected Datapoints object is created from reading of
a file.
"""
actual_datapoints = solvationenergyreader.parse_free_energy_from_file("resources/energyvaluestest.xml")
self.assertEqual(self.expected_datapoints, actual_datapoints)
def test_create_datapoints_with_values(self):
"""Test to see if expected Datapoints object is created.
"""
actual_datapoints = solvationenergyreader.create_datapoints_with_values(self.solvation_info_dict)
self.assertEqual(self.expected_datapoints, actual_datapoints)
def test_parse_free_energy_info(self):
"""Test to see if expected free energy values are extracted from file.
"""
expected_dict = {"total_energy": -34.8195308084233, "value_type":"MOLEFRACTION",
"to_solvent_id":"water", "from_solvent_id":"",
"stdinchikey":"-14.100solute"}
actual_dict_dict = solvationenergyreader.parse_free_energy_info("resources/energyvaluestest.xml")
self.assertListEqual(["-14.100solute"], sorted(actual_dict_dict.keys()))
actual_dict = actual_dict_dict["-14.100solute"]
self.assertListEqual(sorted(expected_dict.keys()), sorted(actual_dict.keys()))
for key, value in expected_dict.items():
if key == "total_energy":
self.assertAlmostEqual(value, actual_dict[key])
else:
self.assertEqual(value, actual_dict[key])
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script for running the tests.
@author: mark
"""
import logging
import unittest
from solventmapcreator.test.iotest.solvationenergyreadertest import SolvationEnergyReaderTestCase
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
IO_TEST_CASES = [SolvationEnergyReaderTestCase]
def test_suite():
"""Function creates a test suite and then loads all the tests from the
different test cases.
"""
LOGGER.info("setting up loader and test suite")
loader = unittest.TestLoader()
suite = unittest.TestSuite()
for test_case in IO_TEST_CASES:
LOGGER.debug("Adding %s", test_case)
suite.addTests(loader.loadTestsFromTestCase(test_case))
return suite
if __name__ == '__main__':
LOGGER.info("calling test suite method")
SUITE = test_suite()
LOGGER.info("running test suite")
unittest.TextTestRunner(verbosity=2).run(SUITE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment