Skip to content

Commit ad7d762

Browse files
esbenh4jenshnielsen
authored andcommitted
extend test_value_validation to cover more cases
1 parent 35aaf75 commit ad7d762

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/parameter/test_delegate_parameter.py

+32
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,23 @@ def test_value_validation() -> None:
574574
source_param = Parameter("source", set_cmd=None, get_cmd=None)
575575
delegate_param = DelegateParameter("delegate", source=source_param)
576576

577+
# Test case where source parameter validator is None and delegate parameter validator is
578+
# specified.
577579
delegate_param.vals = vals.Numbers(-10, 10)
578580
source_param.vals = None
579581
delegate_param.validate(1)
580582
with pytest.raises(ValueError):
581583
delegate_param.validate(11)
582584

585+
# Test where delegate parameter validator is None and source parameter validator is
586+
# specified.
583587
delegate_param.vals = None
584588
source_param.vals = vals.Numbers(-5, 5)
585589
delegate_param.validate(1)
586590
with pytest.raises(ValueError):
587591
delegate_param.validate(6)
588592

593+
# Test case where source parameter validator is more restricted than delegate parameter.
589594
delegate_param.vals = vals.Numbers(-10, 10)
590595
source_param.vals = vals.Numbers(-5, 5)
591596
delegate_param.validate(1)
@@ -594,6 +599,33 @@ def test_value_validation() -> None:
594599
with pytest.raises(ValueError):
595600
delegate_param.validate(11)
596601

602+
# Test case that the order of setting validator on source and delegate parameters does not matter.
603+
source_param.vals = vals.Numbers(-5, 5)
604+
delegate_param.vals = vals.Numbers(-10, 10)
605+
delegate_param.validate(1)
606+
with pytest.raises(ValueError):
607+
delegate_param.validate(6)
608+
with pytest.raises(ValueError):
609+
delegate_param.validate(11)
610+
611+
# Test case where delegate parameter validator is more restricted than source parameter.
612+
delegate_param.vals = vals.Numbers(-5, 5)
613+
source_param.vals = vals.Numbers(-10, 10)
614+
delegate_param.validate(1)
615+
with pytest.raises(ValueError):
616+
delegate_param.validate(6)
617+
with pytest.raises(ValueError):
618+
delegate_param.validate(11)
619+
620+
# Test case that the order of setting validator on source and delegate parameters does not matter.
621+
source_param.vals = vals.Numbers(-10, 10)
622+
delegate_param.vals = vals.Numbers(-5, 5)
623+
delegate_param.validate(1)
624+
with pytest.raises(ValueError):
625+
delegate_param.validate(6)
626+
with pytest.raises(ValueError):
627+
delegate_param.validate(11)
628+
597629

598630
def test_value_validation_with_offset_and_scale() -> None:
599631
source_param = Parameter(

0 commit comments

Comments
 (0)