From fa25f16f7d760aad173344e01649f69d99d89aa5 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 5 Apr 2020 19:16:05 +0100 Subject: [PATCH] fix repr (0x prefix) and add repr test for selectable int --- src/soc/decoder/selectable_int.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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() -- 2.30.2