65 lines
1.4 KiB
Python
65 lines
1.4 KiB
Python
from dataclasses import field
|
|
|
|
import pytest
|
|
|
|
from scgenerator.variableparameters import Variable, vdataclass, vfield
|
|
|
|
|
|
def test_vfield_identification():
|
|
"""only vfields and not normal fields count"""
|
|
|
|
class Conf:
|
|
x: int
|
|
|
|
with pytest.warns(UserWarning):
|
|
vdataclass(Conf)
|
|
|
|
@vdataclass
|
|
class Conf2:
|
|
x: Variable = vfield(default=5)
|
|
|
|
assert hasattr(Conf2, "filter")
|
|
|
|
|
|
def test_constant():
|
|
"""classes with constant fields don't increase size and always return the constant"""
|
|
|
|
@vdataclass
|
|
class Conf:
|
|
x: Variable = vfield(default=3)
|
|
y: Variable = vfield(default=4)
|
|
|
|
conf = Conf()
|
|
assert len(conf) == 1
|
|
assert conf.x(0) == 3
|
|
assert conf.y(0) == 4
|
|
|
|
with pytest.raises(ValueError):
|
|
conf.x(1)
|
|
with pytest.raises(ValueError):
|
|
conf.y(1)
|
|
|
|
|
|
def test_decoration():
|
|
"""proper construction of the class"""
|
|
|
|
|
|
def test_name_error():
|
|
"""name errors are raised when accessing inexistent variable (direct, filter, ...)"""
|
|
|
|
|
|
def test_defaults():
|
|
"""default values are respected, of proper type and of size one"""
|
|
|
|
|
|
def test_formatting():
|
|
"""formatting is always respected"""
|
|
|
|
|
|
def test_param_parsing():
|
|
"""parsing a string or path returns the correct values"""
|
|
|
|
|
|
def test_config_parsing():
|
|
"""parsing a string returns the exact id corresponding to the string/path"""
|