Skip to content

Commit

Permalink
✨ Refactoring tests to pass CI ...
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyle committed Dec 11, 2021
1 parent 48ac3e8 commit 7bbaa50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
9 changes: 2 additions & 7 deletions tests/integration/blocks/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@
from PyQt5.QtCore import QPointF

from opencodeblocks.blocks.block import OCBBlock
from opencodeblocks.graphics.window import OCBWindow
from opencodeblocks.graphics.widget import OCBWidget

from tests.integration.utils import apply_function_inapp, CheckingQueue
from tests.integration.utils import apply_function_inapp, CheckingQueue, start_app


class TestBlocks:
@pytest.fixture(autouse=True)
def setup(self):
"""Setup reused variables."""
self.window = OCBWindow()
self.ocb_widget = OCBWidget()
self.subwindow = self.window.mdiArea.addSubWindow(self.ocb_widget)
self.subwindow.show()
start_app(self)
self.block = OCBBlock(title="Testing block")

def test_create_blocks(self, qtbot: QtBot):
Expand Down
19 changes: 6 additions & 13 deletions tests/integration/blocks/test_codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
Integration tests for the OCBCodeBlocks.
"""

import time
import pyautogui
import pytest
from pytestqt.qtbot import QtBot

from PyQt5.QtCore import QPointF

from opencodeblocks.blocks.codeblock import OCBCodeBlock
from opencodeblocks.graphics.window import OCBWindow
from opencodeblocks.graphics.widget import OCBWidget

from tests.integration.utils import apply_function_inapp, CheckingQueue
from tests.integration.utils import apply_function_inapp, CheckingQueue, start_app


class TestCodeBlocks:
class TestCodeBlocks():

@pytest.fixture(autouse=True)
def setup(self):
""" Setup reused variables. """
self.window = OCBWindow()
self.ocb_widget = OCBWidget()
self.subwindow = self.window.mdiArea.addSubWindow(self.ocb_widget)
self.subwindow.show()
start_app(self)

def test_run_python(self, qtbot: QtBot):
def test_run_python(self):
""" run source code when run button is pressed. """

# Add a block with the source to the window
Expand Down Expand Up @@ -56,12 +53,8 @@ def testing_run(msgQueue: CheckingQueue):
pyautogui.mouseDown(button="left")
pyautogui.mouseUp(button="left")

# qtbot.mouseMove(test_block.run_button)
# qtbot.mousePress(test_block.run_button,
# Qt.MouseButton.LeftButton, delay=1)
# qtbot.mouseRelease(test_block.run_button, Qt.MouseButton.LeftButton)
time.sleep(0.1)

# When the execution becomes non-blocking for the UI, a refactor will be needed here.
msgQueue.check_equal(test_block.stdout.strip(), expected_result)
msgQueue.stop()

Expand Down
7 changes: 7 additions & 0 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from queue import Queue
from qtpy.QtWidgets import QApplication
import pytest_check as check
from opencodeblocks.graphics.widget import OCBWidget

from opencodeblocks.graphics.window import OCBWindow

Expand All @@ -33,6 +34,12 @@ def stop(self):
self.put([STOP_MSG])


def start_app(obj):
obj.window = OCBWindow()
obj.ocb_widget = OCBWidget()
obj.subwindow = obj.window.mdiArea.addSubWindow(obj.ocb_widget)
obj.subwindow.show()

def apply_function_inapp(window: OCBWindow, run_func: Callable):

if os.name == "nt": # If on windows
Expand Down

0 comments on commit 7bbaa50

Please sign in to comment.