Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
idanpa committed Jan 26, 2025
1 parent 7e29f87 commit 98e703c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pypad/tests/test_pypad.py
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')

0 comments on commit 98e703c

Please sign in to comment.