Skip to content

Commit

Permalink
WIP use original QgsMessageBar as base class [GispoCoding#24]
Browse files Browse the repository at this point in the history
  • Loading branch information
Joonalai committed Nov 27, 2023
1 parent aa9c3b5 commit 7c9f179
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/pytest_qgis/mock_qgis_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#
# You should have received a copy of the GNU General Public License
# along with pytest-qgis. If not, see <https://www.gnu.org/licenses/>.


import typing
from typing import Dict, List

from qgis import _core
from qgis.core import Qgis
from qgis.gui import QgsMessageBar as QgsMessageBarOriginal
from qgis.PyQt.QtCore import QObject


class MockMessageBar(QObject):
class MockMessageBar(QgsMessageBarOriginal):
"""Mocked message bar to hold the messages."""

def __init__(self) -> None:
Expand All @@ -39,9 +40,23 @@ def get_messages(self, level: int) -> List[str]:
"""Used to test which messages have been logged."""
return self.messages[level]

def pushMessage( # noqa: N802
self, title: str, text: str, level: int, duration: int
) -> None:
"""A mocked method for pushing a message to the bar."""
msg = f"{title}:{text}"
self.messages[level].append(msg)
@typing.overload
def pushMessage(self, text: typing.Optional[str], level: _core.Qgis.MessageLevel = ..., duration: int = ...) -> None: ...

@typing.overload
def pushMessage(self, title: typing.Optional[str], text: typing.Optional[str], level: _core.Qgis.MessageLevel = ..., duration: int = ...) -> None: ...

@typing.overload
def pushMessage(self, title: typing.Optional[str], text: typing.Optional[str], showMore: typing.Optional[str], level: _core.Qgis.MessageLevel = ..., duration: int = ...) -> None: ...

def pushMessage(self, text: typing.Optional[str], level: _core.Qgis.MessageLevel = ...,
duration: int = ...) -> None:
super().pushMessage(text, level, duration)

# def pushMessage( # noqa: N802
# self, title: str, text: str, level: int, duration: int
# ) -> None:
# """A mocked method for pushing a message to the bar."""
# msg = f"{title}:{text}"
# self.messages[level].append(msg)

0 comments on commit 7c9f179

Please sign in to comment.