feat: improved implementation and validations of configs
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
from diceplayer.config.dice_config import DiceConfig
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestDiceDto(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
dice_dto = DiceConfig(
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
|
||||
self.assertIsInstance(dice_dto, DiceConfig)
|
||||
|
||||
def test_validate_jname(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname=None,
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
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",
|
||||
outname=None,
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
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",
|
||||
dens=None,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
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",
|
||||
dens=1.0,
|
||||
nmol=0,
|
||||
nstep=[1, 1],
|
||||
)
|
||||
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",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=0,
|
||||
)
|
||||
self.assertEqual(
|
||||
ex.exception,
|
||||
"Error: 'nstep' keyword not defined appropriately in config file",
|
||||
)
|
||||
|
||||
def test_from_dict(self):
|
||||
dice_dto = DiceConfig.model_validate(
|
||||
{
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
"nmol": [1],
|
||||
"nstep": [1, 1],
|
||||
}
|
||||
)
|
||||
|
||||
self.assertIsInstance(dice_dto, DiceConfig)
|
||||
@@ -1,45 +0,0 @@
|
||||
from diceplayer.config.gaussian_config import GaussianConfig
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class TestGaussianDTO(unittest.TestCase):
|
||||
def test_class_instantiation(self):
|
||||
gaussian_dto = GaussianConfig(
|
||||
level="test",
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
self.assertIsInstance(gaussian_dto, GaussianConfig)
|
||||
|
||||
def test_is_valid_qmprog(self):
|
||||
with self.assertRaises(ValueError):
|
||||
gaussian_dto = GaussianConfig(
|
||||
level="test",
|
||||
qmprog="test",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
def test_is_valid_level(self):
|
||||
with self.assertRaises(ValueError):
|
||||
gaussian_dto = GaussianConfig(
|
||||
level=None,
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
def test_from_dict(self):
|
||||
gaussian_dto = GaussianConfig.model_validate(
|
||||
{
|
||||
"level": "test",
|
||||
"qmprog": "g16",
|
||||
"keywords": "test",
|
||||
}
|
||||
)
|
||||
|
||||
self.assertIsInstance(gaussian_dto, GaussianConfig)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,83 +0,0 @@
|
||||
from diceplayer.config.dice_config import DiceConfig
|
||||
from diceplayer.config.gaussian_config import GaussianConfig
|
||||
from diceplayer.config.player_config import PlayerConfig
|
||||
|
||||
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],
|
||||
},
|
||||
"gaussian": {
|
||||
"level": "test",
|
||||
"qmprog": "g16",
|
||||
"keywords": "test",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
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 = GaussianConfig(
|
||||
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, GaussianConfig)
|
||||
|
||||
def test_min_altsteps(self):
|
||||
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 = PlayerConfig.from_dict(get_config_dict())
|
||||
|
||||
self.assertIsInstance(player_dto, PlayerConfig)
|
||||
self.assertIsInstance(player_dto.dice, DiceConfig)
|
||||
self.assertIsInstance(player_dto.gaussian, GaussianConfig)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -19,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.model_validate(config["diceplayer"])
|
||||
|
||||
def test_class_instantiation(self):
|
||||
dice = DiceInterface()
|
||||
|
||||
@@ -16,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.model_validate(config["diceplayer"])
|
||||
|
||||
def test_class_instantiation(self):
|
||||
gaussian_interface = GaussianInterface()
|
||||
|
||||
Reference in New Issue
Block a user