1
1
"""Test launching Jupyter Server Applications
2
2
through as ExtensionApp launch_instance.
3
3
"""
4
+ from pathlib import Path
4
5
import os
5
6
import sys
6
7
import time
@@ -45,7 +46,7 @@ def wait_up(url, interval=0.1, check=None):
45
46
46
47
@pytest .fixture
47
48
def launch_instance (request , port , token ):
48
- def _run_in_subprocess (argv = []):
49
+ def _run_in_subprocess (argv = [], add_token = True ):
49
50
50
51
def _kill_extension_app ():
51
52
try :
@@ -55,13 +56,15 @@ def _kill_extension_app():
55
56
pass
56
57
process .wait (10 )
57
58
59
+ if add_token :
60
+ f'--ServerApp.token="{ token } "' ,
61
+
58
62
process = subprocess .Popen ([
59
63
sys .executable , '-m' ,
60
64
'mockextensions.app' ,
61
65
f'--port={ port } ' ,
62
66
'--ip=127.0.0.1' ,
63
67
'--no-browser' ,
64
- f'--ServerApp.token="{ token } "' ,
65
68
* argv ,
66
69
], cwd = HERE )
67
70
@@ -93,3 +96,15 @@ def test_base_url(launch_instance, fetch):
93
96
assert r .status_code == 200
94
97
95
98
99
+ def test_token_file (launch_instance , fetch , token ):
100
+ token_file = HERE / Path ('token_file.txt' )
101
+ os .environ ['JUPYTER_TOKEN_FILE' ] = str (token_file )
102
+ token_file .write_text (token , encoding = 'utf-8' )
103
+
104
+ launch_instance (add_token = False )
105
+ r = fetch ("/mock" )
106
+ del os .environ ['JUPYTER_TOKEN_FILE' ]
107
+ token_file .unlink ()
108
+ assert r .status_code == 200
109
+
110
+
0 commit comments