diff --git a/IPython/html/services/kernelspecs/handlers.py b/IPython/html/services/kernelspecs/handlers.py
index 3aeb554..975cd5d 100644
--- a/IPython/html/services/kernelspecs/handlers.py
+++ b/IPython/html/services/kernelspecs/handlers.py
@@ -19,8 +19,9 @@ class MainKernelSpecHandler(IPythonHandler):
ksm = self.kernel_spec_manager
results = []
for kernel_name in ksm.find_kernel_specs():
- results.append(dict(name=kernel_name,
- display_name=ksm.get_kernel_spec(kernel_name).display_name))
+ d = ksm.get_kernel_spec(kernel_name).to_dict()
+ d['name'] = kernel_name
+ results.append(d)
self.set_header("Content-Type", 'application/json')
self.finish(jsonapi.dumps(results))
diff --git a/IPython/html/services/kernelspecs/tests/test_kernelspecs_api.py b/IPython/html/services/kernelspecs/tests/test_kernelspecs_api.py
index 9022415..ad2a5fb 100644
--- a/IPython/html/services/kernelspecs/tests/test_kernelspecs_api.py
+++ b/IPython/html/services/kernelspecs/tests/test_kernelspecs_api.py
@@ -68,11 +68,14 @@ class APITest(NotebookTestBase):
def test_list_kernelspecs(self):
specs = self.ks_api.list().json()
assert isinstance(specs, list)
-
+
# 2: the sample kernelspec created in setUp, and the native Python kernel
self.assertEqual(len(specs), 2)
- assert any(s == {'name': 'sample', 'display_name': 'Test kernel'}
- for s in specs), specs
+
+ def is_sample_kernelspec(s):
+ return s['name'] == 'sample' and s['display_name'] == 'Test kernel'
+
+ assert any(is_sample_kernelspec(s) for s in specs), specs
def test_get_kernelspec(self):
spec = self.ks_api.kernel_spec_info('Sample').json() # Case insensitive
diff --git a/IPython/kernel/kernelspec.py b/IPython/kernel/kernelspec.py
index 1028b66..a9e51ca 100644
--- a/IPython/kernel/kernelspec.py
+++ b/IPython/kernel/kernelspec.py
@@ -47,14 +47,17 @@ class KernelSpec(HasTraits):
with io.open(kernel_file, 'r', encoding='utf-8') as f:
kernel_dict = json.load(f)
return cls(resource_dir=resource_dir, **kernel_dict)
+
+ def to_dict(self):
+ return dict(argv=self.argv,
+ env=self.env,
+ display_name=self.display_name,
+ language=self.language,
+ codemirror_mode=self.codemirror_mode,
+ )
def to_json(self):
- return json.dumps(dict(argv=self.argv,
- env=self.env,
- display_name=self.display_name,
- language=self.language,
- codemirror_mode=self.codemirror_mode,
- ))
+ return json.dumps(self.to_dict())
def _is_kernel_dir(path):
"""Is ``path`` a kernel directory?"""