Skip to content

Commit

Permalink
Merge from 3.x: PR #6137
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jan 17, 2018
2 parents 336a406 + 6d896f5 commit 74576d1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions spyder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
__license__ = __doc__
__project_url__ = 'https://github.com/spyder-ide/spyder'
__forum_url__ = 'http://groups.google.com/group/spyderlib'
__trouble_url__ = __project_url__ + '/wiki/Troubleshooting-Guide-and-FAQ'

# Dear (Debian, RPM, ...) package makers, please feel free to customize the
# following path to module's data (images) and translations:
Expand Down
33 changes: 23 additions & 10 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
#==============================================================================
# Local utility imports
#==============================================================================
from spyder import __version__, __project_url__, __forum_url__, get_versions
from spyder import (__version__, __project_url__, __forum_url__,
__trouble_url__, get_versions)
from spyder.config.base import (get_conf_path, get_module_data_path,
get_module_source_path, STDERR, DEBUG,
debug_print, MAC_APP_NAME, get_home_dir,
Expand Down Expand Up @@ -947,6 +948,9 @@ def create_edit_action(text, tr_text, icon):
self.set_splash(_("Setting up main window..."))

# Help menu
trouble_action = create_action(self,
_("Troubleshooting..."),
triggered=self.trouble_guide)
dep_action = create_action(self, _("Dependencies..."),
triggered=self.show_dependencies,
icon=ima.icon('advanced'))
Expand Down Expand Up @@ -1021,7 +1025,8 @@ def trigger(i=i, self=self): # closure needed!

self.help_menu_actions = [doc_action, tut_action, shortcuts_action,
self.tours_menu,
MENU_SEPARATOR, report_action, dep_action,
MENU_SEPARATOR, trouble_action,
report_action, dep_action,
self.check_updates_action, support_action,
MENU_SEPARATOR]
# Python documentation
Expand Down Expand Up @@ -2345,9 +2350,10 @@ def about(self):
<br>Developed and maintained by the
<a href="%s/blob/master/AUTHORS">Spyder Project Contributors</a>.
<br>Many thanks to all the Spyder beta testers and regular users.
<p>For bug reports and feature requests, please go
to our <a href="%s">Github website</a>. For discussions around the
project, please go to our <a href="%s">Google Group</a>
<p>For help with Spyder errors and crashes, please read our
<a href="%s">Troubleshooting page</a>, and for bug reports and
feature requests, visit our <a href="%s">Github website</a>.
For project discussion, see our <a href="%s">Google Group</a>.
<p>This project is part of a larger effort to promote and
facilitate the use of Python for scientific and engineering
software development. The popular Python distributions
Expand All @@ -2363,7 +2369,7 @@ def about(self):
<a href="http://www.oxygen-icons.org/">
The Oxygen icon theme</a></small>.
"""
% (versions['spyder'], revlink, __project_url__,
% (versions['spyder'], revlink, __project_url__, __trouble_url__,
__project_url__, __forum_url__, versions['python'],
versions['bitness'], versions['qt'], versions['qt_api'],
versions['qt_api_ver'], versions['system']))
Expand Down Expand Up @@ -2453,6 +2459,9 @@ def report_issue(self, body=None, title=None):
if title:
url.addEncodedQueryItem("title", quote(title))

@Slot()
def trouble_guide(self):
url = QUrl(__trouble_url__)
QDesktopServices.openUrl(url)

@Slot()
Expand Down Expand Up @@ -3119,7 +3128,8 @@ def main():
CONF.set('main', 'crash', False)
if SPLASH is not None:
SPLASH.hide()
QMessageBox.information(None, "Spyder",
QMessageBox.information(
None, "Spyder",
"Spyder crashed during last session.<br><br>"
"If Spyder does not start at all and <u>before submitting a "
"bug report</u>, please try to reset settings to defaults by "
Expand All @@ -3129,12 +3139,15 @@ def main():
"<span style=\'color: #ff5555\'><b>Warning:</b></span> "
"this command will remove all your Spyder configuration files "
"located in '%s').<br><br>"
"If restoring the default settings does not help, please take "
"If Spyder still fails to launch, you should consult our "
"comprehensive <b><a href=\"%s\">Troubleshooting Guide</a></b>, "
"which when followed carefully solves the vast majority of "
"crashes; also, take "
"the time to search for <a href=\"%s\">known bugs</a> or "
"<a href=\"%s\">discussions</a> matching your situation before "
"eventually creating a new issue <a href=\"%s\">here</a>. "
"submitting a report to our <a href=\"%s\">issue tracker</a>. "
"Your feedback will always be greatly appreciated."
"" % (get_conf_path(), __project_url__,
"" % (get_conf_path(), __trouble_url__, __project_url__,
__forum_url__, __project_url__))

# Create main window
Expand Down
43 changes: 42 additions & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from sys import version_info
import shutil
import tempfile
try:
from unittest.mock import Mock, MagicMock
except ImportError:
from mock import Mock, MagicMock # Python 2

from flaky import flaky
from jupyter_client.manager import KernelManager
Expand All @@ -24,15 +28,24 @@
from qtpy.QtTest import QTest
from qtpy.QtWidgets import QApplication, QFileDialog, QLineEdit

from spyder import __trouble_url__
from spyder.app.cli_options import get_options
from spyder.app.mainwindow import initialize, run_spyder
from spyder.app.mainwindow import initialize, run_spyder, MainWindow
from spyder.config.base import get_home_dir
from spyder.config.main import CONF
from spyder.plugins.runconfig import RunConfiguration
from spyder.py3compat import PY2, to_text_string
from spyder.utils.ipython.kernelspec import SpyderKernelSpec
from spyder.utils.programs import is_module_installed

# For testing various Spyder urls
if not PY2:
from urllib.request import urlopen
from urllib.error import URLError
else:
from urllib2 import urlopen, URLError


#==============================================================================
# Constants
#==============================================================================
Expand Down Expand Up @@ -1142,5 +1155,33 @@ def test_run_static_code_analysis(main_window, qtbot):
main_window.editor.close_file()


@flaky(max_runs=3)
def test_troubleshooting_menu_item_and_url(monkeypatch):
"""Test that the troubleshooting menu item calls the valid URL."""
MockMainWindow = MagicMock(spec=MainWindow)
mockMainWindow_instance = MockMainWindow()
mockMainWindow_instance.__class__ = MainWindow
MockQDesktopServices = Mock()
mockQDesktopServices_instance = MockQDesktopServices()
attr_to_patch = ('spyder.app.mainwindow.QDesktopServices')
monkeypatch.setattr(attr_to_patch, MockQDesktopServices)

# Unit test of help menu item: Make sure the correct URL is called.
MainWindow.trouble_guide(mockMainWindow_instance)
assert MockQDesktopServices.openUrl.call_count == 1
mockQDesktopServices_instance.openUrl.called_once_with(__trouble_url__)

# Check that the URL resolves correctly. Ignored if no internet connection.
try:
urlopen("https://www.github.com", timeout=1)
except Exception:
pass
else:
try:
urlopen(__trouble_url__, timeout=1)
except URLError:
raise


if __name__ == "__main__":
pytest.main()

0 comments on commit 74576d1

Please sign in to comment.