generated from neutrons/python_project_template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update tests to get full coverage #17
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Unit test for the garnet.tabs.home.model.home_presenter.py HomePresenter.""" | ||
|
||
import unittest | ||
from typing import Any | ||
from unittest.mock import MagicMock | ||
|
||
# Import the HomePresenter class to be tested | ||
from garnet.home.model import HomeModel | ||
from garnet.home.presenter import HomePresenter | ||
from garnet.home.view import HomeView | ||
|
||
|
||
class TestHomePresenter(unittest.TestCase): | ||
"""Test the HomePresenter class.""" | ||
|
||
def test_init(self: Any) -> None: | ||
"""Test the HomePresenter constructor.""" | ||
mock_view = MagicMock(spec=HomeView) | ||
mock_model = MagicMock(spec=HomeModel) | ||
|
||
presenter = HomePresenter(mock_view, mock_model) | ||
|
||
assert presenter._view is mock_view | ||
assert presenter._model is mock_model | ||
|
||
def test_view_property(self: Any) -> None: | ||
"""Test the view property.""" | ||
mock_view = MagicMock(spec=HomeView) | ||
mock_model = MagicMock(spec=HomeModel) | ||
|
||
presenter = HomePresenter(mock_view, mock_model) | ||
assert presenter.view is mock_view | ||
|
||
def test_model_property(self: Any) -> None: | ||
"""Test the model property.""" | ||
mock_view = MagicMock(spec=HomeView) | ||
mock_model = MagicMock(spec=HomeModel) | ||
|
||
presenter = HomePresenter(mock_view, mock_model) | ||
assert presenter.model is mock_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Test the garnet.garnet.gui function | ||
|
||
This is the entry point for the GUI application. | ||
""" | ||
|
||
import sys | ||
from unittest import mock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from garnet.garnet import gui | ||
|
||
|
||
def test_gui_version(): | ||
"""Test the version flag.""" | ||
t_argv = sys.argv.copy() | ||
sys.argv.append("--version") | ||
with pytest.raises(SystemExit) as excinfo: | ||
gui() | ||
assert excinfo.value.code is None | ||
sys.argv = t_argv | ||
|
||
|
||
@patch("garnet.garnet.QApplication") | ||
@patch("garnet.garnet.Garnet") | ||
def test_gui(mock_garnet: mock, mock_qtapp: mock): | ||
"""Test the GUI entry point.""" | ||
with pytest.raises(SystemExit) as excinfo: | ||
gui() | ||
|
||
assert excinfo.type == SystemExit | ||
assert mock_garnet.called | ||
assert mock_qtapp.called |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Tests for the Logger class in garnet/logger.py.""" | ||
|
||
from garnet.logger import Logger | ||
from mantid.kernel import Logger as mantid_logger # noqa: N813 | ||
|
||
|
||
def test_get_logger(): | ||
"""Test getting the logger.""" | ||
logger_name = "custom_logger" | ||
logger = Logger(logger_name) | ||
logger.get(logger_name) | ||
|
||
# Assert that the returned logger instance is correct | ||
assert isinstance(logger, mantid_logger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can be part of the test /presenter folder?