Finishes DiceInterface Refactoring and Continues Tests Implementation

This commit is contained in:
2023-04-24 12:15:51 -03:00
parent b869ee74fb
commit 9202331852
19 changed files with 629 additions and 190 deletions

View File

@@ -8,10 +8,9 @@ class TestDiceDto(unittest.TestCase):
dice_dto = DiceDTO(
ljname='test',
outname='test',
ncores=1,
dens=1.0,
nmol=[1],
nstep=[1],
nstep=[1, 1],
)
self.assertIsInstance(dice_dto, DiceDTO)
@@ -21,10 +20,9 @@ class TestDiceDto(unittest.TestCase):
DiceDTO(
ljname=None,
outname='test',
ncores=1,
dens=1.0,
nmol=[1],
nstep=[1],
nstep=[1, 1],
)
self.assertEqual(ex.exception, "Error: 'ljname' keyword not specified in config file")
@@ -33,10 +31,9 @@ class TestDiceDto(unittest.TestCase):
DiceDTO(
ljname='test',
outname=None,
ncores=1,
dens=1.0,
nmol=[1],
nstep=[1],
nstep=[1, 1],
)
self.assertEqual(ex.exception, "Error: 'outname' keyword not specified in config file")
@@ -45,10 +42,9 @@ class TestDiceDto(unittest.TestCase):
DiceDTO(
ljname='test',
outname='test',
ncores=1,
dens=None,
nmol=[1],
nstep=[1],
nstep=[1, 1],
)
self.assertEqual(ex.exception, "Error: 'dens' keyword not specified in config file")
@@ -57,10 +53,9 @@ class TestDiceDto(unittest.TestCase):
DiceDTO(
ljname='test',
outname='test',
ncores=1,
dens=1.0,
nmol=0,
nstep=[1],
nstep=[1, 1],
)
self.assertEqual(ex.exception, "Error: 'nmol' keyword not defined appropriately in config file")
@@ -69,7 +64,6 @@ class TestDiceDto(unittest.TestCase):
DiceDTO(
ljname='test',
outname='test',
ncores=1,
dens=1.0,
nmol=[1],
nstep=0,
@@ -80,10 +74,9 @@ class TestDiceDto(unittest.TestCase):
dice_dto = DiceDTO.from_dict({
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
})
self.assertIsInstance(dice_dto, DiceDTO)

View File

@@ -0,0 +1,45 @@
from diceplayer.shared.config.gaussian_dto import GaussianDTO
import unittest
class TestGaussianDTO(unittest.TestCase):
def test_class_instantiation(self):
gaussian_dto = GaussianDTO(
level='test',
qmprog='g16',
keywords='test',
)
self.assertIsInstance(gaussian_dto, GaussianDTO)
def test_is_valid_qmprog(self):
with self.assertRaises(ValueError):
gaussian_dto = GaussianDTO(
level='test',
qmprog='test',
keywords='test',
)
def test_is_valid_level(self):
with self.assertRaises(ValueError):
gaussian_dto = GaussianDTO(
level=None,
qmprog='g16',
keywords='test',
)
def test_from_dict(self):
gaussian_dto = GaussianDTO.from_dict(
{
'level': 'test',
'qmprog': 'g16',
'keywords': 'test',
}
)
self.assertIsInstance(gaussian_dto, GaussianDTO)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,28 @@
from diceplayer.shared.config.player_dto import PlayerDTO
import unittest
class TestPlayerDTO(unittest.TestCase):
def test_class_instantiation(self):
player_dto = PlayerDTO(opt=True, maxcyc=100, nprocs=4)
self.assertIsInstance(player_dto, PlayerDTO)
def test_min_altsteps(self):
player_dto = PlayerDTO(opt=True, maxcyc=100, nprocs=4, altsteps=100)
self.assertEqual(player_dto.altsteps, 20000)
def test_from_dict(self):
player_dto = PlayerDTO.from_dict({
'opt': True,
'maxcyc': 100,
'nprocs': 4
})
self.assertIsInstance(player_dto, PlayerDTO)
if __name__ == '__main__':
unittest.main()

View File

@@ -26,25 +26,6 @@ class TestSystem(unittest.TestCase):
system.add_type('test', Molecule('test'))
self.assertEqual(ex.exception, 'Error: nmols is not an integer')
def test_center_of_mass_distance(self):
system = System()
a = Molecule('test')
a.add_atom(
Atom(lbl=0, na=1, rx=0, ry=0, rz=0, chg=0, eps=0, sig=0)
)
system.add_type(1, a)
b = Molecule('test')
b.add_atom(
Atom(lbl=0, na=1, rx=0, ry=0, rz=0, chg=0, eps=0, sig=0)
)
system.add_type(1, b)
self.assertIsInstance(system.center_of_mass_distance(0, 1), float)
if __name__ == '__main__':
unittest.main()

View File

@@ -1,4 +1,5 @@
from diceplayer.shared.external.dice import Dice
from diceplayer.shared.config.step_dto import StepDTO
from diceplayer.shared.interface.dice_interface import DiceInterface
from unittest import mock
import unittest
@@ -6,28 +7,28 @@ import unittest
class TestDice(unittest.TestCase):
def test_class_instantiation(self):
dice = Dice(
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
}
)
self.assertIsInstance(dice, Dice)
self.assertIsInstance(dice, DiceInterface)
def test_configure(self):
dice = Dice(
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
}
)
@@ -38,14 +39,14 @@ class TestDice(unittest.TestCase):
self.assertTrue(hasattr(dice, 'step'))
def test_reset(self):
dice = Dice(
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
}
)
@@ -60,30 +61,41 @@ class TestDice(unittest.TestCase):
@mock.patch('diceplayer.shared.external.dice.connection')
@mock.patch('diceplayer.shared.external.dice.Process')
def test_start(self, mock_process, mock_connection):
dice = Dice(
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice.start(1)
self.assertTrue(mock_process.called)
self.assertTrue(mock_connection.wait.called)
def test_simulation_process_raises_exception(self):
dice = Dice(
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
}
)
@@ -94,14 +106,14 @@ class TestDice(unittest.TestCase):
@mock.patch('diceplayer.shared.external.dice.Dice._make_dice_inputs')
@mock.patch('diceplayer.shared.external.dice.Dice._run_dice')
def test_simulation_process(self, mock_run_dice, mock_make_dice_inputs, mock_make_proc_dir):
dice = Dice(
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1],
'nstep': [1, 1],
}
)
@@ -111,6 +123,82 @@ class TestDice(unittest.TestCase):
self.assertTrue(dice._make_dice_inputs.called)
self.assertTrue(dice._run_dice.called)
@mock.patch('diceplayer.shared.external.dice.Path.mkdir')
@mock.patch('diceplayer.shared.external.dice.Path.exists')
def test_make_proc_dir_if_simdir_exists(self, mock_path_exists, mock_path_mkdir):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
mock_path_exists.return_value = False
dice._make_proc_dir(1, 1)
self.assertEqual(mock_path_mkdir.call_count, 2)
@mock.patch('diceplayer.shared.external.dice.Path.mkdir')
@mock.patch('diceplayer.shared.external.dice.Path.exists')
def test_make_proc_dir_if_simdir_doesnt_exists(self, mock_path_exists, mock_path_mkdir):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
mock_path_exists.return_value = False
dice._make_proc_dir(1, 1)
self.assertEqual(mock_path_mkdir.call_count, 2)
def test_make_dice_seed(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
seed = dice._make_dice_seed()
self.assertIsInstance(seed, int)
if __name__ == '__main__':
unittest.main()