Skip to content

Commit

Permalink
Merge from 3.x: PR #6540
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Mar 3, 2018
2 parents 6aeade9 + 715b099 commit ed16d88
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
10 changes: 5 additions & 5 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@
#==============================================================================
# Create splash screen out of MainWindow to reduce perceived startup time.
#==============================================================================
from spyder.config.base import _, get_image_path, DEV, PYTEST
from spyder.config.base import _, get_image_path, DEV, running_under_pytest

if not PYTEST:
if not running_under_pytest():
SPLASH = QSplashScreen(QPixmap(get_image_path('splash.svg')))
SPLASH_FONT = SPLASH.font()
SPLASH_FONT.setPixelSize(10)
Expand Down Expand Up @@ -450,7 +450,7 @@ def signal_handler(signum, frame=None):
self.layout_toolbar = None
self.layout_toolbar_actions = []

if PYTEST:
if running_under_pytest():
# Show errors in internal console when testing.
CONF.set('main', 'show_internal_errors', False)

Expand Down Expand Up @@ -3110,7 +3110,7 @@ def run_spyder(app, options, args):
# the window
app.focusChanged.connect(main.change_last_focused_widget)

if not PYTEST:
if not running_under_pytest():
app.exec_()
return main

Expand All @@ -3120,7 +3120,7 @@ def run_spyder(app, options, args):
#==============================================================================
def main():
"""Main function"""
if PYTEST:
if running_under_pytest():
try:
from unittest.mock import Mock
except ImportError:
Expand Down
11 changes: 6 additions & 5 deletions spyder/app/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

