From 27ca96383eedd68758dec50f0548299b5f932c6f Mon Sep 17 00:00:00 2001 From: mcc Date: Mon, 11 Mar 2024 15:42:13 -0400 Subject: [PATCH] utils: F-strings are missing the letter "f" Also adds tests for utils ValueError strings. --- amaranth/utils.py | 4 ++-- tests/test_utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/amaranth/utils.py b/amaranth/utils.py index cb2e1a1..014ef40 100644 --- a/amaranth/utils.py +++ b/amaranth/utils.py @@ -13,7 +13,7 @@ def ceil_log2(n): """ n = operator.index(n) if n < 0: - raise ValueError("{n} is negative") + raise ValueError(f"{n} is negative") if n == 0: return 0 return (n - 1).bit_length() @@ -26,7 +26,7 @@ def exact_log2(n): """ n = operator.index(n) if n <= 0 or (n & (n - 1)): - raise ValueError("{n} is not a power of 2") + raise ValueError(f"{n} is not a power of 2") return (n - 1).bit_length() diff --git a/tests/test_utils.py b/tests/test_utils.py index feb5147..4e11f71 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,7 +16,7 @@ class Log2TestCase(unittest.TestCase): self.assertEqual(ceil_log2(9), 4) with self.assertRaises(TypeError): ceil_log2(1.5) - with self.assertRaises(ValueError): + with self.assertRaisesRegex(ValueError, r"^-1 is negative$"): ceil_log2(-1) def test_exact_log2(self): @@ -25,7 +25,7 @@ class Log2TestCase(unittest.TestCase): self.assertEqual(exact_log2(4), 2) self.assertEqual(exact_log2(8), 3) for val in [-1, 0, 3, 5, 6, 7, 9]: - with self.assertRaises(ValueError): + with self.assertRaisesRegex(ValueError, (f"^{val} is not a power of 2$")): exact_log2(val) with self.assertRaises(TypeError): exact_log2(1.5)