Implements Refactoring in Player Class and Initial Working Version

This commit is contained in:
2023-06-02 20:20:38 -03:00
parent b440a0f05d
commit 33612f2d7b
21 changed files with 1193 additions and 983 deletions

111
tests/mocks/mock_inputs.py Normal file
View File

@@ -0,0 +1,111 @@
from unittest import mock
def get_config_example():
return """
diceplayer:
opt: no
mem: 12
maxcyc: 3
ncores: 4
nprocs: 4
qmprog: 'g16'
lps: no
ghosts: no
altsteps: 20000
dice:
nmol: [1, 50]
dens: 0.75
nstep: [2000, 3000, 4000]
isave: 1000
outname: 'phb'
progname: '~/.local/bin/dice'
ljname: 'phb.ljc'
randominit: 'first'
gaussian:
qmprog: 'g16'
level: 'MP2/aug-cc-pVDZ'
keywords: 'freq'
"""
def get_potentials_exemple():
return """\
*
2
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_combrule():
return """\
.
2
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_ntypes():
return """\
*
a
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_ntypes_config():
return """\
*
3
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_nsites():
return """\
*
2
. TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_molname():
return """\
*
2
1
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def mock_open(file, *args, **kwargs):
values = {
"control.test.yml": get_config_example(),
"phb.ljc": get_potentials_exemple(),
"phb.error.combrule.ljc": get_potentials_error_combrule(),
"phb.error.ntypes.ljc": get_potentials_error_ntypes(),
"phb.error.ntypes.config.ljc": get_potentials_error_ntypes_config(),
"phb.error.nsites.ljc": get_potentials_error_nsites(),
"phb.error.molname.ljc": get_potentials_error_molname(),
}
mock_file = mock.mock_open(read_data=values[file])
return mock_file()

View File

