Skip to content
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

Configuration Initialization moved to shiver.py #106

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/shiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import shiver.models.makeslice # noqa: F401 pylint: disable=unused-import
import shiver.models.convert_dgs_to_single_mde # noqa: F401 pylint: disable=unused-import
import shiver.models.generate_dgs_mde # noqa: F401 pylint: disable=unused-import
from shiver.configuration import Configuration
from .version import __version__

# make sure matplotlib is correctly set before we import shiver
Expand All @@ -32,17 +31,6 @@ def main():
"""
Main entry point for Qt application
"""
config = Configuration()
if not config.is_valid():
msg = (
"Error with configuration settings!",
f"Check and update your file: {config.config_file_path}",
"with the latest settings found here:",
f"{config.template_file_path} and start the application again.",
)

print(" ".join(msg))
return
app = QApplication(sys.argv)
window = Shiver()
window.show()
Expand Down
12 changes: 12 additions & 0 deletions src/shiver/shiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from qtpy.QtWidgets import QMainWindow
from shiver.configuration import Configuration
from shiver.version import __version__
from shiver.views.mainwindow import MainWindow

Expand All @@ -19,6 +20,17 @@ def __new__(cls):

def __init__(self, parent=None):
super().__init__(parent)
config = Configuration()
if not config.is_valid():
msg = (
"Error with configuration settings!",
f"Check and update your file: {config.config_file_path}",
"with the latest settings found here:",
f"{config.template_file_path} and start the application again.",
)

print(" ".join(msg))
return
self.setWindowTitle(f"SHIVER - {__version__}")
self.main_window = MainWindow(self)
self.setCentralWidget(self.main_window)
9 changes: 7 additions & 2 deletions tests/models/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pathlib import Path

import pytest
from shiver import main
from qtpy.QtWidgets import QApplication
from shiver.shiver import Shiver
from shiver.configuration import Configuration, get_data


Expand Down Expand Up @@ -194,6 +195,8 @@ def test_get_data_invalid(monkeypatch, user_conf_file):
def test_conf_init_invalid(capsys, user_conf_file, monkeypatch):
"""Test starting the app with invalid configuration"""

# initialization
_ = QApplication([])
# mock conf info
monkeypatch.setattr("shiver.configuration.CONFIG_PATH_FILE", user_conf_file)

Expand All @@ -202,6 +205,8 @@ def mock_is_valid(self): # pylint: disable=unused-argument

monkeypatch.setattr("shiver.configuration.Configuration.is_valid", mock_is_valid)

main()
shiver = Shiver()
shiver.show()

captured = capsys.readouterr()
assert captured[0].startswith("Error with configuration settings!")
Loading