# Local imports
from spyder.app.cli_options import get_options
from spyder.config.base import PYTEST, get_conf_path, running_in_mac_app
from spyder.config.base import (get_conf_path, running_in_mac_app,
running_under_pytest)
from spyder.config.main import CONF
from spyder.utils.external import lockfile
from spyder.py3compat import is_unicode
Expand Down Expand Up @@ -64,7 +65,7 @@ def main():
options to the application.
"""
# Parse command line options
if PYTEST:
if running_under_pytest():
try:
from unittest.mock import Mock
except ImportError:
Expand Down Expand Up @@ -146,7 +147,7 @@ def main():
# executing this script because it doesn't make
# sense
from spyder.app import mainwindow
if PYTEST:
if running_under_pytest():
return mainwindow.main()
else:
mainwindow.main()
Expand All @@ -155,7 +156,7 @@ def main():
if lock_created:
# Start a new instance
from spyder.app import mainwindow
if PYTEST:
if running_under_pytest():
return mainwindow.main()
else:
mainwindow.main()
Expand All @@ -169,7 +170,7 @@ def main():
"instance, please pass to it the --new-instance option")
else:
from spyder.app import mainwindow
if PYTEST:
if running_under_pytest():
return mainwindow.main()
else:
mainwindow.main()
Expand Down
17 changes: 11 additions & 6 deletions spyder/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
TEST = os.environ.get('SPYDER_TEST')


# To do some adjustments for pytest
# This env var is defined in runtests.py
PYTEST = os.environ.get('SPYDER_PYTEST')
def running_under_pytest():
"""
Return True if currently running under py.test.
This function is used to do some adjustment for testing. The environment
variable SPYDER_PYTEST is defined in conftest.py.
"""
return bool(os.environ.get('SPYDER_PYTEST'))


#==============================================================================
Expand Down Expand Up @@ -119,7 +124,7 @@ def get_home_dir():
def get_conf_path(filename=None):
"""Return absolute path for configuration file with specified filename"""
# Define conf_dir
if PYTEST:
if running_under_pytest():
import py
from _pytest.tmpdir import get_user
conf_dir = osp.join(str(py.path.local.get_temproot()),
Expand All @@ -139,7 +144,7 @@ def get_conf_path(filename=None):

# Create conf_dir
if not osp.isdir(conf_dir):
if PYTEST:
if running_under_pytest():
os.makedirs(conf_dir)
else:
os.mkdir(conf_dir)
Expand Down Expand Up @@ -295,7 +300,7 @@ def get_interface_language():
locale_language = DEFAULT_LANGUAGE

# Tests expect English as the interface language
if PYTEST:
if running_under_pytest():
locale_language = DEFAULT_LANGUAGE

language = DEFAULT_LANGUAGE
Expand Down
11 changes: 7 additions & 4 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

# Local imports
from spyder import dependencies
from spyder.config.base import _, get_conf_path, PYTEST, debug_print
from spyder.config.base import (_, debug_print, get_conf_path,
running_under_pytest)
from spyder.config.main import (CONF, RUN_CELL_SHORTCUT,
RUN_CELL_AND_ADVANCE_SHORTCUT)
from spyder.config.utils import (get_edit_filetypes, get_edit_filters,
Expand Down Expand Up @@ -483,7 +484,8 @@ def __init__(self, parent, ignore_last_opened_files=False):

# Don't start IntrospectionManager when running tests because
# it consumes a lot of memory
if PYTEST and not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
if (running_under_pytest()
and not os.environ.get('SPY_TEST_USE_INTROSPECTION')):
try:
from unittest.mock import Mock
except ImportError:
Expand Down Expand Up @@ -2013,7 +2015,7 @@ def load(self, filenames=None, goto=None, word='', editorwindow=None,
osp.splitext(filename0)[1])
else:
selectedfilter = ''
if not PYTEST:
if not running_under_pytest():
filenames, _sf = getopenfilenames(
parent_widget,
_("Open file"), basedir,
Expand Down Expand Up @@ -2522,7 +2524,8 @@ def run_file(self, debug=False):
if self.dialog_size is not None:
dialog.resize(self.dialog_size)
dialog.setup(fname)
if CONF.get('run', 'open_at_least_once', not PYTEST):
if CONF.get('run', 'open_at_least_once',
not running_under_pytest()):
# Open Run Config dialog at least once: the first time
# a script is ever run in Spyder, so that the user may
# see it at least once and be conscious that it exists
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Local imports
from spyder import dependencies
from spyder.config.base import (_, DEV, get_conf_path, get_home_dir,
get_module_path, PYTEST)
get_module_path, running_under_pytest)
from spyder.config.main import CONF
from spyder.api.plugins import SpyderPluginWidget
from spyder.api.preferences import PluginConfigPage
Expand Down Expand Up @@ -1093,7 +1093,7 @@ def set_editor(self):
import1 = "import sys"
# We need to add spy_dir to sys.path so this test can be
# run in our CIs
if PYTEST:
if running_under_pytest():
if os.name == 'nt':
import1 = (import1 +
'; sys.path.append(""{}"")'.format(spy_dir))
Expand Down
4 changes: 2 additions & 2 deletions spyder/utils/external/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from time import time as _uniquefloat

import psutil
from spyder.config.base import PYTEST
from spyder.config.base import running_under_pytest
from spyder.py3compat import PY2, to_binary_string

def unique():
Expand Down Expand Up @@ -185,7 +185,7 @@ def lock(self):

# Valid names for main script
names = set(['spyder', 'spyder3', 'bootstrap.py'])
if PYTEST:
if running_under_pytest():
names.add('runtests.py')

# Check the first three command line arguments
Expand Down
4 changes: 2 additions & 2 deletions spyder/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
QVBoxLayout, QWidget, QListWidget, QListWidgetItem)

# Local imports
from spyder.config.base import _, DEBUG, PYTEST, STDERR, STDOUT
from spyder.config.base import _, DEBUG, STDERR, STDOUT, running_under_pytest
from spyder.config.gui import config_shortcut, get_shortcut
from spyder.config.utils import (get_edit_filetypes, get_edit_filters,
get_filter, is_kde_desktop, is_anaconda)
Expand Down Expand Up @@ -609,7 +609,7 @@ def __init__(self, parent, actions):
self.edit_filters = None

# For testing
self.save_dialog_on_tests = not PYTEST
self.save_dialog_on_tests = not running_under_pytest()

@Slot()
def show_in_external_file_explorer(self, fnames=None):
Expand Down

0 comments on commit ed16d88

Please sign in to comment.