Skip to content

Commit eeb0439

Browse files
Add tests that .set() rejects invalid values
1 parent 6f254fc commit eeb0439

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

tests/test_record_values.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,3 +885,84 @@ def test_waveform_rejects_overlong_values(self):
885885
w_in.set([1, 2, 3, 4])
886886
with pytest.raises(AssertionError):
887887
w_out.set([1, 2, 3, 4])
888+
889+
def test_long_rejects_invalid_values(self):
890+
"""Test that longIn/longOut reject invalid values"""
891+
l_in = builder.longIn("L_IN_1")
892+
l_out = builder.longOut("L_OUT_1")
893+
894+
long_min = numpy.iinfo(numpy.int32).min
895+
long_max = numpy.iinfo(numpy.int32).max
896+
897+
with pytest.raises(AssertionError):
898+
l_in.set(long_min - 1)
899+
with pytest.raises(AssertionError):
900+
l_out.set(long_min - 1)
901+
902+
with pytest.raises(AssertionError):
903+
l_in.set(long_max + 1)
904+
with pytest.raises(AssertionError):
905+
l_out.set(long_max + 1)
906+
907+
# And confirm that creating with invalid values also raises
908+
with pytest.raises(AssertionError):
909+
builder.longIn("L_IN_2", initial_value = long_min - 1)
910+
with pytest.raises(AssertionError):
911+
builder.longOut("L_OUT_2", initial_value = long_min - 1)
912+
913+
with pytest.raises(AssertionError):
914+
builder.longIn("L_IN_3", initial_value = long_max + 1)
915+
with pytest.raises(AssertionError):
916+
builder.longOut("L_OUT_3", initial_value = long_max + 1)
917+
918+
def test_bool_rejects_invalid_values(self):
919+
"""Test that boolIn/boolOut rejects invalid values"""
920+
b_in = builder.boolIn("B_IN_1")
921+
b_out = builder.boolOut("B_OUT_1")
922+
923+
with pytest.raises(AssertionError):
924+
b_in.set(-1)
925+
with pytest.raises(AssertionError):
926+
b_out.set(-1)
927+
928+
with pytest.raises(AssertionError):
929+
b_in.set(2)
930+
with pytest.raises(AssertionError):
931+
b_out.set(2)
932+
933+
# And confirm that creating with invalid values also raises
934+
with pytest.raises(AssertionError):
935+
builder.boolIn("B_IN_2", initial_value=-1)
936+
with pytest.raises(AssertionError):
937+
builder.boolOut("B_OUT_2", initial_value=-1)
938+
939+
with pytest.raises(AssertionError):
940+
builder.boolIn("B_IN_3", initial_value=2)
941+
with pytest.raises(AssertionError):
942+
builder.boolOut("B_OUT_3", initial_value=2)
943+
944+
def test_mbb_rejects_invalid_values(self):
945+
"""Test that mbbIn/mbbOut rejects invalid values"""
946+
mbb_in = builder.mbbIn("MBB_IN_1")
947+
mbb_out = builder.mbbOut("MBB_OUT_1")
948+
949+
with pytest.raises(AssertionError):
950+
mbb_in.set(-1)
951+
with pytest.raises(AssertionError):
952+
mbb_out.set(-1)
953+
954+
with pytest.raises(AssertionError):
955+
mbb_in.set(16)
956+
with pytest.raises(AssertionError):
957+
mbb_out.set(16)
958+
959+
# And confirm that creating with invalid values also raises
960+
with pytest.raises(AssertionError):
961+
builder.mbbIn("MBB_IN_2", initial_value=-1)
962+
with pytest.raises(AssertionError):
963+
builder.mbbOut("MBB_OUT_2", initial_value=-1)
964+
965+
with pytest.raises(AssertionError):
966+
builder.mbbIn("MBB_IN_3", initial_value=16)
967+
with pytest.raises(AssertionError):
968+
builder.mbbOut("MBB_OUT_3", initial_value=16)

0 commit comments

Comments
 (0)