Skip to content

Commit

Permalink
test that KernelSpecManager subclasses work if they don't implement g…
Browse files Browse the repository at this point in the history
…et_all_specs
  • Loading branch information
minrk committed Jan 23, 2018
1 parent ca73a87 commit 7dfa6c4
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions jupyter_client/tests/test_kernelspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import copy
import io
import json
from logging import StreamHandler
import os
from os.path import join as pjoin
from subprocess import Popen, PIPE, STDOUT
import sys
import tempfile
import unittest

import pytest
Expand Down Expand Up @@ -156,7 +158,7 @@ def test_validate_kernel_name(self):
'Haskell-1-2-3',
]:
assert kernelspec._is_valid_kernel_name(good)

for bad in [
'has space',
u'ünicode',
Expand All @@ -165,4 +167,33 @@ def test_validate_kernel_name(self):
]:
assert not kernelspec._is_valid_kernel_name(bad)


def test_subclass(self):
"""Test get_all_specs in subclasses that override find_kernel_specs"""
ksm = self.ksm
resource_dir = tempfile.gettempdir()
native_name = kernelspec.NATIVE_KERNEL_NAME
native_kernel = ksm.get_kernel_spec(native_name)

class MyKSM(kernelspec.KernelSpecManager):
def get_kernel_spec(self, name):
spec = copy.copy(native_kernel)
if name == 'fake':
spec.name = name
spec.resource_dir = resource_dir
elif name == native_name:
pass
else:
raise KeyError(name)
return spec

def find_kernel_specs(self):
return {
'fake': resource_dir,
native_name: native_kernel.resource_dir,
}

# ensure that get_all_specs doesn't raise if only
# find_kernel_specs and get_kernel_spec are defined
myksm = MyKSM()
specs = myksm.get_all_specs()
assert sorted(specs) == ['fake', native_name]

0 comments on commit 7dfa6c4

Please sign in to comment.