##// END OF EJS Templates
log kernel specs that fail to load
Min RK -
Show More
@@ -19,7 +19,11 b' class MainKernelSpecHandler(IPythonHandler):'
19 ksm = self.kernel_spec_manager
19 ksm = self.kernel_spec_manager
20 results = []
20 results = []
21 for kernel_name in sorted(ksm.find_kernel_specs(), key=_pythonfirst):
21 for kernel_name in sorted(ksm.find_kernel_specs(), key=_pythonfirst):
22 try:
22 d = ksm.get_kernel_spec(kernel_name).to_dict()
23 d = ksm.get_kernel_spec(kernel_name).to_dict()
24 except Exception:
25 self.log.error("Failed to load kernel spec: '%s'", kernel_name, exc_info=True)
26 continue
23 d['name'] = kernel_name
27 d['name'] = kernel_name
24 results.append(d)
28 results.append(d)
25
29
@@ -5,6 +5,7 b' import errno'
5 import io
5 import io
6 import json
6 import json
7 import os
7 import os
8 import shutil
8
9
9 pjoin = os.path.join
10 pjoin = os.path.join
10
11
@@ -66,6 +67,25 b' class APITest(NotebookTestBase):'
66
67
67 self.ks_api = KernelSpecAPI(self.base_url())
68 self.ks_api = KernelSpecAPI(self.base_url())
68
69
70 def test_list_kernelspecs_bad(self):
71 """Can list kernelspecs when one is invalid"""
72 bad_kernel_dir = pjoin(self.ipython_dir.name, 'kernels', 'bad')
73 try:
74 os.makedirs(bad_kernel_dir)
75 except OSError as e:
76 if e.errno != errno.EEXIST:
77 raise
78
79 with open(pjoin(bad_kernel_dir, 'kernel.json'), 'w') as f:
80 f.write("garbage")
81
82 specs = self.ks_api.list().json()
83 assert isinstance(specs, list)
84 # 2: the sample kernelspec created in setUp, and the native Python kernel
85 self.assertGreaterEqual(len(specs), 2)
86
87 shutil.rmtree(bad_kernel_dir)
88
69 def test_list_kernelspecs(self):
89 def test_list_kernelspecs(self):
70 specs = self.ks_api.list().json()
90 specs = self.ks_api.list().json()
71 assert isinstance(specs, list)
91 assert isinstance(specs, list)
General Comments 0
You need to be logged in to leave comments. Login now