-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Romain Pesche <[email protected]>
- Loading branch information
Showing
3 changed files
with
83 additions
and
27 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,53 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from mitype import app, commandline, history | ||
from mitype.database import fetch_text_from_id | ||
|
||
|
||
@pytest.fixture() | ||
def empty_history_file(monkeypatch, tmp_path): | ||
history_file = tmp_path / ".mitype_history.csv" | ||
history_file.touch() | ||
|
||
monkeypatch.setattr(history, "history_file_absolute_path", lambda: history_file) | ||
|
||
|
||
@pytest.fixture() | ||
def header_only_history_file(monkeypatch, tmp_path): | ||
history_file = tmp_path / ".mitype_history.csv" | ||
|
||
with history_file.open("w+") as fd: | ||
fd.write("ID,WPM,DATE,TIME,ACCURACY\n") | ||
|
||
monkeypatch.setattr(history, "history_file_absolute_path", lambda: history_file) | ||
|
||
|
||
@pytest.fixture() | ||
def history_file(monkeypatch, tmp_path): | ||
history_file = tmp_path / ".mitype_history.csv" | ||
monkeypatch.setattr(history, "history_file_absolute_path", lambda: history_file) | ||
|
||
for i in range(100): | ||
history.save_history(i, 65.3, 89) | ||
|
||
|
||
@pytest.fixture() | ||
def mocked_curses(monkeypatch): | ||
monkeypatch.setattr(app, "curses", MagicMock()) | ||
|
||
|
||
@pytest.fixture() | ||
def mocked_app(mocked_curses, monkeypatch): | ||
text_id = 1758 | ||
text = fetch_text_from_id(text_id) | ||
|
||
monkeypatch.setattr(app, "resolve_commandline_arguments", lambda: (text, text_id)) | ||
|
||
myapp = app.App() | ||
myapp.Color = MagicMock() | ||
myapp.window_width = 274 | ||
myapp.window_height = 75 | ||
|
||
return myapp |
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
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,30 @@ | ||
from copy import copy | ||
from unittest.mock import MagicMock | ||
|
||
|
||
def test_perfect_accuracy(mocked_app): | ||
win = MagicMock() | ||
|
||
for character in copy(mocked_app.text): | ||
mocked_app.typing_mode(win, character) | ||
assert mocked_app.accuracy == 100 | ||
|
||
|
||
def test_error_during_typing(mocked_app): | ||
win = MagicMock() | ||
|
||
text = ["z", "KEY_BACKSPACE"] + list(copy(mocked_app.text)) | ||
|
||
for character in copy(text): | ||
mocked_app.typing_mode(win, character) | ||
assert mocked_app.accuracy == 99.2 | ||
|
||
|
||
def test_same_character_after_typing(mocked_app): | ||
win = MagicMock() | ||
|
||
text = list(copy(mocked_app.text)) + list(mocked_app.text[-1] * 10) | ||
|
||
for character in copy(text): | ||
mocked_app.typing_mode(win, character) | ||
assert mocked_app.accuracy == 100 |