Skip to content
Merged

Dev #595

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
16 changes: 13 additions & 3 deletions speedwagon/frontend/qtwidgets/dialog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import abc
import logging
import os
import sys
import platform

# This is fine! It's only used to open a settings directory on a mac.
Expand Down Expand Up @@ -162,7 +163,7 @@
).setEnabled(False)

self.button_box.accepted.connect(self.accept) # type: ignore
self.button_box.rejected.connect(self.reject) # type: ignore

Check warning on line 166 in speedwagon/frontend/qtwidgets/dialog/settings.py

View check run for this annotation

Jenkins - UIUCLibrary / Pylint

no-member

HIGH: Method ' ' has no 'connect' member
Raw output
Used when a variable is accessed for an unexistent member.
layout.addWidget(self.button_box)

self.setLayout(layout)
Expand Down Expand Up @@ -216,12 +217,21 @@


class WindowsOpenSettings(AbsOpenSettings):

def __init__(self, settings_directory: str) -> None:
super().__init__(settings_directory)
if sys.platform == "win32":

Check warning on line 223 in speedwagon/frontend/qtwidgets/dialog/settings.py

View check run for this annotation

Jenkins - UIUCLibrary / Code Coverage

Partially covered line

Line 223 is only partially covered, one branch is missing
self.startfile = os.startfile

Check warning on line 224 in speedwagon/frontend/qtwidgets/dialog/settings.py

View check run for this annotation

Jenkins - UIUCLibrary / Code Coverage

Not covered line

Line 224 is not covered by tests
else:
self.startfile =\
lambda _: logger.error(
"os.startfile is for the Windows platform only"
)

def system_open_directory(self, settings_directory: str) -> None:
self.validate_user_option(settings_directory)
# pylint: disable=no-member
os.startfile(
settings_directory
) # type: ignore[attr-defined] # nosec: B606
self.startfile(settings_directory)


DEFAULT_SETTINGS_DIR_STRATEGIES: Dict[str, Type[AbsOpenSettings]] = {
Expand Down
11 changes: 8 additions & 3 deletions speedwagon/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,18 @@ def __init__(self, args: argparse.Namespace) -> None:
report_format=self.args.report_format
)
)
self.exit_strategy: Callable[[], None] = lambda: sys.exit(0)
self.exit_strategy: Callable[[int], None] = sys.exit

def run(self) -> None:
"""Build a system info report and write it to stdout."""
report = self.build_report()
logger.info(report)
self.exit_strategy()
try:
logger.info(report)
sys.stdout.flush()
except BrokenPipeError:
print("Broken pipe")
finally:
self.exit_strategy(0)

def build_report(self) -> str:
"""Build a system info report as a string.
Expand Down
5 changes: 1 addition & 4 deletions tests/frontend/test_qt_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ def test_open_windows_settings(self, monkeypatch):
opening_strategy.validate_user_option = lambda _: None
import os
startfile = Mock()
if platform.system() != "Windows":
setattr(os, "startfile", startfile)
else:
monkeypatch.setattr(os, "startfile", startfile)
opening_strategy.startfile = startfile
opening_strategy.open()
assert startfile.called is True

Expand Down
17 changes: 17 additions & 0 deletions tests/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ def test_build_report_runs_report_builder_strategy(self):
command.build_report()
mock_report_builder_strategy.assert_called_once()

def test_run_calls_exit_strategy(self):
command = speedwagon.startup.InfoCommand(Mock(spec=argparse.Namespace))
command.exit_strategy = Mock(name="exit_strategy")
command.build_report = Mock(return_value="some logging")
command.run()
command.exit_strategy.assert_called_once_with(0)

def test_run_calls_exit_strategy_with_broken_pipe(self, monkeypatch):
command = speedwagon.startup.InfoCommand(Mock(spec=argparse.Namespace))
command.exit_strategy = Mock(name="exit_strategy")
command.build_report = Mock(return_value="some logging")
info = Mock(side_effect=BrokenPipeError)
monkeypatch.setattr(speedwagon.startup.logger, "info", info)
command.run()
info.assert_called_once()
command.exit_strategy.assert_called_once_with(0)

def test_get_global_options():
resolution_order = [
Mock(spec_set=speedwagon.config.config.AbsSetting, update=Mock()),
Expand Down
Loading