-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03f0df2
commit 4f86c10
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import pytest | ||
|
||
from core.config import Config | ||
from core.input import LEFT_MOUSE, RIGHT_MOUSE | ||
from modules.contrib.aerlive import Module, Measurement | ||
|
||
|
||
@pytest.fixture | ||
def mock_data(): | ||
return { | ||
"measurements": [ | ||
Measurement("city1", 15, 30), | ||
Measurement("city2", 78, 90), | ||
Measurement("city3", 32, 50), | ||
], | ||
"expected_index": 1, | ||
} | ||
|
||
|
||
def build_module(): | ||
return Module( | ||
config=Config([]), | ||
theme=None, | ||
) | ||
|
||
|
||
def test_load_module(): | ||
__import__("modules.contrib.aerlive") | ||
|
||
|
||
def test_input_registration(mocker): | ||
input_register = mocker.patch("core.input.register") | ||
module = build_module() | ||
|
||
input_register.assert_any_call( | ||
module, | ||
button=LEFT_MOUSE, | ||
cmd=module.next_location, | ||
) | ||
|
||
input_register.assert_any_call( | ||
module, | ||
button=RIGHT_MOUSE, | ||
cmd=module.reset_location, | ||
) | ||
|
||
def test_initial_full_text(mocker): | ||
module = build_module() | ||
assert module.widget().full_text() == "?" | ||
|
||
|
||
def test_update_full_text(mock_data, mocker): | ||
mock_event = mocker.MagicMock() | ||
module = build_module() | ||
|
||
module.text(mock_event) | ||
assert module.widget().full_text() == "?" | ||
|
||
module.measurements = mock_data["measurements"] | ||
module.current_index = mock_data["expected_index"] | ||
|
||
module.text(mock_event) | ||
assert module.widget().full_text() == "city2 78" | ||
|
||
|
||
def test_reset_measurement_index(mock_data, mocker): | ||
module = build_module() | ||
|
||
module.reset_measurement_index() | ||
assert not module.measurements and module.current_index == -1 | ||
|
||
module.measurements = mock_data["measurements"] | ||
module.reset_measurement_index() | ||
assert module.measurements and module.current_index == mock_data["expected_index"] |