Skip to content

Commit ed520ba

Browse files
committed
Minor check and unit test for bitpattern_to_val
1 parent 4b17076 commit ed520ba

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pyrtl/helperfuncs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ def bitpattern_to_val(bitpattern, *ordered_fields, **named_fields):
307307
# evaluates to 0b00000000001100100010000010100011
308308
"""
309309

310+
if not bitpattern:
311+
raise PyrtlError('bitpattern must be nonempty')
312+
310313
if len(ordered_fields) > 0 and len(named_fields) > 0:
311314
raise PyrtlError('named and ordered fields cannot be mixed')
312315

tests/test_helperfuncs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,9 @@ def test_error_value_doesnt_fit_in_field(self):
454454
with self.assertRaises(pyrtl.PyrtlError):
455455
pyrtl.bitpattern_to_val('iiiiiiirrrrrsssss010iiiii0100011', 1, 65, 4)
456456

457-
@unittest.skip("This error might not be possible")
458-
def test_error_bitlist_and_value_different_sizes(self):
457+
def test_error_empty_bitpattern(self):
459458
with self.assertRaises(pyrtl.PyrtlError):
460-
pass
459+
pyrtl.bitpattern_to_val('')
461460

462461

463462
class TestChop(unittest.TestCase):

0 commit comments

Comments
 (0)