Added more type annotations to Python tester programs.

pull/118/head
Project Nayuki 3 years ago
parent 27dd722961
commit aa32fe1235

@ -68,7 +68,9 @@ def main() -> None:
def do_trial() -> None:
mode = random.randrange(4)
mode: int = random.randrange(4)
length: int
data: List[int]
if mode == 0: # Numeric
length = round((2 * 7089) ** random.random())
data = random.choices(b"0123456789", k=length)
@ -88,12 +90,12 @@ def do_trial() -> None:
for b in data:
write_all(b)
errcorlvl = random.randrange(4)
minversion = random.randint(1, 40)
maxversion = random.randint(1, 40)
errcorlvl: int = random.randrange(4)
minversion: int = random.randint(1, 40)
maxversion: int = random.randint(1, 40)
if minversion > maxversion:
minversion, maxversion = maxversion, minversion
mask = -1
mask: int = -1
if random.random() < 0.5:
mask = random.randrange(8)
boostecl = int(random.random() < 0.2)
@ -106,11 +108,11 @@ def do_trial() -> None:
write_all(boostecl)
flush_all()
version = read_verify()
version: int = read_verify()
print(" version={}".format(version), end="")
if version == -1:
return
size = version * 4 + 17
size: int = version * 4 + 17
for _ in range(size**2):
read_verify()
@ -124,7 +126,7 @@ def flush_all() -> None:
not_none(proc.stdin).flush()
def read_verify() -> int:
val = not_none(subprocs[0].stdout).readline().rstrip("\r\n")
val: str = not_none(subprocs[0].stdout).readline().rstrip("\r\n")
for proc in subprocs[1 : ]:
if not_none(proc.stdout).readline().rstrip("\r\n") != val:
raise ValueError("Mismatch")

@ -27,6 +27,7 @@
#
import sys
from typing import List, Sequence
import qrcodegen
@ -38,26 +39,26 @@ def main() -> None:
while True:
# Read data or exit
length = read_int()
length: int = read_int()
if length == -1:
break
data = bytearray(read_int() for _ in range(length))
# Read encoding parameters
errcorlvl = read_int()
minversion = read_int()
maxversion = read_int()
mask = read_int()
boostecl = read_int()
errcorlvl : int = read_int()
minversion: int = read_int()
maxversion: int = read_int()
mask : int = read_int()
boostecl : int = read_int()
# Make segments for encoding
if all((b < 128) for b in data): # Is ASCII
segs = qrcodegen.QrSegment.make_segments(data.decode("ASCII"))
segs: List[qrcodegen.QrSegment] = qrcodegen.QrSegment.make_segments(data.decode("ASCII"))
else:
segs = [qrcodegen.QrSegment.make_bytes(data)]
try: # Try to make QR Code symbol
qr = qrcodegen.QrCode.encode_segments(segs, ECC_LEVELS[errcorlvl], minversion, maxversion, mask, boostecl != 0)
qr: qrcodegen.QrCode = qrcodegen.QrCode.encode_segments(segs, ECC_LEVELS[errcorlvl], minversion, maxversion, mask, boostecl != 0)
# Print grid of modules
print(qr.get_version())
for y in range(qr.get_size()):
@ -69,7 +70,7 @@ def main() -> None:
sys.stdout.flush()
ECC_LEVELS = (
ECC_LEVELS: Sequence[qrcodegen.QrCode.Ecc] = (
qrcodegen.QrCode.Ecc.LOW,
qrcodegen.QrCode.Ecc.MEDIUM,
qrcodegen.QrCode.Ecc.QUARTILE,

Loading…
Cancel
Save