From: Luke Kenneth Casson Leighton Date: Sun, 5 Apr 2020 18:16:05 +0000 (+0100) Subject: fix repr (0x prefix) and add repr test for selectable int X-Git-Tag: div_pipeline~1480 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa25f16f7d760aad173344e01649f69d99d89aa5;p=soc.git fix repr (0x prefix) and add repr test for selectable int --- diff --git a/src/soc/decoder/selectable_int.py b/src/soc/decoder/selectable_int.py index 28e48f2e..ccdac9f5 100644 --- a/src/soc/decoder/selectable_int.py +++ b/src/soc/decoder/selectable_int.py @@ -167,7 +167,7 @@ class SelectableInt: return self.value != 0 def __repr__(self): - return "SelectableInt(value={:x}, bits={})".format(self.value, + return "SelectableInt(value=0x{:x}, bits={})".format(self.value, self.bits) def onebit(bit): @@ -278,6 +278,11 @@ class SelectableIntTestCase(unittest.TestCase): self.assertEqual(c, 0x00) self.assertEqual(c.bits, 8) + def test_repr(self): + for i in range(65536): + a = SelectableInt(i, 16) + b = eval(repr(a)) + self.assertEqual(a, b) if __name__ == "__main__": unittest.main()