refactor: update imports and switch to pytest for testing
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from diceplayer.config.dice_config import DiceConfig
|
||||
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
|
||||
class TestDiceDto(unittest.TestCase):
|
||||
class TestDiceConfig:
|
||||
def test_class_instantiation(self):
|
||||
dice_dto = DiceConfig(
|
||||
ljname="test",
|
||||
@@ -13,10 +13,10 @@ class TestDiceDto(unittest.TestCase):
|
||||
nstep=[1, 1],
|
||||
)
|
||||
|
||||
self.assertIsInstance(dice_dto, DiceConfig)
|
||||
assert isinstance(dice_dto, DiceConfig)
|
||||
|
||||
def test_validate_jname(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname=None,
|
||||
outname="test",
|
||||
@@ -24,12 +24,11 @@ class TestDiceDto(unittest.TestCase):
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(
|
||||
ex.exception, "Error: 'ljname' keyword not specified in config file"
|
||||
)
|
||||
|
||||
assert ex.value == "Error: 'ljname' keyword not specified in config file"
|
||||
|
||||
def test_validate_outname(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname="test",
|
||||
outname=None,
|
||||
@@ -37,12 +36,11 @@ class TestDiceDto(unittest.TestCase):
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(
|
||||
ex.exception, "Error: 'outname' keyword not specified in config file"
|
||||
)
|
||||
|
||||
assert ex.value == "Error: 'outname' keyword not specified in config file"
|
||||
|
||||
def test_validate_dens(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname="test",
|
||||
outname="test",
|
||||
@@ -50,12 +48,11 @@ class TestDiceDto(unittest.TestCase):
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(
|
||||
ex.exception, "Error: 'dens' keyword not specified in config file"
|
||||
)
|
||||
|
||||
assert ex.value == "Error: 'dens' keyword not specified in config file"
|
||||
|
||||
def test_validate_nmol(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname="test",
|
||||
outname="test",
|
||||
@@ -63,13 +60,11 @@ class TestDiceDto(unittest.TestCase):
|
||||
nmol=0,
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.assertEqual(
|
||||
ex.exception,
|
||||
"Error: 'nmol' keyword not defined appropriately in config file",
|
||||
)
|
||||
|
||||
assert ex.value == "Error: 'nmol' keyword not specified in config file"
|
||||
|
||||
def test_validate_nstep(self):
|
||||
with self.assertRaises(ValueError) as ex:
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
ljname="test",
|
||||
outname="test",
|
||||
@@ -77,10 +72,8 @@ class TestDiceDto(unittest.TestCase):
|
||||
nmol=[1],
|
||||
nstep=0,
|
||||
)
|
||||
self.assertEqual(
|
||||
ex.exception,
|
||||
"Error: 'nstep' keyword not defined appropriately in config file",
|
||||
)
|
||||
|
||||
assert ex.value == "Error: 'nstep' keyword not specified in config file"
|
||||
|
||||
def test_from_dict(self):
|
||||
dice_dto = DiceConfig.model_validate(
|
||||
@@ -93,4 +86,4 @@ class TestDiceDto(unittest.TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
self.assertIsInstance(dice_dto, DiceConfig)
|
||||
assert isinstance(dice_dto, DiceConfig)
|
||||
@@ -1,9 +1,9 @@
|
||||
from diceplayer.config.gaussian_config import GaussianConfig
|
||||
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
|
||||
class TestGaussianDTO(unittest.TestCase):
|
||||
class TestGaussianConfig:
|
||||
def test_class_instantiation(self):
|
||||
gaussian_dto = GaussianConfig(
|
||||
level="test",
|
||||
@@ -11,10 +11,10 @@ class TestGaussianDTO(unittest.TestCase):
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
self.assertIsInstance(gaussian_dto, GaussianConfig)
|
||||
assert isinstance(gaussian_dto, GaussianConfig)
|
||||
|
||||
def test_is_valid_qmprog(self):
|
||||
with self.assertRaises(ValueError):
|
||||
with pytest.raises(ValueError):
|
||||
GaussianConfig(
|
||||
level="test",
|
||||
qmprog="test",
|
||||
@@ -22,7 +22,7 @@ class TestGaussianDTO(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_is_valid_level(self):
|
||||
with self.assertRaises(ValueError):
|
||||
with pytest.raises(ValueError):
|
||||
GaussianConfig(
|
||||
level=None,
|
||||
qmprog="g16",
|
||||
@@ -38,8 +38,4 @@ class TestGaussianDTO(unittest.TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
self.assertIsInstance(gaussian_dto, GaussianConfig)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
assert isinstance(gaussian_dto, GaussianConfig)
|
||||
@@ -2,7 +2,7 @@ from diceplayer.config.dice_config import DiceConfig
|
||||
from diceplayer.config.gaussian_config import GaussianConfig
|
||||
from diceplayer.config.player_config import PlayerConfig
|
||||
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
|
||||
def get_config_dict():
|
||||
@@ -27,37 +27,41 @@ def get_config_dict():
|
||||
}
|
||||
|
||||
|
||||
class TestPlayerDTO(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.dice_dto = DiceConfig(
|
||||
class TestPlayerConfig:
|
||||
@pytest.fixture
|
||||
def dice_config(self):
|
||||
return DiceConfig(
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
self.gaussian_dto = GaussianConfig(
|
||||
|
||||
@pytest.fixture
|
||||
def gaussian_config(self):
|
||||
return GaussianConfig(
|
||||
level="test",
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
|
||||
def test_class_instantiation(self):
|
||||
def test_class_instantiation(self, dice_config, gaussian_config):
|
||||
player_dto = PlayerConfig(
|
||||
opt=True,
|
||||
mem=12,
|
||||
maxcyc=100,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
dice=self.dice_dto,
|
||||
gaussian=self.gaussian_dto,
|
||||
dice=dice_config,
|
||||
gaussian=gaussian_config,
|
||||
)
|
||||
|
||||
self.assertIsInstance(player_dto, PlayerConfig)
|
||||
self.assertIsInstance(player_dto.dice, DiceConfig)
|
||||
self.assertIsInstance(player_dto.gaussian, GaussianConfig)
|
||||
assert isinstance(player_dto, PlayerConfig)
|
||||
assert isinstance(player_dto.dice, DiceConfig)
|
||||
assert isinstance(player_dto.gaussian, GaussianConfig)
|
||||
|
||||
def test_min_altsteps(self):
|
||||
def test_min_altsteps(self, dice_config, gaussian_config):
|
||||
player_dto = PlayerConfig(
|
||||
opt=True,
|
||||
mem=12,
|
||||
@@ -65,19 +69,15 @@ class TestPlayerDTO(unittest.TestCase):
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
altsteps=100,
|
||||
dice=self.dice_dto,
|
||||
gaussian=self.gaussian_dto,
|
||||
dice=dice_config,
|
||||
gaussian=gaussian_config,
|
||||
)
|
||||
|
||||
self.assertEqual(player_dto.altsteps, 20000)
|
||||
assert player_dto.altsteps == 20000
|
||||
|
||||
def test_from_dict(self):
|
||||
player_dto = PlayerConfig.model_validate(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()
|
||||
assert isinstance(player_dto, PlayerConfig)
|
||||
assert isinstance(player_dto.dice, DiceConfig)
|
||||
assert isinstance(player_dto.gaussian, GaussianConfig)
|
||||
Reference in New Issue
Block a user