16
16
import ipykernel
17
17
from pygments .token import Name
18
18
import pytest
19
- from qtpy import PYQT4 , PYQT5 , PYQT_VERSION
20
- from qtpy .QtCore import Qt , QTimer
21
- from qtpy .QtWidgets import QApplication
19
+ from qtpy import PYQT4 , PYQT5
20
+ from qtpy .QtCore import Qt
22
21
import zmq
23
22
24
23
from spyder .config .gui import get_color_scheme
25
24
from spyder .config .main import CONF
26
- from spyder .py3compat import PY2 , PY3
27
- from spyder .plugins .ipythonconsole import (IPythonConsole ,
28
- KernelConnectionDialog )
29
- from spyder .utils .environ import listdict2envdict
25
+ from spyder .py3compat import PY2 , to_text_string
26
+ from spyder .plugins .ipythonconsole import IPythonConsole
30
27
from spyder .utils .ipython .style import create_style_class
31
28
from spyder .utils .programs import TEMPDIR
32
- from spyder .utils .test import close_message_box
33
- from spyder .widgets .variableexplorer .collectionseditor import CollectionsEditor
34
29
35
30
36
31
#==============================================================================
44
39
#==============================================================================
45
40
# Utillity Functions
46
41
#==============================================================================
47
- def open_client_from_connection_info (connection_info , qtbot ):
48
- top_level_widgets = QApplication .topLevelWidgets ()
49
- for w in top_level_widgets :
50
- if isinstance (w , KernelConnectionDialog ):
51
- w .cf .setText (connection_info )
52
- qtbot .keyClick (w , Qt .Key_Enter )
53
-
54
42
def get_console_font_color (syntax_style ):
55
43
styles = create_style_class (syntax_style ).styles
56
44
font_color = styles [Name ]
57
-
58
45
return font_color
59
46
47
+
60
48
def get_console_background_color (style_sheet ):
61
49
background_color = style_sheet .split ('background-color:' )[1 ]
62
50
background_color = background_color .split (';' )[0 ]
63
51
return background_color
64
52
53
+
65
54
#==============================================================================
66
55
# Qt Test Fixtures
67
56
#==============================================================================
@@ -137,7 +126,6 @@ def test_auto_backend(ipyconsole, qtbot):
137
126
138
127
@pytest .mark .slow
139
128
@flaky (max_runs = 3 )
140
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
141
129
def test_tab_rename_for_slaves (ipyconsole , qtbot ):
142
130
"""Test slave clients are renamed correctly."""
143
131
# Wait until the window is fully up
@@ -159,9 +147,11 @@ def test_tab_rename_for_slaves(ipyconsole, qtbot):
159
147
160
148
@pytest .mark .slow
161
149
@flaky (max_runs = 3 )
162
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
163
150
def test_no_repeated_tabs_name (ipyconsole , qtbot ):
164
151
"""Test that tabs can't have repeated given names."""
152
+ shell = ipyconsole .get_current_shellwidget ()
153
+ qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
154
+
165
155
# Rename first client
166
156
ipyconsole .rename_tabs_after_change ('foo' )
167
157
@@ -176,9 +166,11 @@ def test_no_repeated_tabs_name(ipyconsole, qtbot):
176
166
177
167
@pytest .mark .slow
178
168
@flaky (max_runs = 3 )
179
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
180
169
def test_tabs_preserve_name_after_move (ipyconsole , qtbot ):
181
170
"""Test that tabs preserve their names after they are moved."""
171
+ shell = ipyconsole .get_current_shellwidget ()
172
+ qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
173
+
182
174
# Create a new client
183
175
ipyconsole .create_new_client ()
184
176
@@ -192,7 +184,6 @@ def test_tabs_preserve_name_after_move(ipyconsole, qtbot):
192
184
193
185
@pytest .mark .slow
194
186
@flaky (max_runs = 3 )
195
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
196
187
def test_conf_env_vars (ipyconsole , qtbot ):
197
188
"""Test that kernels have env vars set by our kernel spec."""
198
189
# Wait until the window is fully up
@@ -210,7 +201,6 @@ def test_conf_env_vars(ipyconsole, qtbot):
210
201
211
202
@pytest .mark .slow
212
203
@flaky (max_runs = 3 )
213
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
214
204
@pytest .mark .no_stderr_file
215
205
def test_no_stderr_file (ipyconsole , qtbot ):
216
206
"""Test that consoles can run without an stderr."""
@@ -230,7 +220,7 @@ def test_no_stderr_file(ipyconsole, qtbot):
230
220
@pytest .mark .slow
231
221
@pytest .mark .non_ascii_dir
232
222
@flaky (max_runs = 3 )
233
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
223
+ @pytest .mark .skipif (os .name == 'nt' , reason = "It fails on Windows" )
234
224
def test_non_ascii_stderr_file (ipyconsole , qtbot ):
235
225
"""Test the creation of a console with a stderr file in a non-ascii dir."""
236
226
# Wait until the window is fully up
@@ -248,7 +238,6 @@ def test_non_ascii_stderr_file(ipyconsole, qtbot):
248
238
249
239
@pytest .mark .slow
250
240
@flaky (max_runs = 3 )
251
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out sometimes on Windows" )
252
241
def test_console_import_namespace (ipyconsole , qtbot ):
253
242
"""Test an import of the form 'from foo import *'."""
254
243
# Wait until the window is fully up
@@ -267,6 +256,9 @@ def test_console_import_namespace(ipyconsole, qtbot):
267
256
@flaky (max_runs = 3 )
268
257
def test_console_disambiguation (ipyconsole , qtbot ):
269
258
"""Test the disambiguation of dedicated consoles."""
259
+ shell = ipyconsole .get_current_shellwidget ()
260
+ qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
261
+
270
262
# Create directories and file for TEMP_DIRECTORY/a/b/c.py
271
263
# and TEMP_DIRECTORY/a/d/c.py
272
264
dir_b = osp .join (TEMP_DIRECTORY , 'a' , 'b' )
@@ -301,6 +293,9 @@ def test_console_disambiguation(ipyconsole, qtbot):
301
293
@pytest .mark .slow
302
294
@flaky (max_runs = 3 )
303
295
def test_console_coloring (ipyconsole , qtbot ):
296
+ """Test that console gets the same coloring present in the Editor."""
297
+ shell = ipyconsole .get_current_shellwidget ()
298
+ qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
304
299
305
300
config_options = ipyconsole .config_options ()
306
301
@@ -325,10 +320,8 @@ def test_console_coloring(ipyconsole, qtbot):
325
320
326
321
@pytest .mark .slow
327
322
@flaky (max_runs = 3 )
328
- @pytest .mark .skipif (os .name == 'nt' or PYQT4 ,
329
- reason = "It doesn't work on Windows and segfaults in PyQt4" )
330
323
def test_get_env (ipyconsole , qtbot ):
331
- """Test that showing env var contents is working as expected."""
324
+ """Test that getting env vars from the kernel is working as expected."""
332
325
shell = ipyconsole .get_current_shellwidget ()
333
326
qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
334
327
@@ -337,55 +330,43 @@ def test_get_env(ipyconsole, qtbot):
337
330
shell .execute ("import os; os.environ['FOO'] = 'bar'" )
338
331
339
332
# Ask for os.environ contents
340
- with qtbot .waitSignal (shell .sig_show_env ):
333
+ with qtbot .waitSignal (shell .sig_show_env ) as blocker :
341
334
shell .get_env ()
342
335
343
- # Get env contents from the generated widget
344
- top_level_widgets = QApplication .topLevelWidgets ()
345
- for w in top_level_widgets :
346
- if isinstance (w , CollectionsEditor ):
347
- env_contents = w .get_value ()
348
- qtbot .keyClick (w , Qt .Key_Enter )
336
+ # Get env contents from the signal
337
+ env_contents = blocker .args [0 ]
349
338
350
339
# Assert that our added entry is part of os.environ
351
- env_contents = listdict2envdict (env_contents )
352
340
assert env_contents ['FOO' ] == 'bar'
353
341
354
342
355
343
@pytest .mark .slow
356
344
@flaky (max_runs = 3 )
357
- @pytest .mark .skipif (os .name == 'nt' or PYQT4 ,
358
- reason = "It doesn't work on Windows and segfaults in PyQt4" )
359
- def test_get_syspath (ipyconsole , qtbot ):
360
- """Test that showing sys.path contents is working as expected."""
345
+ @pytest .mark .skipif (os .name == 'nt' ,
346
+ reason = "Fails due to differences in path handling" )
347
+ def test_get_syspath (ipyconsole , qtbot , tmpdir ):
348
+ """
349
+ Test that getting sys.path contents from the kernel is working as
350
+ expected.
351
+ """
361
352
shell = ipyconsole .get_current_shellwidget ()
362
353
qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
363
354
364
355
# Add a new entry to sys.path
365
356
with qtbot .waitSignal (shell .executed ):
366
- tmp_dir = tempfile . mkdtemp ( )
367
- shell .execute ("import sys, tempfile ; sys.path.append('%s')" % tmp_dir )
357
+ tmp_dir = to_text_string ( tmpdir )
358
+ shell .execute ("import sys; sys.path.append('%s')" % tmp_dir )
368
359
369
360
# Ask for sys.path contents
370
- with qtbot .waitSignal (shell .sig_show_syspath ):
361
+ with qtbot .waitSignal (shell .sig_show_syspath ) as blocker :
371
362
shell .get_syspath ()
372
363
373
- # Get sys.path contents from the generated widget
374
- top_level_widgets = QApplication .topLevelWidgets ()
375
- for w in top_level_widgets :
376
- if isinstance (w , CollectionsEditor ):
377
- syspath_contents = w .get_value ()
378
- qtbot .keyClick (w , Qt .Key_Enter )
364
+ # Get sys.path contents from the signal
365
+ syspath_contents = blocker .args [0 ]
379
366
380
367
# Assert that our added entry is part of sys.path
381
368
assert tmp_dir in syspath_contents
382
369
383
- # Remove temporary directory
384
- try :
385
- os .rmdir (tmp_dir )
386
- except :
387
- pass
388
-
389
370
390
371
@pytest .mark .slow
391
372
@flaky (max_runs = 10 )
@@ -423,8 +404,7 @@ def test_browse_history_dbg(ipyconsole, qtbot):
423
404
424
405
@pytest .mark .slow
425
406
@flaky (max_runs = 3 )
426
- @pytest .mark .skipif (os .name == 'nt' or PY2 ,
427
- reason = "It times out sometimes on Windows and doesn't work on PY2" )
407
+ @pytest .mark .skipif (PY2 , reason = "It doesn't work on PY2" )
428
408
def test_unicode_vars (ipyconsole , qtbot ):
429
409
"""
430
410
Test that the Variable Explorer Works with unicode variables.
@@ -546,7 +526,6 @@ def test_plot_magic_dbg(ipyconsole, qtbot):
546
526
547
527
@pytest .mark .slow
548
528
@flaky (max_runs = 3 )
549
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out on Windows" )
550
529
def test_run_doctest (ipyconsole , qtbot ):
551
530
"""
552
531
Test that doctests can be run without problems
@@ -684,8 +663,6 @@ def test_clear_and_reset_magics_dbg(ipyconsole, qtbot):
684
663
685
664
@pytest .mark .slow
686
665
@flaky (max_runs = 3 )
687
- @pytest .mark .skipif (os .name == 'nt' or PYQT4 ,
688
- reason = "It doesn't work on Windows and segfaults in PyQt4" )
689
666
def test_restart_kernel (ipyconsole , qtbot ):
690
667
"""
691
668
Test that kernel is restarted correctly
@@ -700,17 +677,15 @@ def test_restart_kernel(ipyconsole, qtbot):
700
677
701
678
# Restart kernel and wait until it's up again
702
679
shell ._prompt_html = None
703
- QTimer .singleShot (1000 , lambda : close_message_box (qtbot ))
704
680
client .restart_kernel ()
705
681
qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
706
682
683
+ assert 'Restarting kernel...' in shell ._control .toPlainText ()
707
684
assert not shell .is_defined ('a' )
708
685
709
686
710
687
@pytest .mark .slow
711
688
@flaky (max_runs = 3 )
712
- @pytest .mark .skipif (os .name == 'nt' or PYQT4 ,
713
- reason = "It doesn't work on Windows and segfaults in PyQt4" )
714
689
def test_load_kernel_file_from_id (ipyconsole , qtbot ):
715
690
"""
716
691
Test that a new client is created using its id
@@ -722,9 +697,7 @@ def test_load_kernel_file_from_id(ipyconsole, qtbot):
722
697
connection_file = osp .basename (client .connection_file )
723
698
id_ = connection_file .split ('kernel-' )[- 1 ].split ('.json' )[0 ]
724
699
725
- QTimer .singleShot (2000 , lambda : open_client_from_connection_info (
726
- id_ , qtbot ))
727
- ipyconsole .create_client_for_kernel ()
700
+ ipyconsole ._create_client_for_kernel (id_ , None , None , None )
728
701
qtbot .wait (1000 )
729
702
730
703
new_client = ipyconsole .get_clients ()[1 ]
@@ -733,9 +706,7 @@ def test_load_kernel_file_from_id(ipyconsole, qtbot):
733
706
734
707
@pytest .mark .slow
735
708
@flaky (max_runs = 3 )
736
- @pytest .mark .skipif (os .name == 'nt' or PYQT4 ,
737
- reason = "It segfaults frequently" )
738
- def test_load_kernel_file_from_location (ipyconsole , qtbot ):
709
+ def test_load_kernel_file_from_location (ipyconsole , qtbot , tmpdir ):
739
710
"""
740
711
Test that a new client is created using a connection file
741
712
placed in a different location from jupyter_runtime_dir
@@ -744,24 +715,19 @@ def test_load_kernel_file_from_location(ipyconsole, qtbot):
744
715
client = ipyconsole .get_current_client ()
745
716
qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
746
717
747
- connection_file = osp .join ( tempfile . gettempdir (),
748
- osp . basename ( client . connection_file ))
718
+ fname = osp .basename ( client . connection_file )
719
+ connection_file = to_text_string ( tmpdir . join ( fname ))
749
720
shutil .copy2 (client .connection_file , connection_file )
750
721
751
- QTimer .singleShot (2000 , lambda : open_client_from_connection_info (
752
- connection_file ,
753
- qtbot ))
754
- ipyconsole .create_client_for_kernel ()
722
+ ipyconsole ._create_client_for_kernel (connection_file , None , None , None )
755
723
qtbot .wait (1000 )
756
724
757
725
assert len (ipyconsole .get_clients ()) == 2
758
726
759
727
760
728
@pytest .mark .slow
761
729
@flaky (max_runs = 3 )
762
- @pytest .mark .skipif (os .name == 'nt' or PYQT4 ,
763
- reason = "It segfaults frequently" )
764
- def test_load_kernel_file (ipyconsole , qtbot ):
730
+ def test_load_kernel_file (ipyconsole , qtbot , tmpdir ):
765
731
"""
766
732
Test that a new client is created using the connection file
767
733
of an existing client
@@ -770,10 +736,7 @@ def test_load_kernel_file(ipyconsole, qtbot):
770
736
client = ipyconsole .get_current_client ()
771
737
qtbot .waitUntil (lambda : shell ._prompt_html is not None , timeout = SHELL_TIMEOUT )
772
738
773
- QTimer .singleShot (2000 , lambda : open_client_from_connection_info (
774
- client .connection_file ,
775
- qtbot ))
776
- ipyconsole .create_client_for_kernel ()
739
+ ipyconsole ._create_client_for_kernel (client .connection_file , None , None , None )
777
740
qtbot .wait (1000 )
778
741
779
742
new_client = ipyconsole .get_clients ()[1 ]
@@ -787,7 +750,6 @@ def test_load_kernel_file(ipyconsole, qtbot):
787
750
788
751
@pytest .mark .slow
789
752
@flaky (max_runs = 3 )
790
- @pytest .mark .skipif (os .name == 'nt' , reason = "It times out on Windows" )
791
753
def test_sys_argv_clear (ipyconsole , qtbot ):
792
754
"""Test that sys.argv is cleared up correctly"""
793
755
shell = ipyconsole .get_current_shellwidget ()
0 commit comments