Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qr_code_frame_calc branch: code review + tests #294

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/krux/pages/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def list_address_type(self, addr_type=0):
self.ctx.display.clear()
self.ctx.display.draw_centered_text(loading_txt % (num_checked + 1))

pos_str = str(num_checked + 1) + ". "
pos_str = str(num_checked + 1) + "." + " " # thin space
tadeubas marked this conversation as resolved.
Show resolved Hide resolved
qr_title = pos_str + addr
items.append(
(
Expand Down
9 changes: 3 additions & 6 deletions src/krux/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,9 @@ def max_qr_bytes(max_width):
max_width -= 2 # Subtract frame width
qr_version = (max_width - 17) // 4
try:
capacity = QR_CAPACITY[qr_version - 1]
return QR_CAPACITY[qr_version - 1]
except:
capacity = QR_CAPACITY[-1]
return capacity
return QR_CAPACITY[-1]


def find_min_num_parts(data, max_width, qr_format):
Expand Down Expand Up @@ -217,9 +216,7 @@ def find_min_num_parts(data, max_width, qr_format):
num_parts = (data_length + qr_capacity - 1) // qr_capacity
# For UR, part size will be the input for "max_fragment_len"
part_size = len(data.cbor) // num_parts
part_size = max(
part_size, UR_MIN_FRAGMENT_LENGTH
)
part_size = max(part_size, UR_MIN_FRAGMENT_LENGTH)
else:
raise ValueError("Invalid format type")
return num_parts, part_size
Expand Down
14 changes: 12 additions & 2 deletions tests/test_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_to_qr_codes(mocker, m5stickv, tdata):
for case in cases:
mocker.patch(
"krux.display.lcd",
new=mocker.MagicMock(width=mocker.MagicMock(return_value=case[2]))
new=mocker.MagicMock(width=mocker.MagicMock(return_value=case[2])),
)
display = Display()
qr_data_width = display.qr_data_width()
Expand All @@ -154,7 +154,7 @@ def test_to_qr_codes(mocker, m5stickv, tdata):
if i == total - 1:
break
except Exception as e:
print("Error:",e)
print("Error:", e)
break
i += 1
assert len(codes) == expected_parts
Expand All @@ -168,3 +168,13 @@ def test_detect_plaintext_qr(mocker, m5stickv):
)

detect_format(PLAINTEXT_QR_DATA)


def test_find_min_num_parts(m5stickv):
from krux.qr import find_min_num_parts

with pytest.raises(ValueError) as raised_ex:
find_min_num_parts("", 10, "format unknown")

assert raised_ex.type is ValueError
assert raised_ex.value.args[0] == "Invalid format type"
Loading