Skip to content

Commit

Permalink
Implement the newly introduced BettyQtBot.mouse_click() everywhere (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra authored Feb 22, 2024
1 parent 8f88455 commit 5a9bf6b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
14 changes: 7 additions & 7 deletions betty/tests/extension/cotton_candy/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QColor
from PyQt6.QtWidgets import QColorDialog
from pytest_mock import MockerFixture
Expand All @@ -11,6 +10,7 @@
from betty.locale import Str
from betty.model import Entity, UserFacingEntity
from betty.project import EntityReference
from betty.tests.conftest import BettyQtBot


class TestColorConfigurationWidget:
Expand Down Expand Up @@ -45,15 +45,15 @@ def entity_type_label_plural(cls) -> Str:


class TestCottonCandyGuiWidget:
async def test_add_featured_entities(self, qtbot: QtBot) -> None:
async def test_add_featured_entities(self, betty_qtbot: BettyQtBot) -> None:
async with App() as app:
app.project.configuration.extensions.enable(CottonCandy)
sut = _CottonCandyGuiWidget(app)
qtbot.addWidget(sut)
betty_qtbot.qtbot.addWidget(sut)
sut.show()

entity_id = '123'
qtbot.mouseClick(sut._featured_entities_entity_references_collector._add_entity_reference_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut._featured_entities_entity_references_collector._add_entity_reference_button)
# @todo Find out an elegant way to test changing the entity type.
sut._featured_entities_entity_references_collector._entity_reference_collectors[0]._entity_id.setText(entity_id)
assert app.extensions[CottonCandy].configuration.featured_entities[0].entity_id == entity_id
Expand Down Expand Up @@ -82,7 +82,7 @@ async def test_change_featured_entities(self, qtbot: QtBot) -> None:
sut._featured_entities_entity_references_collector._entity_reference_collectors[1]._entity_id.setText(entity_id)
assert app.extensions[CottonCandy].configuration.featured_entities[1].entity_id == entity_id

async def test_remove_featured_entities(self, qtbot: QtBot) -> None:
async def test_remove_featured_entities(self, betty_qtbot: BettyQtBot) -> None:
async with App() as app:
app.project.configuration.extensions.enable(CottonCandy)
entity_reference_1 = EntityReference[CottonCandyGuiWidgetTestEntity](CottonCandyGuiWidgetTestEntity, '123')
Expand All @@ -98,10 +98,10 @@ async def test_remove_featured_entities(self, qtbot: QtBot) -> None:
entity_reference_3, # type: ignore[arg-type]
)
sut = _CottonCandyGuiWidget(app)
qtbot.addWidget(sut)
betty_qtbot.qtbot.addWidget(sut)
sut.show()

qtbot.mouseClick(sut._featured_entities_entity_references_collector._entity_reference_remove_buttons[1], Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut._featured_entities_entity_references_collector._entity_reference_remove_buttons[1])
assert entity_reference_1 in app.extensions[CottonCandy].configuration.featured_entities
assert entity_reference_2 not in app.extensions[CottonCandy].configuration.featured_entities
assert entity_reference_3 in app.extensions[CottonCandy].configuration.featured_entities
Expand Down
18 changes: 8 additions & 10 deletions betty/tests/extension/gramps/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

from pathlib import Path

from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QFileDialog
from pytest_mock import MockerFixture
from pytestqt.qtbot import QtBot

