Show More
@@ -3,6 +3,7 b' import os' | |||
|
3 | 3 | from os.path import join as pjoin |
|
4 | 4 | import unittest |
|
5 | 5 | |
|
6 | from IPython.testing.decorators import onlyif | |
|
6 | 7 | from IPython.utils.tempdir import TemporaryDirectory |
|
7 | 8 | from IPython.kernel import kernelspec |
|
8 | 9 | |
@@ -13,7 +14,8 b" sample_kernel_json = {'argv':['cat', '{connection_file}']," | |||
|
13 | 14 | |
|
14 | 15 | class KernelSpecTests(unittest.TestCase): |
|
15 | 16 | def setUp(self): |
|
16 |
|
|
|
17 | td = TemporaryDirectory() | |
|
18 | self.addCleanup(td.cleanup) | |
|
17 | 19 | self.sample_kernel_dir = pjoin(td.name, 'kernels', 'Sample') |
|
18 | 20 | os.makedirs(self.sample_kernel_dir) |
|
19 | 21 | json_file = pjoin(self.sample_kernel_dir, 'kernel.json') |
@@ -22,8 +24,11 b' class KernelSpecTests(unittest.TestCase):' | |||
|
22 | 24 | |
|
23 | 25 | self.ksm = kernelspec.KernelSpecManager(ipython_dir=td.name) |
|
24 | 26 | |
|
25 | def tearDown(self): | |
|
26 |
self. |
|
|
27 | td2 = TemporaryDirectory() | |
|
28 | self.addCleanup(td2.cleanup) | |
|
29 | self.installable_kernel = td2.name | |
|
30 | with open(pjoin(self.installable_kernel, 'kernel.json'), 'w') as f: | |
|
31 | json.dump(sample_kernel_json, f) | |
|
27 | 32 | |
|
28 | 33 | def test_find_kernel_specs(self): |
|
29 | 34 | kernels = self.ksm.find_kernel_specs() |
@@ -37,3 +42,24 b' class KernelSpecTests(unittest.TestCase):' | |||
|
37 | 42 | self.assertEqual(ks.language, sample_kernel_json['language']) |
|
38 | 43 | self.assertEqual(ks.codemirror_mode, sample_kernel_json['language']) |
|
39 | 44 | self.assertEqual(ks.env, {}) |
|
45 | ||
|
46 | def test_install_kernel_spec(self): | |
|
47 | self.ksm.install_kernel_spec(self.installable_kernel, | |
|
48 | kernel_name='tstinstalled') | |
|
49 | self.assertIn('tstinstalled', self.ksm.find_kernel_specs()) | |
|
50 | ||
|
51 | with self.assertRaises(OSError): | |
|
52 | self.ksm.install_kernel_spec(self.installable_kernel, | |
|
53 | kernel_name='tstinstalled') | |
|
54 | ||
|
55 | # Smoketest that this succeeds | |
|
56 | self.ksm.install_kernel_spec(self.installable_kernel, | |
|
57 | kernel_name='tstinstalled', | |
|
58 | replace=True) | |
|
59 | ||
|
60 | @onlyif(os.name != 'nt' and os.getuid() != 0, "needs Unix system and non-root uid") | |
|
61 | def test_cant_install_kernel_spec(self): | |
|
62 | with self.assertRaises(OSError): | |
|
63 | self.ksm.install_kernel_spec(self.installable_kernel, | |
|
64 | kernel_name='tstinstalled', | |
|
65 | system=True) |
General Comments 0
You need to be logged in to leave comments.
Login now