Skip to content

Commit a394b68

Browse files
committed
numbertheory: don't require branch coverage for loops that always execute at least once
1 parent ce2dd53 commit a394b68

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ecdsa/numbertheory.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ def square_root_mod_prime(a, p):
222222
range_top = min(0x7FFFFFFF, p)
223223
else:
224224
range_top = p
225-
for b in xrange(2, range_top):
225+
for b in xrange(2, range_top): # pragma: no branch
226226
if jacobi(b * b - 4 * a, p) == -1:
227227
f = (a, -b, 1)
228228
ff = polynomial_exp_mod((0, 1), (p + 1) // 2, f, p)
229229
if ff[1]:
230230
raise SquareRootError("p is not prime")
231231
return ff[0]
232-
raise RuntimeError("No b found.")
232+
# just an assertion
233+
raise RuntimeError("No b found.") # pragma: no cover
233234

234235

235236
# because all the inverse_mod code is arch/environment specific, and coveralls
@@ -352,7 +353,7 @@ def factorization(n):
352353
q, r = divmod(n, d)
353354
if r == 0:
354355
count = 1
355-
while d <= n:
356+
while d <= n: # pragma: no branch
356357
n = q
357358
q, r = divmod(n, d)
358359
if r != 0:
@@ -376,7 +377,8 @@ def factorization(n):
376377
if r == 0: # d divides n. How many times?
377378
count = 1
378379
n = q
379-
while d <= n: # As long as d might still divide n,
380+
# As long as d might still divide n,
381+
while d <= n: # pragma: no branch
380382
q, r = divmod(n, d) # see if it does.
381383
if r != 0:
382384
break

0 commit comments

Comments
 (0)