from betty.app import App
from betty.extension import Gramps
Expand All @@ -26,13 +24,13 @@ async def test_add_family_tree_set_path(
betty_qtbot.qtbot.addWidget(widget)
widget.show()

betty_qtbot.qtbot.mouseClick(widget._family_trees._add_family_tree_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(widget._family_trees._add_family_tree_button)
add_family_tree_window = betty_qtbot.assert_window(_AddFamilyTreeWindow)

file_path = tmp_path / 'family-tree.gpkg'
add_family_tree_window._file_path.setText(str(file_path))

betty_qtbot.qtbot.mouseClick(add_family_tree_window._save_and_close, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(add_family_tree_window._save_and_close)
betty_qtbot.assert_not_window(_AddFamilyTreeWindow)

assert len(sut.configuration.family_trees) == 1
Expand All @@ -52,20 +50,20 @@ async def test_add_family_tree_find_path(
betty_qtbot.qtbot.addWidget(widget)
widget.show()

betty_qtbot.qtbot.mouseClick(widget._family_trees._add_family_tree_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(widget._family_trees._add_family_tree_button)

add_family_tree_window = betty_qtbot.assert_window(_AddFamilyTreeWindow)
file_path = tmp_path / 'family-tree.gpkg'
mocker.patch.object(QFileDialog, 'getOpenFileName', mocker.MagicMock(return_value=[str(file_path), None]))
betty_qtbot.qtbot.mouseClick(add_family_tree_window._file_path_find, Qt.MouseButton.LeftButton)
betty_qtbot.qtbot.mouseClick(add_family_tree_window._save_and_close, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(add_family_tree_window._file_path_find)
betty_qtbot.mouse_click(add_family_tree_window._save_and_close)

assert len(sut.configuration.family_trees) == 1
family_tree = sut.configuration.family_trees[0]
assert family_tree.file_path == file_path


async def test_remove_family_tree(qtbot: QtBot) -> None:
async def test_remove_family_tree(betty_qtbot: BettyQtBot) -> None:
async with App() as app:
app.project.configuration.extensions.append(ExtensionConfiguration(
Gramps,
Expand All @@ -77,10 +75,10 @@ async def test_remove_family_tree(qtbot: QtBot) -> None:
))
sut = app.extensions[Gramps]
widget = sut.gui_build()
qtbot.addWidget(widget)
betty_qtbot.qtbot.addWidget(widget)
widget.show()

qtbot.mouseClick(widget._family_trees._family_trees_remove_buttons[0], Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(widget._family_trees._family_trees_remove_buttons[0])

assert len(sut.configuration.family_trees) == 0
assert [] == widget._family_trees._family_trees_remove_buttons
7 changes: 3 additions & 4 deletions betty/tests/gui/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import aiofiles
import pytest
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QFileDialog
from pytest_mock import MockerFixture
from pytestqt.qtbot import QtBot
Expand Down Expand Up @@ -84,7 +83,7 @@ async def test_open_project_with_invalid_file_should_error(
# Purposefully leave the file empty so it is invalid.
configuration_file_path.write_text('')
mocker.patch.object(QFileDialog, 'getOpenFileName', mocker.MagicMock(return_value=[str(configuration_file_path), None]))
betty_qtbot.qtbot.mouseClick(sut.open_project_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut.open_project_button)

error = betty_qtbot.assert_error(ExceptionError)
assert issubclass(error.error_type, SerdeError)
Expand All @@ -106,7 +105,7 @@ async def test_open_project_with_valid_file_should_show_project_window(
sut.show()

mocker.patch.object(QFileDialog, 'getOpenFileName', mocker.MagicMock(return_value=[str(configuration.configuration_file_path), None]))
betty_qtbot.qtbot.mouseClick(sut.open_project_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut.open_project_button)

window = betty_qtbot.assert_window(ProjectWindow)
assert window._app.project.configuration.title == title
Expand All @@ -124,7 +123,7 @@ async def test_view_demo_site(
betty_qtbot.qtbot.addWidget(sut)
sut.show()

betty_qtbot.qtbot.mouseClick(sut.demo_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut.demo_button)

betty_qtbot.assert_window(ServeDemoWindow)

Expand Down
17 changes: 7 additions & 10 deletions betty/tests/gui/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,22 @@ async def test_add_locale(self, betty_qtbot: BettyQtBot) -> None:
betty_qtbot.qtbot.addWidget(sut)
sut.show()

betty_qtbot.qtbot.mouseClick(sut._add_locale_button, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut._add_locale_button)
betty_qtbot.assert_window(_AddLocaleWindow)

async def test_remove_locale(self, qtbot: QtBot) -> None:
async def test_remove_locale(self, betty_qtbot: BettyQtBot) -> None:
locale = 'de-DE'
async with App() as app:
app.project.configuration.locales.append(
LocaleConfiguration('nl-NL'),
LocaleConfiguration(locale),
)
sut = _LocalizationPane(app)
qtbot.addWidget(sut)
betty_qtbot.qtbot.addWidget(sut)
sut.show()
widget = sut._locales_configuration_widget
assert widget is not None
qtbot.mouseClick(
widget._remove_buttons[locale],
Qt.MouseButton.LeftButton
)
betty_qtbot.mouse_click(widget._remove_buttons[locale])

assert locale not in app.project.configuration.locales

Expand Down Expand Up @@ -249,7 +246,7 @@ async def test_without_alias(
locale = 'nl-NL'
sut._locale_collector.locale.setCurrentText(get_display_name(locale))

betty_qtbot.qtbot.mouseClick(sut._save_and_close, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut._save_and_close)
betty_qtbot.assert_not_window(sut)

assert locale in sut._app.project.configuration.locales
Expand All @@ -269,7 +266,7 @@ async def test_with_valid_alias(
sut._locale_collector.locale.setCurrentText(get_display_name(locale))
sut._alias.setText(alias)

betty_qtbot.qtbot.mouseClick(sut._save_and_close, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut._save_and_close)
betty_qtbot.assert_not_window(sut)

assert locale in sut._app.project.configuration.locales
Expand All @@ -289,7 +286,7 @@ async def test_with_invalid_alias(
sut._locale_collector.locale.setCurrentText(get_display_name(locale))
sut._alias.setText(alias)

betty_qtbot.qtbot.mouseClick(sut._save_and_close, Qt.MouseButton.LeftButton)
betty_qtbot.mouse_click(sut._save_and_close)

betty_qtbot.assert_window(sut)
betty_qtbot.assert_invalid(sut._alias)

0 comments on commit 5a9bf6b

Please sign in to comment.