-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
19 additions
and
5 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 |
---|---|---|
@@ -1,20 +1,34 @@ | ||
|
||
import os | ||
import pytest | ||
import logging | ||
from pytestqt.qtbot import QtBot | ||
|
||
# avoid DeprecationWarning https://github.com/jupyter/jupyter_core/issues/398 | ||
os.environ["JUPYTER_PLATFORM_DIRS"] = "1" | ||
|
||
from PyQt6.QtCore import Qt | ||
from pypad import MainWindow, PyPadTextEdit | ||
|
||
class TestHandler(logging.Handler): | ||
def emit(self, record): | ||
if record.levelno > logging.INFO: | ||
raise AssertionError(self.format(record)) | ||
|
||
@pytest.fixture | ||
def pypad(qtbot): | ||
# todo: clear all cells (e.g. if loaded from file) | ||
def pypad(qtbot: QtBot): | ||
os.environ['PYPAD_SCRIPT'] = '' | ||
window = MainWindow() | ||
pypad = window.pypad_text_edit | ||
pypad.log.addHandler(TestHandler()) | ||
qtbot.waitUntil(lambda: pypad.kernel_info != '', timeout=5000) | ||
# todo: measure init time | ||
yield pypad | ||
window.close() | ||
|
||
def test_execution(pypad: PyPadTextEdit, qtbot): | ||
def test_execution(pypad: PyPadTextEdit, qtbot: QtBot): | ||
qtbot.keyClicks(pypad, '1+1') | ||
qtbot.wait(2000) | ||
assert pypad.get_cell_out(0) == '2' | ||
qtbot.waitUntil(lambda: pypad.get_cell_out(0) == '2') | ||
qtbot.keyClick(pypad, Qt.Key_Enter) | ||
qtbot.keyClicks(pypad, 'print(1)') | ||
qtbot.waitUntil(lambda: pypad.get_cell_out(1) == '1') |