|
6 | 6 | from jupyter_kernel_mgmt.managerabc import KernelManagerABC
|
7 | 7 | from jupyter_kernel_mgmt.subproc.manager import KernelManager
|
8 | 8 | from jupyter_core import paths
|
| 9 | +from traitlets import List, Unicode |
| 10 | +from traitlets.config import Application, SingletonConfigurable |
9 | 11 | from .utils import test_env
|
10 | 12 | from .test_kernelspec import install_sample_kernel
|
11 | 13 |
|
@@ -63,6 +65,35 @@ def get_connection_info(self):
|
63 | 65 | return {}
|
64 | 66 |
|
65 | 67 |
|
| 68 | +class ProviderApplication(Application): |
| 69 | + name = 'ProviderApplication' |
| 70 | + my_app = Unicode('my_app', config=True,) |
| 71 | + |
| 72 | + |
| 73 | +class ProviderConfig(SingletonConfigurable): |
| 74 | + my_argv = List(Unicode(), ['default_argv'], config=True,) |
| 75 | + my_foo = Unicode('foo.bar', config=True,) |
| 76 | + |
| 77 | + |
| 78 | +class TestConfigKernelProvider(DummyKernelProvider): |
| 79 | + """A dummy kernel provider for testing KernelFinder with configuration loading""" |
| 80 | + id = 'config' |
| 81 | + |
| 82 | + config = None |
| 83 | + argv = ['dummy_config_kernel'] # will be replace by config item |
| 84 | + |
| 85 | + def find_kernels(self): |
| 86 | + argv = self.argv |
| 87 | + if self.config: |
| 88 | + argv = self.config.my_argv |
| 89 | + assert self.config.my_foo == 'foo.bar' # verify default config value |
| 90 | + |
| 91 | + yield 'sample', {'argv': argv} |
| 92 | + |
| 93 | + def load_config(self, config=None): |
| 94 | + self.config = ProviderConfig.instance(config=config) |
| 95 | + |
| 96 | + |
66 | 97 | class KernelDiscoveryTests(unittest.TestCase):
|
67 | 98 |
|
68 | 99 | def setUp(self):
|
@@ -134,3 +165,21 @@ def test_kernel_spec_provider_subclass():
|
134 | 165 |
|
135 | 166 | conn_info, manager = kf.launch('dummy_kspec/dummy_kspec1')
|
136 | 167 | assert isinstance(manager, DummyKernelManager)
|
| 168 | + |
| 169 | + def test_load_config(self): |
| 170 | + # create fake application |
| 171 | + app = ProviderApplication() |
| 172 | + app.launch_instance(argv=["--ProviderConfig.my_argv=['xxx','yyy']"]) |
| 173 | + |
| 174 | + kf = discovery.KernelFinder(providers=[TestConfigKernelProvider()]) |
| 175 | + dummy_kspecs = list(kf.find_kernels()) |
| 176 | + |
| 177 | + count = 0 |
| 178 | + found_argv = [] |
| 179 | + for name, spec in dummy_kspecs: |
| 180 | + if name == 'config/sample': |
| 181 | + found_argv = spec['argv'] |
| 182 | + count += 1 |
| 183 | + |
| 184 | + assert count == 1 |
| 185 | + assert found_argv == ['xxx', 'yyy'] |
0 commit comments