@@ -286,3 +286,93 @@ def test_urls(config, public_url, local_url, connection_url):
286
286
assert serverapp .connection_url == connection_url
287
287
# Cleanup singleton after test.
288
288
ServerApp .clear_instance ()
289
+
290
+
291
+ # Preferred dir tests
292
+ # ----------------------------------------------------------------------------
293
+ def test_valid_preferred_dir (tmp_path , jp_configurable_serverapp ):
294
+ path = str (tmp_path )
295
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = path )
296
+ assert app .root_dir == path
297
+ assert app .preferred_dir == path
298
+ assert app .root_dir == app .preferred_dir
299
+
300
+
301
+ def test_valid_preferred_dir_is_root_subdir (tmp_path , jp_configurable_serverapp ):
302
+ path = str (tmp_path )
303
+ path_subdir = str (tmp_path / 'subdir' )
304
+ os .makedirs (path_subdir , exist_ok = True )
305
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = path_subdir )
306
+ assert app .root_dir == path
307
+ assert app .preferred_dir == path_subdir
308
+ assert app .preferred_dir .startswith (app .root_dir )
309
+
310
+
311
+ def test_valid_preferred_dir_does_not_exist (tmp_path , jp_configurable_serverapp ):
312
+ path = str (tmp_path )
313
+ path_subdir = str (tmp_path / 'subdir' )
314
+ with pytest .raises (TraitError ) as error :
315
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = path_subdir )
316
+
317
+ assert "No such preferred dir:" in str (error )
318
+
319
+
320
+ def test_invalid_preferred_dir_does_not_exist (tmp_path , jp_configurable_serverapp ):
321
+ path = str (tmp_path )
322
+ path_subdir = str (tmp_path / 'subdir' )
323
+ with pytest .raises (TraitError ) as error :
324
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = path_subdir )
325
+
326
+ assert "No such preferred dir:" in str (error )
327
+
328
+
329
+ def test_invalid_preferred_dir_does_not_exist_set (tmp_path , jp_configurable_serverapp ):
330
+ path = str (tmp_path )
331
+ path_subdir = str (tmp_path / 'subdir' )
332
+
333
+ app = jp_configurable_serverapp (root_dir = path )
334
+ with pytest .raises (TraitError ) as error :
335
+ app .preferred_dir = path_subdir
336
+
337
+ assert "No such preferred dir:" in str (error )
338
+
339
+
340
+ def test_invalid_preferred_dir_not_root_subdir (tmp_path , jp_configurable_serverapp ):
341
+ path = str (tmp_path / 'subdir' )
342
+ os .makedirs (path , exist_ok = True )
343
+ not_subdir_path = str (tmp_path )
344
+
345
+ with pytest .raises (TraitError ) as error :
346
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = not_subdir_path )
347
+
348
+ assert "preferred_dir must be equal or a subdir of root_dir:" in str (error )
349
+
350
+
351
+ def test_invalid_preferred_dir_not_root_subdir_set (tmp_path , jp_configurable_serverapp ):
352
+ path = str (tmp_path / 'subdir' )
353
+ os .makedirs (path , exist_ok = True )
354
+ not_subdir_path = str (tmp_path )
355
+
356
+ app = jp_configurable_serverapp (root_dir = path )
357
+ with pytest .raises (TraitError ) as error :
358
+ app .preferred_dir = not_subdir_path
359
+
360
+ assert "preferred_dir must be equal or a subdir of root_dir:" in str (error )
361
+
362
+
363
+ def test_observed_root_dir_updates_preferred_dir (tmp_path , jp_configurable_serverapp ):
364
+ path = str (tmp_path )
365
+ new_path = str (tmp_path / 'subdir' )
366
+ os .makedirs (new_path , exist_ok = True )
367
+
368
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = path )
369
+ app .root_dir = new_path
370
+ assert app .preferred_dir == new_path
371
+
372
+
373
+ def test_observed_root_dir_does_not_update_preferred_dir (tmp_path , jp_configurable_serverapp ):
374
+ path = str (tmp_path )
375
+ new_path = str (tmp_path .parent )
376
+ app = jp_configurable_serverapp (root_dir = path , preferred_dir = path )
377
+ app .root_dir = new_path
378
+ assert app .preferred_dir == path
0 commit comments