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