Skip to content

Commit

Permalink
fix pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
searscr committed Apr 24, 2024
1 parent 742fed5 commit 6e00b19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/pyoncatqt/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
class MainWindow(QWidget):
"""Main widget"""

def __init__(self: QWidget, parent: QWidget) -> None:
def __init__(self: QWidget, key: str = "shiver", parent: QWidget = None) -> None:
super().__init__(parent=parent)
self.initUI()

def initUI(self: QWidget) -> None:
layout = QVBoxLayout()

# Create and add the Oncat widget
self.oncat_widget = ONCatLogin(key="shiver", parent=self)
self.oncat_widget = ONCatLogin(key=key, parent=self)
self.oncat_widget.connection_updated.connect(self.update_instrument_lists)
layout.addWidget(self.oncat_widget)

Expand Down
9 changes: 5 additions & 4 deletions src/pyoncatqt/pyoncatqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import sys
from typing import Any, Dict

from qtpy.QtWidgets import QApplication, QMainWindow

Expand All @@ -15,16 +16,16 @@ class PyONCatQt(QMainWindow):

__instance = None

def __new__(cls: QMainWindow) -> QMainWindow:
def __new__(cls: QMainWindow, **kwargs: Dict[str, Any]) -> QMainWindow: # noqa ARG003
if PyONCatQt.__instance is None:
PyONCatQt.__instance = QMainWindow.__new__(cls)
return PyONCatQt.__instance

def __init__(self: QMainWindow, parent: QApplication = None) -> None:
def __init__(self: QMainWindow, parent: QApplication = None, **kwargs: Dict[str, Any]) -> None:
super().__init__(parent)

key = kwargs.pop("key", "shiver")
self.setWindowTitle(f"PYONCATQT - {__version__}")
self.main_window = MainWindow(self)
self.main_window = MainWindow(key, parent=self)
self.setCentralWidget(self.main_window)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_update_instrument_lists(qtbot: pytest.fixture) -> None:
main_window = MainWindow(None)
main_window = MainWindow("test", None)
qtbot.addWidget(main_window)

oncat_widget_mock = MagicMock()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pyoncatqt_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def test_gui(mock_pyoncatqt: mock, mock_qtapp: mock) -> None:


def test_PyONCatQt_initialization(qtbot: pytest.fixture) -> None:
pyoncatqt = PyONCatQt()
kwargs = {"key": "test"}
pyoncatqt = PyONCatQt(**kwargs)
qtbot.addWidget(pyoncatqt)

assert pyoncatqt.windowTitle() == f"PYONCATQT - {__version__}"
Expand Down

0 comments on commit 6e00b19

Please sign in to comment.