##// END OF EJS Templates
Add test for installing kernel spec
Thomas Kluyver -
Show More
@@ -1,39 +1,65 b''
1 1 import json
2 2 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
9 10 sample_kernel_json = {'argv':['cat', '{connection_file}'],
10 11 'display_name':'Test kernel',
11 12 'language':'bash',
12 13 }
13 14
14 15 class KernelSpecTests(unittest.TestCase):
15 16 def setUp(self):
16 self.tempdir = td = TemporaryDirectory()
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')
20 22 with open(json_file, 'w') as f:
21 23 json.dump(sample_kernel_json, f)
22 24
23 25 self.ksm = kernelspec.KernelSpecManager(ipython_dir=td.name)
24
25 def tearDown(self):
26 self.tempdir.cleanup()
26
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()
30 35 self.assertEqual(kernels['sample'], self.sample_kernel_dir)
31 36
32 37 def test_get_kernel_spec(self):
33 38 ks = self.ksm.get_kernel_spec('SAMPLE') # Case insensitive
34 39 self.assertEqual(ks.resource_dir, self.sample_kernel_dir)
35 40 self.assertEqual(ks.argv, sample_kernel_json['argv'])
36 41 self.assertEqual(ks.display_name, sample_kernel_json['display_name'])
37 42 self.assertEqual(ks.language, sample_kernel_json['language'])
38 43 self.assertEqual(ks.codemirror_mode, sample_kernel_json['language'])
39 self.assertEqual(ks.env, {}) No newline at end of file
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