8
8
9
9
from traitlets .config import Config
10
10
from jupyter_core .application import JupyterApp
11
+ from jupyter_core .paths import jupyter_runtime_dir
11
12
from ipython_genutils .tempdir import TemporaryDirectory , TemporaryWorkingDirectory
12
13
from ipython_genutils .py3compat import str_to_bytes
13
14
from jupyter_client import connect , KernelClient
@@ -110,11 +111,9 @@ def test_load_connection_info():
110
111
111
112
112
113
def test_find_connection_file ():
113
- cfg = Config ()
114
114
with TemporaryDirectory () as d :
115
- cfg .ProfileDir .location = d
116
115
cf = 'kernel.json'
117
- app = DummyConsoleApp (config = cfg , connection_file = cf )
116
+ app = DummyConsoleApp (runtime_dir = d , connection_file = cf )
118
117
app .initialize ()
119
118
120
119
security_dir = app .runtime_dir
@@ -131,5 +130,45 @@ def test_find_connection_file():
131
130
):
132
131
assert connect .find_connection_file (query , path = security_dir ) == profile_cf
133
132
134
- JupyterApp ._instance = None
133
+
134
+ def test_find_connection_file_local ():
135
+ with TemporaryWorkingDirectory () as d :
136
+ cf = 'test.json'
137
+ abs_cf = os .path .abspath (cf )
138
+ with open (cf , 'w' ) as f :
139
+ f .write ('{}' )
140
+
141
+ for query in (
142
+ 'test.json' ,
143
+ 'test' ,
144
+ abs_cf ,
145
+ os .path .join ('.' , 'test.json' ),
146
+ ):
147
+ assert connect .find_connection_file (query , path = ['.' , jupyter_runtime_dir ()]) == abs_cf
148
+
149
+
150
+ def test_find_connection_file_relative ():
151
+ with TemporaryWorkingDirectory () as d :
152
+ cf = 'test.json'
153
+ os .mkdir ('subdir' )
154
+ cf = os .path .join ('subdir' , 'test.json' )
155
+ abs_cf = os .path .abspath (cf )
156
+ with open (cf , 'w' ) as f :
157
+ f .write ('{}' )
158
+
159
+ for query in (
160
+ os .path .join ('.' , 'subdir' , 'test.json' ),
161
+ os .path .join ('subdir' , 'test.json' ),
162
+ abs_cf ,
163
+ ):
164
+ assert connect .find_connection_file (query , path = ['.' , jupyter_runtime_dir ()]) == abs_cf
165
+
166
+
167
+ def test_find_connection_file_abspath ():
168
+ with TemporaryDirectory () as d :
169
+ cf = 'absolute.json'
170
+ abs_cf = os .path .abspath (cf )
171
+ with open (cf , 'w' ) as f :
172
+ f .write ('{}' )
173
+ assert connect .find_connection_file (abs_cf , path = jupyter_runtime_dir ()) == abs_cf
135
174
0 commit comments