Skip to content

Commit

Permalink
add autocomplete mnemonic words and image render tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odudex committed Oct 21, 2024
1 parent 4e89600 commit 85a8692
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/pages/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,3 +1275,39 @@ def test_about(mocker, m5stickv):
ctx.display.draw_centered_text.assert_called_with(
"Krux\n\nHardware\n" + board.config["type"] + "\n\nVersion\n" + VERSION
)


def test_auto_complete_qr_words(m5stickv, mocker):
from krux.pages.login import Login

ctx = create_ctx(mocker, [])
login = Login(ctx)

# Test case where all words are valid
words = ["abandon"] * 12
result = login.auto_complete_qr_words(words)
assert result == words

# Test case where some words need to be autocompleted
words = ["abandon", "abil", "abl"] + ["abandon"] * 9
expected_result = ["abandon", "ability", "able"] + ["abandon"] * 9
result = login.auto_complete_qr_words(words)
assert result == expected_result

# Test case where a word cannot be autocompleted
words = ["aband", "abil", "xyz"] + ["abandon"] * 9
result = login.auto_complete_qr_words(words)
assert result == []

# Test case where all words need to be autocompleted
words = ["aband", "abil", "abl"] + ["abandon"] * 9
expected_result = ["abandon", "ability", "able"] + ["abandon"] * 9
result = login.auto_complete_qr_words(words)
assert result == expected_result

# Test case with mixed case words
words = ["AbAnD", "aBiL", "AbL"] + ["abandon"] * 9
expected_result = ["abandon", "ability", "able"] + ["abandon"] * 9
result = login.auto_complete_qr_words(words)
assert result == expected_result

47 changes: 47 additions & 0 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,50 @@ def test_flash_text(mocker, m5stickv):
d.clear.assert_called()
d.draw_centered_text.assert_called_with("test", WHITE)
time.sleep_ms.assert_called_with(FLASH_MSG_TIME)


def test_render_image(mocker, multiple_devices):
mocker.patch("krux.display.lcd", new=mocker.MagicMock())
import krux
from krux.display import Display
import board

d = Display()
img = mocker.MagicMock()

# Test non-compact rendering
d.render_image(img, compact=False)
if board.config["type"] == "m5stickv":
krux.display.lcd.display.assert_called_once_with(
img, oft=(0, 0), roi=(68, 52, 185, 135)
)
elif board.config["type"] == "amigo":
krux.display.lcd.display.assert_called_once_with(img, oft=(40, 40))
elif board.config["type"] == "dock":
krux.display.lcd.display.assert_called_once_with(
img, oft=(0, 0), roi=(8, 0, 304, 240)
)
elif board.config["type"] == "cube":
krux.display.lcd.display.assert_called_once_with(
img, oft=(0, 0), roi=(48, 0, 224, 240)
)

# Reset mock for next test
krux.display.lcd.display.reset_mock()

# Test compact rendering
d.render_image(img, compact=True)
if board.config["type"] == "m5stickv":
krux.display.lcd.display.assert_called_once_with(
img, oft=(24, 0), roi=(68, 52, 185, 135)
)
elif board.config["type"] == "amigo":
krux.display.lcd.display.assert_called_once_with(img, oft=(40, 40))
elif board.config["type"] == "dock":
krux.display.lcd.display.assert_called_once_with(
img, oft=(26, 0), roi=(28, 0, 264, 240)
)
elif board.config["type"] == "cube":
krux.display.lcd.display.assert_called_once_with(
img, oft=(24, 0), roi=(67, 0, 186, 240)
)

0 comments on commit 85a8692

Please sign in to comment.