Adds Formatter to Project
This commit is contained in:
@@ -6,8 +6,8 @@ import unittest
|
||||
class TestDiceDto(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
dice_dto = DiceConfig(
|
||||
ljname='test',
|
||||
outname='test',
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
@@ -19,64 +19,78 @@ class TestDiceDto(unittest.TestCase):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname=None,
|
||||
outname='test',
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(ex.exception, "Error: 'ljname' keyword not specified in config file")
|
||||
self.assertEqual(
|
||||
ex.exception, "Error: 'ljname' keyword not specified in config file"
|
||||
)
|
||||
|
||||
def test_validate_outname(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname='test',
|
||||
ljname="test",
|
||||
outname=None,
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(ex.exception, "Error: 'outname' keyword not specified in config file")
|
||||
self.assertEqual(
|
||||
ex.exception, "Error: 'outname' keyword not specified in config file"
|
||||
)
|
||||
|
||||
def test_validate_dens(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname='test',
|
||||
outname='test',
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=None,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(ex.exception, "Error: 'dens' keyword not specified in config file")
|
||||
self.assertEqual(
|
||||
ex.exception, "Error: 'dens' keyword not specified in config file"
|
||||
)
|
||||
|
||||
def test_validate_nmol(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname='test',
|
||||
outname='test',
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=0,
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(ex.exception, "Error: 'nmol' keyword not defined appropriately in config file")
|
||||
self.assertEqual(
|
||||
ex.exception,
|
||||
"Error: 'nmol' keyword not defined appropriately in config file",
|
||||
)
|
||||
|
||||
def test_validate_nstep(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname='test',
|
||||
outname='test',
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=0,
|
||||
)
|
||||
self.assertEqual(ex.exception, "Error: 'nstep' keyword not defined appropriately in config file")
|
||||
self.assertEqual(
|
||||
ex.exception,
|
||||
"Error: 'nstep' keyword not defined appropriately in config file",
|
||||
)
|
||||
|
||||
def test_from_dict(self):
|
||||
dice_dto = DiceConfig.from_dict({
|
||||
'ljname': 'test',
|
||||
'outname': 'test',
|
||||
'dens': 1.0,
|
||||
'nmol': [1],
|
||||
'nstep': [1, 1],
|
||||
})
|
||||
dice_dto = DiceConfig.from_dict(
|
||||
{
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
"nmol": [1],
|
||||
"nstep": [1, 1],
|
||||
}
|
||||
)
|
||||
|
||||
self.assertIsInstance(dice_dto, DiceConfig)
|
||||
self.assertIsInstance(dice_dto, DiceConfig)
|
||||
|
||||
@@ -6,9 +6,9 @@ import unittest
|
||||
class TestGaussianDTO(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
gaussian_dto = GaussianDTO(
|
||||
level='test',
|
||||
qmprog='g16',
|
||||
keywords='test',
|
||||
level="test",
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
self.assertIsInstance(gaussian_dto, GaussianDTO)
|
||||
@@ -16,30 +16,30 @@ class TestGaussianDTO(unittest.TestCase):
|
||||
def test_is_valid_qmprog(self):
|
||||
with self.assertRaises(ValueError):
|
||||
gaussian_dto = GaussianDTO(
|
||||
level='test',
|
||||
qmprog='test',
|
||||
keywords='test',
|
||||
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',
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
def test_from_dict(self):
|
||||
gaussian_dto = GaussianDTO.from_dict(
|
||||
{
|
||||
'level': 'test',
|
||||
'qmprog': 'g16',
|
||||
'keywords': 'test',
|
||||
"level": "test",
|
||||
"qmprog": "g16",
|
||||
"keywords": "test",
|
||||
}
|
||||
)
|
||||
|
||||
self.assertIsInstance(gaussian_dto, GaussianDTO)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
from diceplayer.shared.config.dice_config import DiceConfig
|
||||
from diceplayer.shared.config.gaussian_config import GaussianDTO
|
||||
from diceplayer.shared.config.player_config import PlayerConfig
|
||||
from diceplayer.shared.config.dice_config import DiceConfig
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
def get_config_dict():
|
||||
return {
|
||||
'opt': True,
|
||||
'mem': 12,
|
||||
'maxcyc': 100,
|
||||
'nprocs': 4,
|
||||
'ncores': 4,
|
||||
'dice': {
|
||||
'ljname': 'test',
|
||||
'outname': 'test',
|
||||
'dens': 1.0,
|
||||
'nmol': [1],
|
||||
'nstep': [1, 1],
|
||||
"opt": True,
|
||||
"mem": 12,
|
||||
"maxcyc": 100,
|
||||
"nprocs": 4,
|
||||
"ncores": 4,
|
||||
"dice": {
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
"nmol": [1],
|
||||
"nstep": [1, 1],
|
||||
},
|
||||
"gaussian": {
|
||||
"level": "test",
|
||||
"qmprog": "g16",
|
||||
"keywords": "test",
|
||||
},
|
||||
'gaussian': {
|
||||
'level': 'test',
|
||||
'qmprog': 'g16',
|
||||
'keywords': 'test',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestPlayerDTO(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.dice_dto = DiceConfig(
|
||||
ljname='test',
|
||||
outname='test',
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.gaussian_dto = GaussianDTO(
|
||||
level='test',
|
||||
qmprog='g16',
|
||||
keywords='test',
|
||||
level="test",
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
def test_class_instantiation(self):
|
||||
@@ -50,7 +50,7 @@ class TestPlayerDTO(unittest.TestCase):
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
dice=self.dice_dto,
|
||||
gaussian=self.gaussian_dto
|
||||
gaussian=self.gaussian_dto,
|
||||
)
|
||||
|
||||
self.assertIsInstance(player_dto, PlayerConfig)
|
||||
@@ -66,20 +66,18 @@ class TestPlayerDTO(unittest.TestCase):
|
||||
ncores=4,
|
||||
altsteps=100,
|
||||
dice=self.dice_dto,
|
||||
gaussian=self.gaussian_dto
|
||||
gaussian=self.gaussian_dto,
|
||||
)
|
||||
|
||||
self.assertEqual(player_dto.altsteps, 20000)
|
||||
|
||||
def test_from_dict(self):
|
||||
player_dto = PlayerConfig.from_dict(
|
||||
get_config_dict()
|
||||
)
|
||||
player_dto = PlayerConfig.from_dict(get_config_dict())
|
||||
|
||||
self.assertIsInstance(player_dto, PlayerConfig)
|
||||
self.assertIsInstance(player_dto.dice, DiceConfig)
|
||||
self.assertIsInstance(player_dto.gaussian, GaussianDTO)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -16,4 +16,4 @@ class TestAtom(unittest.TestCase):
|
||||
sig=1.0,
|
||||
)
|
||||
|
||||
self.assertIsInstance(atom, Atom)
|
||||
self.assertIsInstance(atom, Atom)
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import numpy as np
|
||||
|
||||
from diceplayer.shared.environment.molecule import Molecule
|
||||
from diceplayer.shared.environment.atom import Atom
|
||||
from diceplayer.shared.environment.molecule import Molecule
|
||||
|
||||
import numpy as np
|
||||
import numpy.testing as npt
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestMolecule(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
self.assertIsInstance(mol, Molecule)
|
||||
|
||||
def test_add_atom(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
|
||||
self.assertEqual(len(mol.atom), 1)
|
||||
npt.assert_equal(mol.com, [1., 1., 1.])
|
||||
npt.assert_equal(mol.com, [1.0, 1.0, 1.0])
|
||||
|
||||
def test_center_of_mass(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -33,10 +33,10 @@ class TestMolecule(unittest.TestCase):
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
|
||||
npt.assert_equal(mol.com, [.5, .5, .5])
|
||||
npt.assert_equal(mol.com, [0.5, 0.5, 0.5])
|
||||
|
||||
def test_center_of_mass_to_origin(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -47,7 +47,7 @@ class TestMolecule(unittest.TestCase):
|
||||
npt.assert_equal(mol.com, [0, 0, 0])
|
||||
|
||||
def test_charges_and_dipole(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -57,13 +57,10 @@ class TestMolecule(unittest.TestCase):
|
||||
|
||||
expected_charge_dipole_array = [1.0, 0.0, 0.0, 0.0, 0.0]
|
||||
|
||||
npt.assert_equal(
|
||||
actual_charge_dipole_array,
|
||||
expected_charge_dipole_array
|
||||
)
|
||||
npt.assert_equal(actual_charge_dipole_array, expected_charge_dipole_array)
|
||||
|
||||
def test_distances_between_atoms(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -76,12 +73,11 @@ class TestMolecule(unittest.TestCase):
|
||||
actual_distance_between_atoms = mol.distances_between_atoms()
|
||||
|
||||
npt.assert_almost_equal(
|
||||
expected_distance_between_atoms,
|
||||
actual_distance_between_atoms
|
||||
expected_distance_between_atoms, actual_distance_between_atoms
|
||||
)
|
||||
|
||||
def test_inertia_tensor(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -90,25 +86,28 @@ class TestMolecule(unittest.TestCase):
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
|
||||
expected_inertia_tensor = [[1.00790, -0.50395, -0.50395],
|
||||
[-0.50395, 1.0079, -0.50395],
|
||||
[-0.50395, -0.50395, 1.0079]]
|
||||
expected_inertia_tensor = [
|
||||
[1.00790, -0.50395, -0.50395],
|
||||
[-0.50395, 1.0079, -0.50395],
|
||||
[-0.50395, -0.50395, 1.0079],
|
||||
]
|
||||
|
||||
actual_inertia_tensor = mol.inertia_tensor()
|
||||
|
||||
npt.assert_equal(
|
||||
expected_inertia_tensor,
|
||||
actual_inertia_tensor
|
||||
)
|
||||
npt.assert_equal(expected_inertia_tensor, actual_inertia_tensor)
|
||||
|
||||
def test_principal_axes(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
|
||||
expected_evals, expected_evecs = [0., 0., 0.], [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]
|
||||
expected_evals, expected_evecs = [0.0, 0.0, 0.0], [
|
||||
[1.0, 0.0, 0.0],
|
||||
[0.0, 1.0, 0.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
]
|
||||
|
||||
evals, evecs = mol.principal_axes()
|
||||
|
||||
@@ -116,7 +115,7 @@ class TestMolecule(unittest.TestCase):
|
||||
npt.assert_equal(expected_evecs, evecs)
|
||||
|
||||
def test_read_position(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -126,30 +125,24 @@ class TestMolecule(unittest.TestCase):
|
||||
|
||||
actual_position = mol.read_position()
|
||||
|
||||
npt.assert_equal(
|
||||
expected_position,
|
||||
actual_position
|
||||
)
|
||||
npt.assert_equal(expected_position, actual_position)
|
||||
|
||||
def test_update_charges(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
|
||||
expected_charges = [2.]
|
||||
expected_charges = [2.0]
|
||||
mol.update_charges(expected_charges)
|
||||
|
||||
actual_charges = list(map(lambda a: a.chg, mol.atom))
|
||||
|
||||
npt.assert_equal(
|
||||
expected_charges,
|
||||
actual_charges
|
||||
)
|
||||
npt.assert_equal(expected_charges, actual_charges)
|
||||
|
||||
def test_sizes_of_molecule(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -162,7 +155,7 @@ class TestMolecule(unittest.TestCase):
|
||||
npt.assert_equal(sizes, expected_sizes)
|
||||
|
||||
def test_standard_orientation(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -175,7 +168,7 @@ class TestMolecule(unittest.TestCase):
|
||||
self.assertEqual(mol.read_position().tolist(), expected_position)
|
||||
|
||||
def test_translate(self):
|
||||
mol = Molecule('test')
|
||||
mol = Molecule("test")
|
||||
|
||||
mol.add_atom(
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
@@ -185,18 +178,15 @@ class TestMolecule(unittest.TestCase):
|
||||
|
||||
expected_position = [0.0, 0.0, 0.0]
|
||||
|
||||
self.assertEqual(
|
||||
new_mol.read_position().tolist(),
|
||||
expected_position
|
||||
)
|
||||
self.assertEqual(new_mol.read_position().tolist(), expected_position)
|
||||
|
||||
def test_minimum_distance(self):
|
||||
mol1 = Molecule('test1')
|
||||
mol1 = Molecule("test1")
|
||||
mol1.add_atom(
|
||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
|
||||
mol2 = Molecule('test2')
|
||||
mol2 = Molecule("test2")
|
||||
mol2.add_atom(
|
||||
Atom(lbl=1, na=1, rx=1.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||
)
|
||||
@@ -208,5 +198,5 @@ class TestMolecule(unittest.TestCase):
|
||||
self.assertEqual(expected_distance, actual_distance)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -13,15 +13,14 @@ class TestSystem(unittest.TestCase):
|
||||
|
||||
def test_add_type(self):
|
||||
system = System()
|
||||
system.add_type(Molecule('test'))
|
||||
system.add_type(Molecule("test"))
|
||||
|
||||
self.assertIsInstance(system.molecule, list)
|
||||
|
||||
with self.assertRaises(TypeError) as ex:
|
||||
system.add_type('test')
|
||||
self.assertEqual(ex.exception, 'Error: molecule is not a Molecule instance')
|
||||
system.add_type("test")
|
||||
self.assertEqual(ex.exception, "Error: molecule is not a Molecule instance")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
from diceplayer.shared.interface.dice_interface import DiceInterface
|
||||
from diceplayer import logger
|
||||
from diceplayer.shared.config.player_config import PlayerConfig
|
||||
from diceplayer.shared.environment.atom import Atom
|
||||
from diceplayer.shared.environment.molecule import Molecule
|
||||
from diceplayer.shared.environment.system import System
|
||||
from diceplayer.shared.environment.atom import Atom
|
||||
from diceplayer import logger
|
||||
|
||||
import yaml
|
||||
import io
|
||||
|
||||
from diceplayer.shared.interface.dice_interface import DiceInterface
|
||||
from tests.mocks.mock_inputs import get_config_example
|
||||
from tests.mocks.mock_proc import MockConnection, MockProc
|
||||
|
||||
from unittest import mock
|
||||
import yaml
|
||||
|
||||
import io
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class TestDiceInterface(unittest.TestCase):
|
||||
@@ -20,7 +19,7 @@ class TestDiceInterface(unittest.TestCase):
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
config = yaml.load(get_config_example(), Loader=yaml.Loader)
|
||||
self.config = PlayerConfig.from_dict(config['diceplayer'])
|
||||
self.config = PlayerConfig.from_dict(config["diceplayer"])
|
||||
|
||||
def test_class_instantiation(self):
|
||||
dice = DiceInterface()
|
||||
@@ -44,24 +43,26 @@ class TestDiceInterface(unittest.TestCase):
|
||||
|
||||
dice.configure(self.config, System())
|
||||
|
||||
self.assertTrue(hasattr(dice, 'step'))
|
||||
self.assertTrue(hasattr(dice, 'system'))
|
||||
self.assertTrue(hasattr(dice, "step"))
|
||||
self.assertTrue(hasattr(dice, "system"))
|
||||
|
||||
dice.reset()
|
||||
|
||||
self.assertFalse(hasattr(dice, 'step'))
|
||||
self.assertFalse(hasattr(dice, 'system'))
|
||||
self.assertFalse(hasattr(dice, "step"))
|
||||
self.assertFalse(hasattr(dice, "system"))
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Process', MockProc())
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.connection', MockConnection)
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.Process", MockProc())
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.connection", MockConnection)
|
||||
def test_start(self):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
dice.start(1)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.connection', MockConnection)
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Process', MockProc(exitcode=1))
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.connection", MockConnection)
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.Process", MockProc(exitcode=1)
|
||||
)
|
||||
def test_start_with_process_error(self):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
@@ -75,10 +76,16 @@ class TestDiceInterface(unittest.TestCase):
|
||||
with self.assertRaises(SystemExit):
|
||||
dice._simulation_process(1, 1)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.DiceInterface._make_proc_dir')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.DiceInterface._make_dice_inputs')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.DiceInterface._run_dice')
|
||||
def test_simulation_process(self, mock_run_dice, mock_make_dice_inputs, mock_make_proc_dir):
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.DiceInterface._make_proc_dir"
|
||||
)
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.DiceInterface._make_dice_inputs"
|
||||
)
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.DiceInterface._run_dice")
|
||||
def test_simulation_process(
|
||||
self, mock_run_dice, mock_make_dice_inputs, mock_make_proc_dir
|
||||
):
|
||||
dice = DiceInterface()
|
||||
|
||||
dice._simulation_process(1, 1)
|
||||
@@ -87,8 +94,8 @@ class TestDiceInterface(unittest.TestCase):
|
||||
self.assertTrue(dice._make_dice_inputs.called)
|
||||
self.assertTrue(dice._run_dice.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.mkdir')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists')
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.mkdir")
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.exists")
|
||||
def test_make_proc_dir_if_simdir_exists(self, mock_path_exists, mock_path_mkdir):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
@@ -99,9 +106,11 @@ class TestDiceInterface(unittest.TestCase):
|
||||
|
||||
self.assertEqual(mock_path_mkdir.call_count, 2)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.mkdir')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists')
|
||||
def test_make_proc_dir_if_simdir_doesnt_exists(self, mock_path_exists, mock_path_mkdir):
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.mkdir")
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.exists")
|
||||
def test_make_proc_dir_if_simdir_doesnt_exists(
|
||||
self, mock_path_exists, mock_path_mkdir
|
||||
):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
@@ -145,9 +154,13 @@ class TestDiceInterface(unittest.TestCase):
|
||||
self.assertFalse(dice._make_npt_ter.called)
|
||||
self.assertFalse(dice._make_npt_eq.called)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open, read_data='test')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists', return_value=True)
|
||||
def test_make_dice_inputs_nstep_len_two_with_randoninit_first_cycle_two(self, mock_path_exists, mock_open):
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open, read_data="test")
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=True
|
||||
)
|
||||
def test_make_dice_inputs_nstep_len_two_with_randoninit_first_cycle_two(
|
||||
self, mock_path_exists, mock_open
|
||||
):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
@@ -176,8 +189,12 @@ class TestDiceInterface(unittest.TestCase):
|
||||
self.assertFalse(dice._make_npt_ter.called)
|
||||
self.assertFalse(dice._make_npt_eq.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists', return_value=False)
|
||||
def test_make_dice_inputs_raises_exception_on_last_not_found(self, mock_path_exists):
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=False
|
||||
)
|
||||
def test_make_dice_inputs_raises_exception_on_last_not_found(
|
||||
self, mock_path_exists
|
||||
):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
@@ -223,10 +240,14 @@ class TestDiceInterface(unittest.TestCase):
|
||||
self.assertTrue(dice._make_npt_ter.called)
|
||||
self.assertTrue(dice._make_npt_eq.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.os')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.shutil')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists', return_value=True)
|
||||
def test_run_dice_on_first_cycle_run_successful(self, mock_path_exists, mock_shutils, mock_os):
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.os")
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.shutil")
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=True
|
||||
)
|
||||
def test_run_dice_on_first_cycle_run_successful(
|
||||
self, mock_path_exists, mock_shutils, mock_os
|
||||
):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
@@ -257,10 +278,14 @@ class TestDiceInterface(unittest.TestCase):
|
||||
self.assertEqual(dice.run_dice_file.call_count, 2)
|
||||
self.assertTrue(mock_shutils.copy.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.os')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.shutil')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists', return_value=True)
|
||||
def test_run_dice_on_second_cycle_run_successful(self, mock_path_exists, mock_shutils, mock_os):
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.os")
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.shutil")
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=True
|
||||
)
|
||||
def test_run_dice_on_second_cycle_run_successful(
|
||||
self, mock_path_exists, mock_shutils, mock_os
|
||||
):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
@@ -287,10 +312,14 @@ class TestDiceInterface(unittest.TestCase):
|
||||
self.assertEqual(dice.run_dice_file.call_count, 1)
|
||||
self.assertTrue(mock_shutils.copy.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.os')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.shutil')
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.Path.exists', return_value=False)
|
||||
def test_run_dice_on_second_cycle_run_successful(self, mock_path_exists, mock_shutils, mock_os):
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.os")
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.shutil")
|
||||
@mock.patch(
|
||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=False
|
||||
)
|
||||
def test_run_dice_on_second_cycle_run_successful(
|
||||
self, mock_path_exists, mock_shutils, mock_os
|
||||
):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
@@ -299,7 +328,7 @@ class TestDiceInterface(unittest.TestCase):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
dice._run_dice(1, 1)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
def test_make_init_file(self, mock_open):
|
||||
example_atom = Atom(
|
||||
lbl=1,
|
||||
@@ -312,10 +341,10 @@ class TestDiceInterface(unittest.TestCase):
|
||||
sig=1.0,
|
||||
)
|
||||
|
||||
main_molecule = Molecule('main_molecule')
|
||||
main_molecule = Molecule("main_molecule")
|
||||
main_molecule.add_atom(example_atom)
|
||||
|
||||
secondary_molecule = Molecule('secondary_molecule')
|
||||
secondary_molecule = Molecule("secondary_molecule")
|
||||
secondary_molecule.add_atom(example_atom)
|
||||
|
||||
system = System()
|
||||
@@ -328,15 +357,17 @@ class TestDiceInterface(unittest.TestCase):
|
||||
dice.step.dice.nmol = [1, 1]
|
||||
|
||||
last_xyz_file = io.StringIO()
|
||||
last_xyz_file.writelines([
|
||||
' TEST\n',
|
||||
' Configuration number : TEST = TEST TEST TEST\n',
|
||||
' H 1.00000 1.00000 1.00000\n',
|
||||
' H 1.00000 1.00000 1.00000\n',
|
||||
])
|
||||
last_xyz_file.writelines(
|
||||
[
|
||||
" TEST\n",
|
||||
" Configuration number : TEST = TEST TEST TEST\n",
|
||||
" H 1.00000 1.00000 1.00000\n",
|
||||
" H 1.00000 1.00000 1.00000\n",
|
||||
]
|
||||
)
|
||||
last_xyz_file.seek(0)
|
||||
|
||||
dice._make_init_file('test', last_xyz_file)
|
||||
dice._make_init_file("test", last_xyz_file)
|
||||
|
||||
mock_handler = mock_open()
|
||||
calls = mock_handler.write.call_args_list
|
||||
@@ -344,14 +375,14 @@ class TestDiceInterface(unittest.TestCase):
|
||||
lines = list(map(lambda x: x[0][0], calls))
|
||||
|
||||
expected_lines = [
|
||||
' 1.000000 1.000000 1.000000\n',
|
||||
' 1.000000 1.000000 1.000000\n',
|
||||
'$end'
|
||||
" 1.000000 1.000000 1.000000\n",
|
||||
" 1.000000 1.000000 1.000000\n",
|
||||
"$end",
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
def test_new_density(self, mock_open):
|
||||
example_atom = Atom(
|
||||
lbl=1,
|
||||
@@ -364,10 +395,10 @@ class TestDiceInterface(unittest.TestCase):
|
||||
sig=1.0,
|
||||
)
|
||||
|
||||
main_molecule = Molecule('main_molecule')
|
||||
main_molecule = Molecule("main_molecule")
|
||||
main_molecule.add_atom(example_atom)
|
||||
|
||||
secondary_molecule = Molecule('secondary_molecule')
|
||||
secondary_molecule = Molecule("secondary_molecule")
|
||||
secondary_molecule.add_atom(example_atom)
|
||||
|
||||
system = System()
|
||||
@@ -378,95 +409,166 @@ class TestDiceInterface(unittest.TestCase):
|
||||
dice.configure(self.config, system)
|
||||
|
||||
last_xyz_file = io.StringIO()
|
||||
last_xyz_file.writelines([
|
||||
' TEST\n',
|
||||
' Configuration number : TEST = 1 1 1\n',
|
||||
' H 1.00000 1.00000 1.00000\n',
|
||||
' H 1.00000 1.00000 1.00000\n',
|
||||
])
|
||||
last_xyz_file.writelines(
|
||||
[
|
||||
" TEST\n",
|
||||
" Configuration number : TEST = 1 1 1\n",
|
||||
" H 1.00000 1.00000 1.00000\n",
|
||||
" H 1.00000 1.00000 1.00000\n",
|
||||
]
|
||||
)
|
||||
last_xyz_file.seek(0)
|
||||
|
||||
density = dice._new_density(last_xyz_file)
|
||||
|
||||
self.assertEqual(density, 85.35451545000001)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.random')
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
||||
def test_make_nvt_ter(self, mock_random, mock_open):
|
||||
mock_random.random.return_value = 1
|
||||
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
dice._make_nvt_ter(1, 'test')
|
||||
dice._make_nvt_ter(1, "test")
|
||||
|
||||
mock_handler = mock_open()
|
||||
calls = mock_handler.write.call_args_list
|
||||
|
||||
lines = list(map(lambda x: x[0][0], calls))
|
||||
|
||||
expected_lines = ['title = Diceplayer run - NVT Thermalization\n', 'ncores = 4\n', 'ljname = phb.ljc\n', 'outname = phb\n', 'nmol = 1 50\n', 'dens = 0.75\n', 'temp = 300.0\n', 'init = yes\n', 'nstep = 2000\n', 'vstep = 0\n', 'mstop = 1\n', 'accum = no\n', 'iprint = 1\n', 'isave = 0\n', 'irdf = 0\n', 'seed = 1000000\n', 'upbuf = 360']
|
||||
expected_lines = [
|
||||
"title = Diceplayer run - NVT Thermalization\n",
|
||||
"ncores = 4\n",
|
||||
"ljname = phb.ljc\n",
|
||||
"outname = phb\n",
|
||||
"nmol = 1 50\n",
|
||||
"dens = 0.75\n",
|
||||
"temp = 300.0\n",
|
||||
"init = yes\n",
|
||||
"nstep = 2000\n",
|
||||
"vstep = 0\n",
|
||||
"mstop = 1\n",
|
||||
"accum = no\n",
|
||||
"iprint = 1\n",
|
||||
"isave = 0\n",
|
||||
"irdf = 0\n",
|
||||
"seed = 1000000\n",
|
||||
"upbuf = 360",
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.random')
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
||||
def test_make_nvt_eq(self, mock_random, mock_open):
|
||||
mock_random.random.return_value = 1
|
||||
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
dice._make_nvt_eq(1, 'test')
|
||||
dice._make_nvt_eq(1, "test")
|
||||
|
||||
mock_handler = mock_open()
|
||||
calls = mock_handler.write.call_args_list
|
||||
|
||||
lines = list(map(lambda x: x[0][0], calls))
|
||||
|
||||
expected_lines = ['title = Diceplayer run - NVT Production\n', 'ncores = 4\n', 'ljname = phb.ljc\n', 'outname = phb\n', 'nmol = 1 50\n', 'dens = 0.75\n', 'temp = 300.0\n', 'init = no\n', 'nstep = 3000\n', 'vstep = 0\n', 'mstop = 1\n', 'accum = no\n', 'iprint = 1\n', 'isave = 1000\n', 'irdf = 40\n', 'seed = 1000000\n']
|
||||
expected_lines = [
|
||||
"title = Diceplayer run - NVT Production\n",
|
||||
"ncores = 4\n",
|
||||
"ljname = phb.ljc\n",
|
||||
"outname = phb\n",
|
||||
"nmol = 1 50\n",
|
||||
"dens = 0.75\n",
|
||||
"temp = 300.0\n",
|
||||
"init = no\n",
|
||||
"nstep = 3000\n",
|
||||
"vstep = 0\n",
|
||||
"mstop = 1\n",
|
||||
"accum = no\n",
|
||||
"iprint = 1\n",
|
||||
"isave = 1000\n",
|
||||
"irdf = 40\n",
|
||||
"seed = 1000000\n",
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.random')
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
||||
def test_make_npt_ter(self, mock_random, mock_open):
|
||||
mock_random.random.return_value = 1
|
||||
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
dice._make_npt_ter(1, 'test')
|
||||
dice._make_npt_ter(1, "test")
|
||||
|
||||
mock_handler = mock_open()
|
||||
calls = mock_handler.write.call_args_list
|
||||
|
||||
lines = list(map(lambda x: x[0][0], calls))
|
||||
|
||||
expected_lines = ['title = Diceplayer run - NPT Thermalization\n', 'ncores = 4\n', 'ljname = phb.ljc\n', 'outname = phb\n', 'nmol = 1 50\n', 'press = 1.0\n', 'temp = 300.0\n', 'init = no\n', 'vstep = 600\n', 'nstep = 5\n', 'mstop = 1\n', 'accum = no\n', 'iprint = 1\n', 'isave = 0\n', 'irdf = 0\n', 'seed = 1000000\n']
|
||||
expected_lines = [
|
||||
"title = Diceplayer run - NPT Thermalization\n",
|
||||
"ncores = 4\n",
|
||||
"ljname = phb.ljc\n",
|
||||
"outname = phb\n",
|
||||
"nmol = 1 50\n",
|
||||
"press = 1.0\n",
|
||||
"temp = 300.0\n",
|
||||
"init = no\n",
|
||||
"vstep = 600\n",
|
||||
"nstep = 5\n",
|
||||
"mstop = 1\n",
|
||||
"accum = no\n",
|
||||
"iprint = 1\n",
|
||||
"isave = 0\n",
|
||||
"irdf = 0\n",
|
||||
"seed = 1000000\n",
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.random')
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
||||
def test_make_npt_eq(self, mock_random, mock_open):
|
||||
mock_random.random.return_value = 1
|
||||
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
dice._make_npt_eq('test')
|
||||
dice._make_npt_eq("test")
|
||||
|
||||
mock_handler = mock_open()
|
||||
calls = mock_handler.write.call_args_list
|
||||
|
||||
lines = list(map(lambda x: x[0][0], calls))
|
||||
|
||||
expected_lines = ['title = Diceplayer run - NPT Production\n', 'ncores = 4\n', 'ljname = phb.ljc\n', 'outname = phb\n', 'nmol = 1 50\n', 'press = 1.0\n', 'temp = 300.0\n', 'nstep = 5\n', 'vstep = 800\n', 'init = no\n', 'mstop = 1\n', 'accum = no\n', 'iprint = 1\n', 'isave = 1000\n', 'irdf = 40\n', 'seed = 1000000\n']
|
||||
expected_lines = [
|
||||
"title = Diceplayer run - NPT Production\n",
|
||||
"ncores = 4\n",
|
||||
"ljname = phb.ljc\n",
|
||||
"outname = phb\n",
|
||||
"nmol = 1 50\n",
|
||||
"press = 1.0\n",
|
||||
"temp = 300.0\n",
|
||||
"nstep = 5\n",
|
||||
"vstep = 800\n",
|
||||
"init = no\n",
|
||||
"mstop = 1\n",
|
||||
"accum = no\n",
|
||||
"iprint = 1\n",
|
||||
"isave = 1000\n",
|
||||
"irdf = 40\n",
|
||||
"seed = 1000000\n",
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open)
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
||||
def test_make_potentials(self, mock_open):
|
||||
example_atom = Atom(
|
||||
lbl=1,
|
||||
@@ -479,10 +581,10 @@ class TestDiceInterface(unittest.TestCase):
|
||||
sig=1.0,
|
||||
)
|
||||
|
||||
main_molecule = Molecule('main_molecule')
|
||||
main_molecule = Molecule("main_molecule")
|
||||
main_molecule.add_atom(example_atom)
|
||||
|
||||
secondary_molecule = Molecule('secondary_molecule')
|
||||
secondary_molecule = Molecule("secondary_molecule")
|
||||
secondary_molecule.add_atom(example_atom)
|
||||
|
||||
system = System()
|
||||
@@ -492,49 +594,68 @@ class TestDiceInterface(unittest.TestCase):
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, system)
|
||||
|
||||
dice._make_potentials('test')
|
||||
dice._make_potentials("test")
|
||||
|
||||
mock_handler = mock_open()
|
||||
calls = mock_handler.write.call_args_list
|
||||
|
||||
lines = list(map(lambda x: x[0][0], calls))
|
||||
|
||||
expected_lines = ['*\n', '2\n', '1 main_molecule\n', '1 1 1.00000 1.00000 1.00000 1.000000 1.00000 1.0000\n', '1 secondary_molecule\n', '1 1 1.00000 1.00000 1.00000 1.000000 1.00000 1.0000\n']
|
||||
expected_lines = [
|
||||
"*\n",
|
||||
"2\n",
|
||||
"1 main_molecule\n",
|
||||
"1 1 1.00000 1.00000 1.00000 1.000000 1.00000 1.0000\n",
|
||||
"1 secondary_molecule\n",
|
||||
"1 1 1.00000 1.00000 1.00000 1.000000 1.00000 1.0000\n",
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.subprocess')
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open, read_data='End of simulation\nBLABLA')
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.subprocess")
|
||||
@mock.patch(
|
||||
"builtins.open",
|
||||
new_callable=mock.mock_open,
|
||||
read_data="End of simulation\nBLABLA",
|
||||
)
|
||||
def test_run_dice_file(self, mock_open, mock_subprocess):
|
||||
mock_subprocess.call.return_value = 0
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
dice.run_dice_file(1, 1, 'test')
|
||||
dice.run_dice_file(1, 1, "test")
|
||||
|
||||
self.assertTrue(mock_subprocess.call.called)
|
||||
self.assertTrue(mock_open.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.subprocess')
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open, read_data='Error\nBLABLA')
|
||||
def test_run_dice_file_raises_runtime_error_on_dice_file(self, mock_open, mock_subprocess):
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.subprocess")
|
||||
@mock.patch("builtins.open", new_callable=mock.mock_open, read_data="Error\nBLABLA")
|
||||
def test_run_dice_file_raises_runtime_error_on_dice_file(
|
||||
self, mock_open, mock_subprocess
|
||||
):
|
||||
mock_subprocess.call.return_value = 0
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
dice.run_dice_file(1, 1, 'test')
|
||||
dice.run_dice_file(1, 1, "test")
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.dice_interface.subprocess')
|
||||
@mock.patch('builtins.open', new_callable=mock.mock_open, read_data='End of simulation\nBLABLA')
|
||||
def test_run_dice_file_raises_runtime_error_of_dice_exit_code(self, mock_open, mock_subprocess):
|
||||
@mock.patch("diceplayer.shared.interface.dice_interface.subprocess")
|
||||
@mock.patch(
|
||||
"builtins.open",
|
||||
new_callable=mock.mock_open,
|
||||
read_data="End of simulation\nBLABLA",
|
||||
)
|
||||
def test_run_dice_file_raises_runtime_error_of_dice_exit_code(
|
||||
self, mock_open, mock_subprocess
|
||||
):
|
||||
mock_subprocess.call.return_value = 1
|
||||
dice = DiceInterface()
|
||||
dice.configure(self.config, System())
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
dice.run_dice_file(1, 1, 'test')
|
||||
dice.run_dice_file(1, 1, "test")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
from diceplayer.shared.interface.gaussian_interface import GaussianInterface
|
||||
from diceplayer import logger
|
||||
from diceplayer.shared.config.player_config import PlayerConfig
|
||||
from diceplayer.shared.environment.system import System
|
||||
from diceplayer import logger
|
||||
|
||||
from diceplayer.shared.interface.gaussian_interface import GaussianInterface
|
||||
from tests.mocks.mock_inputs import get_config_example
|
||||
|
||||
import yaml
|
||||
|
||||
import io
|
||||
|
||||
|
||||
from unittest import mock
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class TestGaussianInterface(unittest.TestCase):
|
||||
@@ -18,7 +16,7 @@ class TestGaussianInterface(unittest.TestCase):
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
config = yaml.load(get_config_example(), Loader=yaml.Loader)
|
||||
self.config = PlayerConfig.from_dict(config['diceplayer'])
|
||||
self.config = PlayerConfig.from_dict(config["diceplayer"])
|
||||
|
||||
def test_class_instantiation(self):
|
||||
gaussian_interface = GaussianInterface()
|
||||
@@ -45,11 +43,11 @@ class TestGaussianInterface(unittest.TestCase):
|
||||
|
||||
gaussian_interface.reset()
|
||||
|
||||
self.assertFalse(hasattr(gaussian_interface, 'step'))
|
||||
self.assertFalse(hasattr(gaussian_interface, 'system'))
|
||||
self.assertFalse(hasattr(gaussian_interface, "step"))
|
||||
self.assertFalse(hasattr(gaussian_interface, "system"))
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.Path.mkdir')
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.Path.exists')
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.mkdir")
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
||||
def test_make_qm_dir(self, mock_exists, mock_mkdir):
|
||||
mock_exists.return_value = False
|
||||
|
||||
@@ -61,8 +59,8 @@ class TestGaussianInterface(unittest.TestCase):
|
||||
mock_exists.assert_called_once()
|
||||
mock_mkdir.assert_called_once()
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.shutil.copy')
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.Path.exists')
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy")
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
||||
def test_copy_chk_file_from_previous_step(self, mock_exists, mock_copy):
|
||||
gaussian_interface = GaussianInterface()
|
||||
gaussian_interface.configure(self.config, System())
|
||||
@@ -74,9 +72,11 @@ class TestGaussianInterface(unittest.TestCase):
|
||||
self.assertTrue(mock_exists.called)
|
||||
self.assertTrue(mock_copy.called)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.shutil.copy')
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.Path.exists')
|
||||
def test_copy_chk_file_from_previous_step_no_previous_step(self, mock_exists, mock_copy):
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy")
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
||||
def test_copy_chk_file_from_previous_step_no_previous_step(
|
||||
self, mock_exists, mock_copy
|
||||
):
|
||||
gaussian_interface = GaussianInterface()
|
||||
gaussian_interface.configure(self.config, System())
|
||||
|
||||
@@ -85,9 +85,11 @@ class TestGaussianInterface(unittest.TestCase):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
gaussian_interface._copy_chk_file_from_previous_step(2)
|
||||
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.shutil.copy')
|
||||
@mock.patch('diceplayer.shared.interface.gaussian_interface.Path.exists')
|
||||
def test_copy_chk_file_from_previous_step_current_exists(self, mock_exists, mock_copy):
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy")
|
||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
||||
def test_copy_chk_file_from_previous_step_current_exists(
|
||||
self, mock_exists, mock_copy
|
||||
):
|
||||
gaussian_interface = GaussianInterface()
|
||||
gaussian_interface.configure(self.config, System())
|
||||
|
||||
@@ -109,5 +111,5 @@ class TestGaussianInterface(unittest.TestCase):
|
||||
# gaussian_interface._copy_chk_file_from_previous_step.assert_called_once_with(2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from diceplayer.shared.utils.logger import Logger, valid_logger
|
||||
|
||||
import logging
|
||||
import io
|
||||
|
||||
from unittest import mock
|
||||
import logging
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class TestValidateLogger(unittest.TestCase):
|
||||
@@ -32,102 +31,102 @@ class TestValidateLogger(unittest.TestCase):
|
||||
|
||||
class TestLogger(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
|
||||
self.assertIsInstance(logger, Logger)
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
def test_set_logger_to_file(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
self.assertIsNotNone(logger._logger)
|
||||
self.assertEqual(logger._logger.name, 'test')
|
||||
self.assertEqual(logger._logger.name, "test")
|
||||
|
||||
def test_set_logger_to_stream(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
self.assertIsNotNone(logger._logger)
|
||||
self.assertEqual(logger._logger.name, 'test')
|
||||
self.assertEqual(logger._logger.name, "test")
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch('diceplayer.shared.utils.logger.Path.exists')
|
||||
@mock.patch('diceplayer.shared.utils.logger.Path.rename')
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
@mock.patch("diceplayer.shared.utils.logger.Path.exists")
|
||||
@mock.patch("diceplayer.shared.utils.logger.Path.rename")
|
||||
def test_set_logger_if_file_exists(self, mock_rename, mock_exists):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
|
||||
mock_exists.return_value = True
|
||||
logger.set_logger()
|
||||
|
||||
self.assertTrue(mock_rename.called)
|
||||
self.assertIsNotNone(logger._logger)
|
||||
self.assertEqual(logger._logger.name, 'test')
|
||||
self.assertEqual(logger._logger.name, "test")
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch('diceplayer.shared.utils.logger.Path.exists')
|
||||
@mock.patch('diceplayer.shared.utils.logger.Path.rename')
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
@mock.patch("diceplayer.shared.utils.logger.Path.exists")
|
||||
@mock.patch("diceplayer.shared.utils.logger.Path.rename")
|
||||
def test_set_logger_if_file_not_exists(self, mock_rename, mock_exists):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
|
||||
mock_exists.return_value = False
|
||||
logger.set_logger()
|
||||
|
||||
self.assertFalse(mock_rename.called)
|
||||
self.assertIsNotNone(logger._logger)
|
||||
self.assertEqual(logger._logger.name, 'test')
|
||||
self.assertEqual(logger._logger.name, "test")
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
def test_close(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
|
||||
logger.set_logger()
|
||||
logger.close()
|
||||
|
||||
self.assertEqual(len(logger._logger.handlers), 0)
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
def test_info(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
with self.assertLogs(level='INFO') as cm:
|
||||
logger.info('test')
|
||||
with self.assertLogs(level="INFO") as cm:
|
||||
logger.info("test")
|
||||
|
||||
self.assertEqual(cm.output, ['INFO:test:test'])
|
||||
self.assertEqual(cm.output, ["INFO:test:test"])
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
def test_debug(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
logger.set_logger(stream=io.StringIO(), level=logging.DEBUG)
|
||||
|
||||
with self.assertLogs(level='DEBUG') as cm:
|
||||
logger.debug('test')
|
||||
with self.assertLogs(level="DEBUG") as cm:
|
||||
logger.debug("test")
|
||||
|
||||
self.assertEqual(cm.output, ['DEBUG:test:test'])
|
||||
self.assertEqual(cm.output, ["DEBUG:test:test"])
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
def test_warning(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
with self.assertLogs(level='WARNING') as cm:
|
||||
logger.warning('test')
|
||||
with self.assertLogs(level="WARNING") as cm:
|
||||
logger.warning("test")
|
||||
|
||||
self.assertEqual(cm.output, ['WARNING:test:test'])
|
||||
self.assertEqual(cm.output, ["WARNING:test:test"])
|
||||
|
||||
@mock.patch('builtins.open', mock.mock_open())
|
||||
@mock.patch("builtins.open", mock.mock_open())
|
||||
def test_error(self):
|
||||
logger = Logger('test')
|
||||
logger = Logger("test")
|
||||
logger.set_logger(stream=io.StringIO())
|
||||
|
||||
with self.assertLogs(level='ERROR') as cm:
|
||||
logger.error('test')
|
||||
with self.assertLogs(level="ERROR") as cm:
|
||||
logger.error("test")
|
||||
|
||||
self.assertEqual(cm.output, ['ERROR:test:test'])
|
||||
self.assertEqual(cm.output, ["ERROR:test:test"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user