mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Add basic unittests for __main__
This commit is contained in:
parent
d2c26d98d6
commit
e88bdb5910
3 changed files with 55 additions and 3 deletions
|
|
@ -30,7 +30,7 @@ logger = logging.getLogger('BeeRef')
|
|||
|
||||
class BeeRefMainWindow(QtWidgets.QWidget):
|
||||
|
||||
def __init__(self, app, filename=None):
|
||||
def __init__(self, app):
|
||||
super().__init__()
|
||||
self.setWindowTitle('BeeRef')
|
||||
self.setWindowIcon(BeeAssets().logo)
|
||||
|
|
@ -38,9 +38,9 @@ class BeeRefMainWindow(QtWidgets.QWidget):
|
|||
layout.setContentsMargins(QtCore.QMargins(0, 0, 0, 0))
|
||||
self.setLayout(layout)
|
||||
self.resize(500, 300)
|
||||
self.show()
|
||||
self.view = BeeGraphicsView(app, self)
|
||||
layout.addWidget(self.view)
|
||||
self.show()
|
||||
|
||||
def __del__(self):
|
||||
del self.view
|
||||
|
|
@ -81,4 +81,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main() # pragma: no cover
|
||||
|
|
|
|||
32
tests/test_main.py
Normal file
32
tests/test_main.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from PyQt6 import QtCore
|
||||
|
||||
from beeref.__main__ import BeeRefMainWindow, main
|
||||
from beeref.assets import BeeAssets
|
||||
from beeref.view import BeeGraphicsView
|
||||
|
||||
from .base import BeeTestCase
|
||||
|
||||
|
||||
class BeeRefMainWindowTestCase(BeeTestCase):
|
||||
|
||||
@patch('PyQt6.QtWidgets.QWidget.show')
|
||||
def test_init(self, show_mock):
|
||||
window = BeeRefMainWindow(self.app)
|
||||
assert window.windowTitle() == 'BeeRef'
|
||||
assert BeeAssets().logo == BeeAssets().logo
|
||||
assert window.windowIcon()
|
||||
assert window.contentsMargins() == QtCore.QMargins(0, 0, 0, 0)
|
||||
assert isinstance(window.view, BeeGraphicsView)
|
||||
show_mock.assert_called_once()
|
||||
|
||||
|
||||
class BeeRefMainTestCase(BeeTestCase):
|
||||
|
||||
@patch('PyQt6.QtWidgets.QApplication')
|
||||
def test_run(self, app_mock):
|
||||
app_mock.return_value = self.app
|
||||
with patch.object(self.app, 'exec') as exec_mock:
|
||||
main()
|
||||
exec_mock.assert_called_once_with()
|
||||
|
|
@ -206,6 +206,26 @@ class SelectableMixinTestCase(SelectableMixinBaseTestCase):
|
|||
self.item.SELECT_ROTATE_SIZE = 100
|
||||
assert self.item.select_rotate_size == 25
|
||||
|
||||
def test_draw_debug_shape_rect(self):
|
||||
painter = MagicMock()
|
||||
self.item.draw_debug_shape(
|
||||
painter,
|
||||
QtCore.QRectF(5, 6, 20, 30),
|
||||
255, 0, 0)
|
||||
painter.fillRect.assert_called_once()
|
||||
painter.fillPath.assert_not_called()
|
||||
|
||||
def test_draw_debug_shape_path(self):
|
||||
painter = MagicMock()
|
||||
path = QtGui.QPainterPath()
|
||||
path.addRect(QtCore.QRectF(5, 6, 20, 30))
|
||||
self.item.draw_debug_shape(
|
||||
painter,
|
||||
path,
|
||||
0, 255, 0)
|
||||
painter.fillPath.assert_called_once()
|
||||
painter.fillRect.assert_not_called()
|
||||
|
||||
@patch('beeref.items.BeePixmapItem.draw_debug_shape')
|
||||
def test_paint_when_not_selected(self, debug_mock):
|
||||
painter = MagicMock()
|
||||
|
|
|
|||
Loading…
Reference in a new issue