@@ -1,11 +1,11 @@
from diceplayer.shared.config.dice_dto import DiceDTO
from diceplayer.shared.config.dice_config import DiceConfig
import unittest
class TestDiceDto(unittest.TestCase):
def test_class_instantiation(self):
dice_dto = DiceDTO(
dice_dto = DiceConfig(
ljname='test',
outname='test',
dens=1.0,
@@ -13,11 +13,11 @@ class TestDiceDto(unittest.TestCase):
nstep=[1, 1],
)
self.assertIsInstance(dice_dto, DiceDTO)
self.assertIsInstance(dice_dto, DiceConfig)
def test_validate_jname(self):
with self.assertRaises(ValueError) as ex:
DiceDTO(
DiceConfig(
ljname=None,
outname='test',
dens=1.0,
@@ -28,7 +28,7 @@ class TestDiceDto(unittest.TestCase):
def test_validate_outname(self):
with self.assertRaises(ValueError) as ex:
DiceDTO(
DiceConfig(
ljname='test',
outname=None,
dens=1.0,
@@ -39,7 +39,7 @@ class TestDiceDto(unittest.TestCase):
def test_validate_dens(self):
with self.assertRaises(ValueError) as ex:
DiceDTO(
DiceConfig(
ljname='test',
outname='test',
dens=None,
@@ -50,7 +50,7 @@ class TestDiceDto(unittest.TestCase):
def test_validate_nmol(self):
with self.assertRaises(ValueError) as ex:
DiceDTO(
DiceConfig(
ljname='test',
outname='test',
dens=1.0,
@@ -61,7 +61,7 @@ class TestDiceDto(unittest.TestCase):
def test_validate_nstep(self):
with self.assertRaises(ValueError) as ex:
DiceDTO(
DiceConfig(
ljname='test',
outname='test',
dens=1.0,
@@ -71,7 +71,7 @@ class TestDiceDto(unittest.TestCase):
self.assertEqual(ex.exception, "Error: 'nstep' keyword not defined appropriately in config file")
def test_from_dict(self):
dice_dto = DiceDTO.from_dict({
dice_dto = DiceConfig.from_dict({
'ljname': 'test',
'outname': 'test',
'dens': 1.0,
@@ -79,4 +79,4 @@ class TestDiceDto(unittest.TestCase):
'nstep': [1, 1],
})
self.assertIsInstance(dice_dto, DiceDTO)
self.assertIsInstance(dice_dto, DiceConfig)

View File

@@ -1,4 +1,4 @@
from diceplayer.shared.config.gaussian_dto import GaussianDTO
from diceplayer.shared.config.gaussian_config import GaussianDTO
import unittest

View File

@@ -1,28 +1,84 @@
from diceplayer.shared.config.player_dto import PlayerDTO
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
class TestPlayerDTO(unittest.TestCase):
def test_class_instantiation(self):
player_dto = PlayerDTO(opt=True, maxcyc=100, nprocs=4, ncores=4)
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],
},
'gaussian': {
'level': 'test',
'qmprog': 'g16',
'keywords': 'test',
}
}
self.assertIsInstance(player_dto, PlayerDTO)
class TestPlayerDTO(unittest.TestCase):
def setUp(self) -> None:
self.dice_dto = DiceConfig(
ljname='test',
outname='test',
dens=1.0,
nmol=[1],
nstep=[1, 1],
)
self.gaussian_dto = GaussianDTO(
level='test',
qmprog='g16',
keywords='test',
)
def test_class_instantiation(self):
player_dto = PlayerConfig(
opt=True,
mem=12,
maxcyc=100,
nprocs=4,
ncores=4,
dice=self.dice_dto,
gaussian=self.gaussian_dto
)
self.assertIsInstance(player_dto, PlayerConfig)
self.assertIsInstance(player_dto.dice, DiceConfig)
self.assertIsInstance(player_dto.gaussian, GaussianDTO)
def test_min_altsteps(self):
player_dto = PlayerDTO(opt=True, maxcyc=100, nprocs=4, ncores=4, altsteps=100)
player_dto = PlayerConfig(
opt=True,
mem=12,
maxcyc=100,
nprocs=4,
ncores=4,
altsteps=100,
dice=self.dice_dto,
gaussian=self.gaussian_dto
)
self.assertEqual(player_dto.altsteps, 20000)
def test_from_dict(self):
player_dto = PlayerDTO.from_dict({
'opt': True,
'maxcyc': 100,
'nprocs': 4,
'ncores': 4,
})
player_dto = PlayerConfig.from_dict(
get_config_dict()
)
self.assertIsInstance(player_dto, PlayerDTO)
self.assertIsInstance(player_dto, PlayerConfig)
self.assertIsInstance(player_dto.dice, DiceConfig)
self.assertIsInstance(player_dto.gaussian, GaussianDTO)
if __name__ == '__main__':

View File

@@ -13,18 +13,14 @@ class TestSystem(unittest.TestCase):
def test_add_type(self):
system = System()
system.add_type(0, Molecule('test'))
system.add_type(Molecule('test'))
self.assertIsInstance(system.molecule, list)
self.assertIsInstance(system.nmols, list)
with self.assertRaises(TypeError) as ex:
system.add_type(0, 'test')
system.add_type('test')
self.assertEqual(ex.exception, 'Error: molecule is not a Molecule instance')
with self.assertRaises(TypeError) as ex:
system.add_type('test', Molecule('test'))
self.assertEqual(ex.exception, 'Error: nmols is not an integer')
if __name__ == '__main__':

View File

@@ -1,11 +1,14 @@
from diceplayer.shared.interface.dice_interface import DiceInterface
from diceplayer.shared.config.player_config import PlayerConfig
from diceplayer.shared.environment.molecule import Molecule
from diceplayer.shared.environment.system import System
from diceplayer.shared.environment.atom import Atom
from diceplayer.shared.config.step_dto import StepDTO
from diceplayer import logger
import yaml
import io
from tests.mocks.mock_inputs import get_config_example
from tests.mocks.mock_proc import MockConnection, MockProc
from unittest import mock
@@ -16,122 +19,58 @@ class TestDiceInterface(unittest.TestCase):
def setUp(self):
logger.set_logger(stream=io.StringIO())
config = yaml.load(get_config_example(), Loader=yaml.Loader)
self.config = PlayerConfig.from_dict(config['diceplayer'])
def test_class_instantiation(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
self.assertIsInstance(dice, DiceInterface)
def test_configure(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
self.assertIsNone(dice.step)
self.assertIsNone(dice.system)
dice.configure('test')
# Ignoring the types for testing purposes
dice.configure(self.config, System())
self.assertIsNotNone(dice.step)
self.assertIsNotNone(dice.system)
def test_reset(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
dice.configure('test')
dice.configure(self.config, System())
self.assertTrue(hasattr(dice, 'step'))
self.assertTrue(hasattr(dice, 'system'))
dice.reset()
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)
def test_start(self):
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=[],
)
)
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))
def test_start_with_process_error(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=2,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
with self.assertRaises(SystemExit):
dice.start(1)
def test_simulation_process_raises_exception(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
with self.assertRaises(SystemExit):
dice._simulation_process(1, 1)
@@ -140,16 +79,7 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
dice._simulation_process(1, 1)
@@ -160,26 +90,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
mock_path_exists.return_value = False
@@ -190,26 +102,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
mock_path_exists.return_value = False
@@ -218,42 +112,15 @@ class TestDiceInterface(unittest.TestCase):
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()
seed = DiceInterface._make_dice_seed()
self.assertIsInstance(seed, int)
def test_make_dice_inputs_nstep_len_two_with_randoninit_first_cycle_one(self):
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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.step.dice.nstep = [1, 1]
dice._make_potentials = mock.Mock()
@@ -281,26 +148,10 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.step.dice.nstep = [1, 1]
dice._make_potentials = mock.Mock()
@@ -327,26 +178,10 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.step.dice.nstep = [1, 1]
dice._make_potentials = mock.Mock()
@@ -362,26 +197,8 @@ class TestDiceInterface(unittest.TestCase):
dice._make_dice_inputs(2, 1)
def test_make_dice_inputs_nstep_len_three_with_randoninit_first_cycle_one(self):
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice._make_potentials = mock.Mock()
@@ -410,26 +227,10 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.step.dice.nstep = [1, 1, 1]
dice.run_dice_file = mock.Mock()
@@ -441,26 +242,10 @@ class TestDiceInterface(unittest.TestCase):
self.assertEqual(dice.run_dice_file.call_count, 3)
self.assertTrue(mock_shutils.copy.called)
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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.step.dice.nstep = [1, 1]
dice.run_dice_file = mock.Mock()
@@ -476,26 +261,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.run_dice_file = mock.Mock()
@@ -507,26 +274,8 @@ class TestDiceInterface(unittest.TestCase):
self.assertEqual(dice.run_dice_file.call_count, 2)
self.assertTrue(mock_shutils.copy.called)
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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.run_dice_file = mock.Mock()
@@ -542,26 +291,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.run_dice_file = mock.Mock()
@@ -587,32 +318,14 @@ class TestDiceInterface(unittest.TestCase):
secondary_molecule = Molecule('secondary_molecule')
secondary_molecule.add_atom(example_atom)
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=[
main_molecule,
secondary_molecule,
],
nmol=[
len(main_molecule.atom),
len(secondary_molecule.atom),
],
)
)
system = System()
system.add_type(main_molecule)
system.add_type(secondary_molecule)
dice = DiceInterface()
dice.configure(self.config, system)
dice.step.dice.nmol = [1, 1]
last_xyz_file = io.StringIO()
last_xyz_file.writelines([
@@ -657,32 +370,12 @@ class TestDiceInterface(unittest.TestCase):
secondary_molecule = Molecule('secondary_molecule')
secondary_molecule.add_atom(example_atom)
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=[
main_molecule,
secondary_molecule,
],
nmol=[
len(main_molecule.atom),
len(secondary_molecule.atom),
],
)
)
system = System()
system.add_type(main_molecule)
system.add_type(secondary_molecule)
dice = DiceInterface()
dice.configure(self.config, system)
last_xyz_file = io.StringIO()
last_xyz_file.writelines([
@@ -695,33 +388,15 @@ class TestDiceInterface(unittest.TestCase):
density = dice._new_density(last_xyz_file)
self.assertEqual(density, 3.3472359000000003)
self.assertEqual(density, 85.35451545000001)
@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(
{
'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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice._make_nvt_ter(1, 'test')
@@ -730,7 +405,7 @@ class TestDiceInterface(unittest.TestCase):
lines = list(map(lambda x: x[0][0], calls))
expected_lines = ['title = Diceplayer run - NVT Thermalization\n', 'ncores = 1\n', 'ljname = test\n', 'outname = test\n', 'nmol = 1\n', 'dens = 1.0\n', 'temp = 300.0\n', 'init = yes\n', 'nstep = 1\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)
@@ -739,26 +414,8 @@ class TestDiceInterface(unittest.TestCase):
def test_make_nvt_eq(self, mock_random, mock_open):
mock_random.random.return_value = 1
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=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice._make_nvt_eq('test')
@@ -767,7 +424,7 @@ class TestDiceInterface(unittest.TestCase):
lines = list(map(lambda x: x[0][0], calls))
expected_lines = ['title = Diceplayer run - NVT Production\n', 'ncores = 1\n', 'ljname = test\n', 'outname = test\n', 'nmol = 1\n', 'dens = 1.0\n', 'temp = 300.0\n', 'init = no\n', 'nstep = 1\n', 'vstep = 0\n', 'mstop = 1\n', 'accum = no\n', 'iprint = 1\n', 'isave = 1000\n', 'irdf = 10\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)
@@ -776,26 +433,8 @@ class TestDiceInterface(unittest.TestCase):
def test_make_npt_ter(self, mock_random, mock_open):
mock_random.random.return_value = 1
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice._make_npt_ter(1, 'test')
@@ -804,7 +443,7 @@ class TestDiceInterface(unittest.TestCase):
lines = list(map(lambda x: x[0][0], calls))
expected_lines = ['title = Diceplayer run - NPT Thermalization\n', 'ncores = 1\n', 'ljname = test\n', 'outname = test\n', 'nmol = 1\n', 'press = 1.0\n', 'temp = 300.0\n', 'init = no\n', 'vstep = 0\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)
@@ -813,26 +452,8 @@ class TestDiceInterface(unittest.TestCase):
def test_make_npt_eq(self, mock_random, mock_open):
mock_random.random.return_value = 1
dice = DiceInterface(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1, 1],
}
)
dice.configure(
StepDTO(
ncores=1,
nprocs=1,
simulation_dir='test',
altsteps=1,
molecule=[],
nmol=[],
)
)
dice = DiceInterface()
dice.configure(self.config, System())
dice._make_npt_eq('test')
@@ -841,7 +462,7 @@ class TestDiceInterface(unittest.TestCase):
lines = list(map(lambda x: x[0][0], calls))
expected_lines = ['title = Diceplayer run - NPT Production\n', 'ncores = 1\n', 'ljname = test\n', 'outname = test\n', 'nmol = 1\n', 'press = 1.0\n', 'temp = 300.0\n', 'nstep = 5\n', 'vstep = 0\n', 'init = no\n', 'mstop = 1\n', 'accum = no\n', 'iprint = 1\n', 'isave = 1000\n', 'irdf = 10\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)
@@ -864,32 +485,12 @@ class TestDiceInterface(unittest.TestCase):
secondary_molecule = Molecule('secondary_molecule')
secondary_molecule.add_atom(example_atom)
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=[
main_molecule,
secondary_molecule,
],
nmol=[
len(main_molecule.atom),
len(secondary_molecule.atom),
],
)
)
system = System()
system.add_type(main_molecule)
system.add_type(secondary_molecule)
dice = DiceInterface()
dice.configure(self.config, system)
dice._make_potentials('test')
@@ -906,16 +507,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
dice.configure(self.config, System())
dice.run_dice_file(1, 1, 'test')
@@ -926,16 +519,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
dice.configure(self.config, System())
with self.assertRaises(RuntimeError):
dice.run_dice_file(1, 1, 'test')
@@ -944,16 +529,8 @@ class TestDiceInterface(unittest.TestCase):
@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(
{
'ljname': 'test',
'outname': 'test',
'ncores': 1,
'dens': 1.0,
'nmol': [1],
'nstep': [1, 1],
}
)
dice = DiceInterface()
dice.configure(self.config, System())
with self.assertRaises(RuntimeError):
dice.run_dice_file(1, 1, 'test')

View File

@@ -0,0 +1,113 @@
from diceplayer.shared.interface.gaussian_interface import GaussianInterface
from diceplayer.shared.config.player_config import PlayerConfig
from diceplayer.shared.environment.system import System
from diceplayer import logger
from tests.mocks.mock_inputs import get_config_example
import yaml
import io
from unittest import mock
import unittest
class TestGaussianInterface(unittest.TestCase):
def setUp(self) -> None:
logger.set_logger(stream=io.StringIO())
config = yaml.load(get_config_example(), Loader=yaml.Loader)
self.config = PlayerConfig.from_dict(config['diceplayer'])
def test_class_instantiation(self):
gaussian_interface = GaussianInterface()
self.assertIsInstance(gaussian_interface, GaussianInterface)
def test_configure(self):
gaussian_interface = GaussianInterface()
self.assertIsNone(gaussian_interface.step)
self.assertIsNone(gaussian_interface.system)
gaussian_interface.configure(self.config, System())
self.assertIsNotNone(gaussian_interface.step)
self.assertIsNotNone(gaussian_interface.system)
def test_reset(self):
gaussian_interface = GaussianInterface()
gaussian_interface.configure(self.config, System())
self.assertIsNotNone(gaussian_interface.step)
self.assertIsNotNone(gaussian_interface.system)
gaussian_interface.reset()
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')
def test_make_qm_dir(self, mock_exists, mock_mkdir):
mock_exists.return_value = False
gaussian_interface = GaussianInterface()
gaussian_interface.configure(self.config, System())
gaussian_interface._make_qm_dir(1)
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')
def test_copy_chk_file_from_previous_step(self, mock_exists, mock_copy):
gaussian_interface = GaussianInterface()
gaussian_interface.configure(self.config, System())
mock_exists.side_effect = [False, True]
gaussian_interface._copy_chk_file_from_previous_step(2)
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):
gaussian_interface = GaussianInterface()
gaussian_interface.configure(self.config, System())
mock_exists.side_effect = [False, False]
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):
gaussian_interface = GaussianInterface()
gaussian_interface.configure(self.config, System())
mock_exists.side_effect = [True, True]
with self.assertRaises(FileExistsError):
gaussian_interface._copy_chk_file_from_previous_step(2)
# def test_start(self):
# gaussian_interface = GaussianInterface()
# gaussian_interface.configure(self.config, System())
#
# gaussian_interface._make_qm_dir = mock.Mock()
# gaussian_interface._copy_chk_file_from_previous_step = mock.Mock()
#
# gaussian_interface.start(2)
#
# gaussian_interface._make_qm_dir.assert_called_once_with(2)
# gaussian_interface._copy_chk_file_from_previous_step.assert_called_once_with(2)
if __name__ == '__main__':
unittest.main()

View File

@@ -3,119 +3,12 @@ from diceplayer import logger
import io
from tests.mocks.mock_inputs import mock_open
from unittest import mock
import unittest
def get_config_example():
return """
diceplayer:
maxcyc: 3
opt: no
ncores: 4
nprocs: 4
qmprog: 'g16'
lps: no
ghosts: no
altsteps: 20000
dice:
nmol: [1, 50]
dens: 0.75
nstep: [2000, 3000, 4000]
isave: 1000
outname: 'phb'
progname: '~/.local/bin/dice'
ljname: 'phb.ljc'
randominit: 'first'
gaussian:
qmprog: 'g16'
level: 'MP2/aug-cc-pVDZ'
keywords: 'freq'
"""
def get_potentials_exemple():
return """\
*
2
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_combrule():
return """\
.
2
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_ntypes():
return """\
*
a
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_ntypes_config():
return """\
*
3
1 TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_nsites():
return """\
*
2
. TEST
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def get_potentials_error_molname():
return """\
*
2
1
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
1 PLACEHOLDER
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
"""
def mock_open(file, *args, **kwargs):
values = {
"control.test.yml": get_config_example(),
"phb.ljc": get_potentials_exemple(),
"phb.error.combrule.ljc": get_potentials_error_combrule(),
"phb.error.ntypes.ljc": get_potentials_error_ntypes(),
"phb.error.ntypes.config.ljc": get_potentials_error_ntypes_config(),
"phb.error.nsites.ljc": get_potentials_error_nsites(),
"phb.error.molname.ljc": get_potentials_error_molname(),
}
mock_file = mock.mock_open(read_data=values[file])
return mock_file()
class TestPlayer(unittest.TestCase):
def setUp(self):
logger.set_logger(stream=io.StringIO())
@@ -131,19 +24,13 @@ class TestPlayer(unittest.TestCase):
def test_start(self):
player = Player("control.test.yml")
player.print_keywords = mock.MagicMock()
player.create_simulation_dir = mock.MagicMock()
player.read_potentials = mock.MagicMock()
player.print_potentials = mock.MagicMock()
player.gaussian_start = mock.MagicMock()
player.dice_start = mock.MagicMock()
player.start(1)
self.assertTrue(player.print_keywords.called)
self.assertTrue(player.create_simulation_dir.called)
self.assertTrue(player.read_potentials.called)
self.assertTrue(player.print_potentials.called)
self.assertEqual(player.dice_start.call_count, 3)
self.assertEqual(player.gaussian_start.call_count, 3)
@mock.patch("builtins.open", mock_open)
@mock.patch("diceplayer.player.Path")
@@ -178,7 +65,22 @@ class TestPlayer(unittest.TestCase):
with self.assertLogs() as cm:
player.print_keywords()
expected_output = ['INFO:diceplayer:##########################################################################################\n############# Welcome to DICEPLAYER version 1.0 #############\n##########################################################################################\n\n', 'INFO:diceplayer:Your python version is TEST\n', 'INFO:diceplayer:\n', 'INFO:diceplayer:Program started on 00 Test 0000 at 00:00:00\n', 'INFO:diceplayer:\n', 'INFO:diceplayer:Environment variables:\n', 'INFO:diceplayer:OMP_STACKSIZE = Not set\n', 'INFO:diceplayer:\n==========================================================================================\n CONTROL variables being used in this run:\n------------------------------------------------------------------------------------------\n\n', 'INFO:diceplayer:\n', 'INFO:diceplayer:------------------------------------------------------------------------------------------\n DICE variables being used in this run:\n------------------------------------------------------------------------------------------\n\n', 'INFO:diceplayer:dens = 0.75', 'INFO:diceplayer:isave = 1000', 'INFO:diceplayer:ljname = phb.ljc', 'INFO:diceplayer:nmol = [ 1 50 ]', 'INFO:diceplayer:nstep = [ 2000 3000 4000 ]', 'INFO:diceplayer:outname = phb', 'INFO:diceplayer:press = 1.0', 'INFO:diceplayer:progname = ~/.local/bin/dice', 'INFO:diceplayer:randominit = first', 'INFO:diceplayer:temp = 300.0', 'INFO:diceplayer:\n', 'INFO:diceplayer:------------------------------------------------------------------------------------------\n GAUSSIAN variables being used in this run:\n------------------------------------------------------------------------------------------\n\n', 'INFO:diceplayer:keywords = freq', 'INFO:diceplayer:level = MP2/aug-cc-pVDZ', 'INFO:diceplayer:pop = chelpg', 'INFO:diceplayer:qmprog = g16', 'INFO:diceplayer:\n']
expected_output = [
'INFO:diceplayer:##########################################################################################\n############# Welcome to DICEPLAYER version 1.0 #############\n##########################################################################################\n\n',
'INFO:diceplayer:Your python version is TEST\n', 'INFO:diceplayer:\n',
'INFO:diceplayer:Program started on 00 Test 0000 at 00:00:00\n', 'INFO:diceplayer:\n',
'INFO:diceplayer:Environment variables:\n', 'INFO:diceplayer:OMP_STACKSIZE = Not set\n',
'INFO:diceplayer:\n==========================================================================================\n CONTROL variables being used in this run:\n------------------------------------------------------------------------------------------\n\n',
'INFO:diceplayer:\n',
'INFO:diceplayer:------------------------------------------------------------------------------------------\n DICE variables being used in this run:\n------------------------------------------------------------------------------------------\n\n',
'INFO:diceplayer:dens = 0.75', 'INFO:diceplayer:isave = 1000', 'INFO:diceplayer:ljname = phb.ljc',
'INFO:diceplayer:nmol = [ 1 50 ]', 'INFO:diceplayer:nstep = [ 2000 3000 4000 ]',
'INFO:diceplayer:outname = phb', 'INFO:diceplayer:press = 1.0',
'INFO:diceplayer:progname = ~/.local/bin/dice', 'INFO:diceplayer:randominit = first',
'INFO:diceplayer:temp = 300.0', 'INFO:diceplayer:\n',
'INFO:diceplayer:------------------------------------------------------------------------------------------\n GAUSSIAN variables being used in this run:\n------------------------------------------------------------------------------------------\n\n',
'INFO:diceplayer:keywords = freq', 'INFO:diceplayer:level = MP2/aug-cc-pVDZ',
'INFO:diceplayer:pop = chelpg', 'INFO:diceplayer:qmprog = g16', 'INFO:diceplayer:\n']
self.assertEqual(cm.output, expected_output)
@@ -333,7 +235,7 @@ class TestPlayer(unittest.TestCase):
# Testing combrule error
with self.assertRaises(SystemExit) as context:
player.dice.config.ljname = "phb.error.combrule.ljc"
player.config.dice.ljname = "phb.error.combrule.ljc"
player.read_potentials()
self.assertEqual(
@@ -343,7 +245,7 @@ class TestPlayer(unittest.TestCase):
# Testing ntypes error
with self.assertRaises(SystemExit) as context:
player.dice.config.ljname = "phb.error.ntypes.ljc"
player.config.dice.ljname = "phb.error.ntypes.ljc"
player.read_potentials()
self.assertEqual(
@@ -353,7 +255,7 @@ class TestPlayer(unittest.TestCase):
# Testing ntypes error on config
with self.assertRaises(SystemExit) as context:
player.dice.config.ljname = "phb.error.ntypes.config.ljc"
player.config.dice.ljname = "phb.error.ntypes.config.ljc"
player.read_potentials()
self.assertEqual(
@@ -364,7 +266,7 @@ class TestPlayer(unittest.TestCase):
# Testing nsite error
with self.assertRaises(ValueError) as context:
player.dice.config.ljname = "phb.error.nsites.ljc"
player.config.dice.ljname = "phb.error.nsites.ljc"
player.read_potentials()
self.assertEqual(
@@ -374,7 +276,7 @@ class TestPlayer(unittest.TestCase):
# Testing molname error
with self.assertRaises(ValueError) as context:
player.dice.config.ljname = "phb.error.molname.ljc"
player.config.dice.ljname = "phb.error.molname.ljc"
player.read_potentials()
self.assertEqual(
@@ -391,7 +293,23 @@ class TestPlayer(unittest.TestCase):
with self.assertLogs(level='INFO') as context:
player.print_potentials()
expected_output = ['INFO:diceplayer:==========================================================================================\n', 'INFO:diceplayer: Potential parameters from file phb.ljc:', 'INFO:diceplayer:------------------------------------------------------------------------------------------\n', 'INFO:diceplayer:Combination rule: *', 'INFO:diceplayer:Types of molecules: 2\n', 'INFO:diceplayer:1 atoms in molecule type 1:', 'INFO:diceplayer:---------------------------------------------------------------------------------', 'INFO:diceplayer:Lbl AN X Y Z Charge Epsilon Sigma Mass', 'INFO:diceplayer:---------------------------------------------------------------------------------', 'INFO:diceplayer:1 1 0.00000 0.00000 0.00000 0.000000 0.00000 0.0000 1.0079', 'INFO:diceplayer:\n', 'INFO:diceplayer:1 atoms in molecule type 2:', 'INFO:diceplayer:---------------------------------------------------------------------------------', 'INFO:diceplayer:Lbl AN X Y Z Charge Epsilon Sigma Mass', 'INFO:diceplayer:---------------------------------------------------------------------------------', 'INFO:diceplayer:1 1 0.00000 0.00000 0.00000 0.000000 0.00000 0.0000 1.0079', 'INFO:diceplayer:\n', 'INFO:diceplayer:==========================================================================================']
expected_output = [
'INFO:diceplayer:==========================================================================================\n',
'INFO:diceplayer: Potential parameters from file phb.ljc:',
'INFO:diceplayer:------------------------------------------------------------------------------------------\n',
'INFO:diceplayer:Combination rule: *', 'INFO:diceplayer:Types of molecules: 2\n',
'INFO:diceplayer:1 atoms in molecule type 1:',
'INFO:diceplayer:---------------------------------------------------------------------------------',
'INFO:diceplayer:Lbl AN X Y Z Charge Epsilon Sigma Mass',
'INFO:diceplayer:---------------------------------------------------------------------------------',
'INFO:diceplayer:1 1 0.00000 0.00000 0.00000 0.000000 0.00000 0.0000 1.0079',
'INFO:diceplayer:\n', 'INFO:diceplayer:1 atoms in molecule type 2:',
'INFO:diceplayer:---------------------------------------------------------------------------------',
'INFO:diceplayer:Lbl AN X Y Z Charge Epsilon Sigma Mass',
'INFO:diceplayer:---------------------------------------------------------------------------------',
'INFO:diceplayer:1 1 0.00000 0.00000 0.00000 0.000000 0.00000 0.0000 1.0079',
'INFO:diceplayer:\n',
'INFO:diceplayer:==========================================================================================']
self.assertEqual(
context.output,
@@ -401,23 +319,22 @@ class TestPlayer(unittest.TestCase):
@mock.patch("builtins.open", mock_open)
def test_dice_start(self):
player = Player("control.test.yml")
player.dice = mock.MagicMock()
player.dice.start = mock.MagicMock()
player.dice_interface = mock.MagicMock()
player.dice_interface.start = mock.MagicMock()
player.dice_start(1)
player.dice.start.assert_called_once()
@mock.patch("builtins.open", mock_open)
def test_gaussian_start(self):
player = Player("control.test.yml")
player.gaussian = mock.MagicMock()
player.gaussian.start = mock.MagicMock()
player.gaussian_start(1)
player.gaussian.start.assert_called_once()
player.dice_interface.start.assert_called_once()
# @mock.patch("builtins.open", mock_open)
# def test_gaussian_start(self):
# player = Player("control.test.yml")
# player.gaussian_interface = mock.MagicMock()
# player.gaussian_interface.start = mock.MagicMock()
#
# player.gaussian_start(1)
#
# player.gaussian_interface.start.assert_called_once()
if __name__ == '__main__':